DUINOMITE: playing melodies with old Floppy :


I have seen lot of projects which use floppy to play melodies like this one http://www.youtube.com/watch?v=yHJOz_y9rZE it look as fun project and today I decided to try implementing it with DuinoMite.

First I searched for the imperial march notes and found them on the internet in the MSP430 launchpad project in C:

notes definitions:

#define c 261
#define d 294
#define e 329
#define f 349
#define g 391
#define gS 415
#define a 440
#define aS 455
#define b 466
#define cH 523
#define cSH 554
#define dH 587
#define dSH 622
#define eH 659
#define fH 698
#define fSH 740
#define gH 784
#define gSH 830
#define aH 880

then the melody:

beep( a, 500);beep( a, 500);beep( a, 500);beep( f, 350);beep( cH, 150); beep( a, 500);beep( f, 350);beep( cH, 150);beep( a, 650);delay_ms(150);

beep( eH, 500);beep( eH, 500);beep( eH, 500); beep( fH, 350);beep( cH, 150);beep( gS, 500);beep( f, 350);beep( cH, 150);beep( a, 650);delay_ms(150);

beep( aH, 500); beep( a, 300);beep( a, 150); beep( aH, 400);beep( gSH, 200); beep( gH, 200); beep( fSH, 125); beep( fH, 125); beep( fSH, 250); delay_ms(250);

beep( aS, 250);  beep( dSH, 400);  beep( dH, 200); beep( cSH, 200); beep( cH, 125); beep( b, 125); beep( cH, 250); delay_ms(250);

beep( f, 125); beep( gS, 500); beep( f, 375); beep( a, 125);beep( cH, 500);beep( a, 375); beep( cH, 125);beep( eH, 650);

beep( aH, 500);beep( a, 300); beep( a, 150); beep( aH, 400); beep( gSH, 200); beep( gH, 200); beep( fSH, 125);beep( fH, 125);  beep( fSH, 250); delay_ms(250);

beep( aS, 250); beep( dSH, 400); beep( dH, 200);  beep( cSH, 200);

beep( cH, 125);  beep( b, 125);  beep( cH, 250); delay_ms(250);

beep( f, 250); beep( gS, 500); beep( f, 375); beep( cH, 125);beep( a, 500); beep( f, 375); beep( cH, 125); beep( a, 650);

I decided first to “verify” the melody by playing it with the SOUND command and wrote this small code:

20 ‘notes c, d, e, f, g, gs, a, as, b, ch, csh,dh, dsh,eh, fh, fsh,gh, gsh,ah
30 ‘note 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
40 DATA 261,294,329,349,391,415,440,455,466,523,554,587,622,659,698,740,784,830,880
50 DIM NOTE(19)
60 FOR I = 1 TO 19: READ NOTE(I): NEXT I ‘load the notes

now in NOTE(n) we have the note frequency for instance a = 7 NOTE(7) is 440 is the frequency for “a” and so on, the melody is:

70 ‘now the march melody
80 DATA 7,500,7,500,7,500,4,350,10,150,7,500,4,350,10,150,7,650,0,150
90 DATA 14,500,14,500,14,500,15,350,10,150,6,500,4,350,10,150,7,650,0,150
100 DATA 19,500,7,300,7,150,19,400,18,200,17,200,16,125,15,125,16,250,0,250
110 DATA 8,250,13,400,12,200,11,200
120 DATA 10,125,9,125,10,250,0,250
130 DATA 4,125,6,500,4,375,7,125,10,500,7,375,10,125,14,650
140 DATA 19,500,7,300,7,150,19,400,18,200,17,200,16,125,15,125,16,250,0,250
150 DATA 8,250,13,400,12,200,11,200
160 DATA 10,125,9,125,10,250,0,250
170 DATA 4,250,6,500,4,375,10,125,7,500,4,375,10,125,7,650,0,0

ok, the two 0 at the end is to tell code that there is no more notes, when the frequency is 0 the code will just add pause

let’s now play:

180 READ N: READ D ‘read note and duration
190 if D = 0 THEN END ‘end when D=0
210 PAUSE 10 ‘add small pause between the notes so they are not connected
220 GOTO 180

Here is video with the result: http://youtu.be/J_Bk2Es_Tpc not quite good but still recognizable :)))

Then I start searching info for the Floppy interfacing.

First I got PC power supply, the connector pinout is:


note that to start the power supply you have to short PS_ON# green cable with the COM black cable next to it

the FLOPPY 34 pin connector is with this layout:


NOTE: Floppy interface is 5V while DUINOMITE is 3.3V so you should use the open collector 5V tolerant pins to drive the Floppy.

In my case the Floppy I found was configured with the jumpers on the back as Floppy B.

So I connected FLOPPY.Pin.12 to GND (select Floppy B – the LED on front lights on when you do this), then I connected FLOPPY.Pin.16 to GND and the motor driving the DISK start rotating.

then I connected FLOPPY.Pin.16 (head direction) with 1K pullup to +5V to PIN(14) and FLOPPY.Pin.20 (head step++) with 1K pullup to +5V to PIN(15) and wrote this small code to test the setup:

10 SETPIN 14,9: SETPIN 15,9 ‘ setup pin 14 and pin 15 as open collector
15 P = 25 ‘ move speed 40 Hz
20 PIN(14) = 0 ‘select one head direction
30 FOR I = 1 TO 100
40 PIN(15) = 0: PAUSE P: PIN(15)=1: PAUSE P ‘ move the head
60 PIN(14) = 1 ‘select the opposite direction
70 FOR I = 1 TO 100
80 PIN(15) = 0: PAUSE P: PIN(15)=1: PAUSE P ‘move the head
100 P = P – 1
110 IF P > 0 THEN 20

as expected the head was moving with different speed and at some speeds the stepper motor insidewas resonating and nice sounds were producing.

now I was ready to write small song:

10 DATA 3,30,3,30,3,30,3,30,6,50,0,0 ‘the melody is stored here and ends with 0,0
20 SETPIN 14,9 : SETPIN 15,9 ‘make pins open collector
30 PIN(14)=0: PIN(15)=1 ‘set the direction
40 DIR = 0 ‘we need to toggle the direction on every note so the head is not stuck at one end
50 READ P: READ D ‘read the note and the duration
60 IF P=0 AND D=0 THEN END ‘until both are 0 then play
70 PRINT “P=”;P; ” D=”;D ‘print them to see what is playing
80 GOSUB 1000 ‘this plays one note
90 GOTO 50 ‘until the notes end

1000 FOR I = 1 TO D ‘for the duration
1010 PIN(15)=0: PAUSE P ‘move the head one step and wait time depend on the note
1020 PIN(15)=1: PAUSE P
1030 NEXT
1040 IF DIR = 0 THEN DIR = 1 ELSE DIR = 0 ‘at the end of the note change head direction
1050 PIN(14) = DIR
1055 PAUSE 100 ‘small pause between the notes

here is the result: http://youtu.be/BFTmGZqjCx4 unfortunately my music composing abilities prevented me to compose the Imperial march but I believe you got the idea and you can make something like this yourself and I hope your musinc composing skills will be better than mines 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: