Go Down

Topic: Play Melody (Read 3193 times) previous topic - next topic

SarahBethC

Does anyone what suggestions on how to hook up 2 speakers to one arduino as well as how to code 2 separate melodies to play from the same board (UNO) at once?? I have 1 strain of note set to play, but I have 5 separate strains that need to play at once....I can't figure out how to write/hookup the program/board to work correctly.....

Grumpy_Mike

There is no need for two speakers, just one will do but connect the output to an amplifier.

The code is complex and might be found on line but I cover this in my book http://www.apress.com/gb/book/9781484217207

Unfortunately due to my deal with the publishers I can't post it here.

SarahBethC

If I hook it up to a speaker will I have to rewrite my whole code??

Grumpy_Mike

No, why do you ask? The sound waveform still comes out of the same pin does it not?

SarahBethC

Yes. I may have been going about it wrong. I was thinking I'd have to use multiple pins for mulitple speakers, but you're saying 1 pin attached to 1 speaker that will play multiple sounds at once??

Grumpy_Mike

Quote
but you're saying 1 pin attached to 1 speaker that will play multiple sounds at once??
Only if your code is written to mix the two waveforms BEFORE they are outputted to the pin.

If you are producing a separate waveform on each pin then connect a resistor between the pin and the input to the amplifier, and another resistor from the input of the amplifier to ground. All 1K ones should do.

CrossRoads

You can "cheat"! Use two microcontrollers, one for note creation, one for melody playing.
My project here used a 1284P processor to allow up to 13 notes to be created from 13 buttons.
You can do the same, but use a Uno/Nano etc to make the button presses.
'1284P cards:
http://www.crossroadsfencing.com/BobuinoRev17/
"piano" project topic
http://forum.arduino.cc/index.php?topic=179761.0
Youtube video
https://www.youtube.com/watch?v=4c8idXN4Pg0
The outputs are mixed together in the analog world instead of the digital world.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

I suppose you could do even more outputs, 2 octaves worth, and send the notes to play in serially. Start and stop info for each.  Like a basic form of MIDI? Might have to put a limit of how many notes can be played at once, I don't know how many notes can actually be created - I only did 8 because that was all the buttons I had.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

DocStein99

You can "cheat"! Use two microcontrollers, one for note creation, one for melody playing.
I was curious about playing tones, and holding up the processor, for handling serial events from orher devices.  Couldnt figure out a way to multi-thread the main loop while playing a tone.

So i guess a seperate board, or external dedicated synth is about the only way to play tones, without jamming the main loop.

Grumpy_Mike

No, you simply have a timer generating an interrupt that increments a tick. The ISR then just looks at this tick count and decides what pins to toggle depending on what time out has been set for each tone. You can have as many tones as you want. The more tones the more processor load. In my book, see link above, I have an example of generating a two tone telephone dialling output.

DocStein99

I just bought the book.  Thanks for pointing that out.  I look forward to figuring out how that works.

Grumpy_Mike

Quote
I just bought the book.
Thanks  :)

SarahBethC

I am creating a program for a piano piece I wrote. 5 strains of notes over 4 octaves (I believe). I've been programming the speaker to play each note based on frequenties. There are 30+ notes (accidentals included). I've been using the sample play melody off the Arduino website.

DocStein99

The piano song sounds interesting.  I made a few programs so far, using arduino uno.  They use speaker play tone.  Ran out of memory and forced me to learn how to maximize code to store notes and tones.

Knowing how to manipulate waveforms to create sounds is always something that interests me.  I like to programatically write sounds, just like they had to do for 80s Atari games.

Grumpy_Mike

Sarah - That sounds like an interesting project. I know it is not an Arduino but it is something that you can do in the Pure Data ( PD ) language. It is rather like MAX but free.

Currently I am working with Drake Music Labs - North, we design accessible instruments for disabled people. I have been working with a girl who is teaching autistic people and we have developed a drum that mimics and plays back what ever rhythm you tap into it.

Some unusual things I have designed and are in the book are:-
SpoonDuino:-
http://vimeo.com/38466551
Harp Player
http://www.vimeo.com/21024841note this is a early version with only 5 of the 10 strings working.
yes - no Arduino sample playing without hardware
https://youtu.be/WShVFcrFpwU
Arduinocaster - keytar
http://www.youtube.com/watch?v=ehy9xgl4YCs

Go Up