Thursday, November 17, 2016

Star Spangled Banner using a Floppy Disc and Moppy

Figure 1
Just a little fun project to attempt to play music with a floppy drive.  There are great directions online for how to do this in various locations.  I originally worked with a stepper motor and developed an Arduino sketch which played the Star Spangled Banner.  The trick to generating a note with a stepper motor is causing the stepper to step with a frequency which matches a musical note.  The timing between steps (the period) is the reciprocal of a frequency (Hz).  If the frequency is between 20 Hz and 20kHz, the human ear can hear it.  In practice, I used frequencies from middle C (C4, 261Hz) to an octave and a half above or G5 (784 Hz) which is the range for the Star Spangled Banner in the key of C.
The Arduino function "note" in Figure 1 calculates the period for a given frequency, and then plays that note.  I have borrowed this code from Arduino Forum user "raschemmel" as published on this website:  https://forum.arduino.cc/index.php?topic=343270.0.

Figure 2

I setup a big array containing notes in the first row, and durations in the second row.  The notes and durations were defined in musical terms making transposition from sheet music relatively painless although tedious (Figure 2).  The full array defining the song can be found in Github with the rest of the Arduino sketch.  Finally, playing the song itself is as simple as a double "for" loop which iterates over the columns of the song array and plays the note for the duration specified in the second "for" loop.  I'm proud of the simplicity of the loop function (Figure 3).  I also included two scalar variables (tempo and pitch_multiplier) which modify all the duration variables (tempo) or pitch variables (pitch_multiplier) allowing for transposition and tempo control.

Figure 3
While this setup worked, the volume of the stepper was too quiet even when I mounted it on a large piece of metal to use as a resonator.  I played around with a piezoelectric pickup and an amplifier circuit (see descriptions later in this post), but the piezo picked up too much vibration noise from the motor and sounded pretty awful.

I stumbled on Moppy, which seems to be the most popular way of playing music from an actual floppy drive.  The principle is presumably similar to my Arduino sketch, except that you feed it a midi file (the equivalent of my array) and it provides a clean Java based user interface.  In addition, Moppy supports multitrack midi files so that you can play different "voices" with different floppy drives.

Setup of the floppy was pretty easy once I figured out which pins to connect to the Arduino (Figures 4 and 5).  
Figure 4
Figure 5
I modified an existing Star Spangled Banner midi file to leave only the melody line using the program Anvil Studio.  The result is shown in the Youtube video below.
Figure 6

Finally, I used an LM386 chip to breadboard an amplifier circuit driving a small 8 Ohm speaker with the piezoelectric pickup mounted on the case of the floppy drive (Figures 7 and 8).  The circuit was adapted from CircuitBasics.  This worked much better than mounting the piezo directly on the stepper, and compounded with the fact that the floppy was much louder than the stepper, I was able to record a decent rendition of the song.  I will be playing the video at the opening ceremony of a robotics tournament which my school is hosting.

Figure 7

Figure 8


I made a PCB board (Figure 9) for a semi permanent installation of this circuit.  The EagleCAD files are located here:  https://github.com/gcronin/StepperTest/tree/master/LM386%20Amp.


Figure 9
I made a JFET board (Figures 10-11) which was designed by Cafe Walter (http://www.cafewalter.com/cafewalter/fetpre/) and is open source!  Thank you so much!!!  The schematic for this circuit can be found here.  The Eagle CAD files for my version of this board can be found here.  

Figure 10

Figure 11

Monday, November 14, 2016

Animatronics Demo with VSA

https://www.youtube.com/watch?v=J2nnmYpLG8Q&feature=youtu.be
Figure 1
Visual Show Automation (VSA) is a software package which coordinates movement, lights, sound and video.  The demo version is free at available from Brookshire Software, however it does not allow you to save files.  I learned about this software from a colleague who had done a basic automation project and used this website as a starting point:  http://animatronicsworkshop.com/.

The process involves making characters which are animated by use of servo motors, recording a script, and then using the VSA software to sync up motion of the servos to the songs in the audio. IMPORTANT:  if you are using the demo version, make sure the Arduino is connected to the computer before you run the software.  Otherwise, you will need to restart the software and you will lose all of your work.  The simple demo that is linked above using two servos and a relay to control a red light (Figure 1).  The setup is done through Tools -> Settings.  Use the audio tab to import an audio file (Figure 2).  
Figure 2

Figure 3
Under the Device Settings tab (Figure 3), choose Disable All from the dropdown menu in the lower left corner, then reselect only those tracks that correspond to pins that you have servos or relays plugged into on your Arduino.  For example, I used two servo motors with the control wires plugged into Arduino pins 2 and 5.  I plugged the base of a transistor controlling a relay into pin 8.  Rename the device with a logical name in the second column.  The 3rd column will remain MiniSCC Servo if you are using a servo attached to an Arduino, or MiniSCC Relay if you are driving a relay using an Arduino.  The fourth column needs to be the COM port that the Arduino is using.  The Default (8th column) will be the starting point for the servo or relay.

From this point, when you go back to the main screen, you will see the audio waveform in the bottom.  There is a tool which will automatically synchronize the motion of a servo to amplitude of the waveform.  This can be found under Tools -> Waveform Analysis.  For this demo, I entered servo and relay values manually.  

Figure 4
For a servo, if you drag your mouse in the row which corresponds to the servo in the top pane, you will create a servo motion event (Figure 4).  You can move the "dial" on the left to adjust the Stop Position; the servo will move in real time.  When it is in the correct position, either click on Capture or manually enter the number on the left (not the angle) into the Stop Position field on the right.  The Start Position is set by the previous motion event, or by the default position for the starting point. You can roughly sync up the motion to the sound waveform as you will see vertical timelines as you drag your mouse to create the event.  You can drag the event to move it, or change the beginning or end times by placing your mouse over the beginning or end of the event. 
Figure 5

A relay works pretty much the same way (Figure 5), although you only have options for on (1 output) or off (0 output).   Put a 1 or a 0 in the field which is called Pulse Value.

You can copy and paste, or select different events by using the right mouse button in the top window.  My demo is very repetitive, which was done using copy  and paste functionality.  It takes a bit of practice to get used to the interface... if you are used to dragging with your left mouse button, you will find that you are creating events instead of selecting.

Figure 6
The finished view for my demo is shown below (Figure 6).  There are three sets of rectangles in the top pane which correspond to the events for the two servos and the relay.  We can see the values which go with those events in the second pane, where I have used the scale and offset arrows to separate the three devices so they don't lie on top of each other.  The bottom pane shows audio.   To run your creation, use the buttons in the top right corner.  The fourth one loops through the program over and over until you stop it.

On the Arduino side, the software which allows the Arduino to act like a MiniSCC is available here: http://animatronicsworkshop.com/?page_id=458.  I tailored this sketch slightly to allow it to work for relays as well.   The full sketch can be found on github.  The picture below shows the modifications to the original sketch.


Here are a couple links to animatronic videos that were made in a class I teach.  These were made without VSA, and I hope that future projects are of even higher quality.