Play Melody

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.....

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 Arduino Music and Audio Projects | SpringerLink

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

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

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

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??

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.

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

The outputs are mixed together in the analog world instead of the digital world.

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.

CrossRoads:
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.

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.

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

I just bought the book.

Thanks :slight_smile:

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.

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.

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:-

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
Arduino Uno saying Yes & No without extra hardware - YouTube
Arduinocaster - keytar
Arduinocaster - YouTube

I switched to the Arduino "Melody" example code and I'm getting an error that says

error: expected declaration before '}' token

};

I've changed my code 30 times and nothing is working....do any of you know what this means and how to fix it??? Its olny highlighting:

#define Note_e4 329.63

There are 35ish more notes exactly like that with different frequencies and a different name (instead of being Note_e4 it'll be Note_f3, etc.). I don't know what is wrong with my code that only that part is messed up....

Well, you could post/attach the code for us to look at and identify where the missing ; needs to go.

Are you sure Melody works with non-whole #s like 329.63?

Magnstowiter:
so , did you made it or not in the end?

Still working on it.

error: expected declaration before '}' token

Normally means a ; or a } misplaced.

If you click on a { then the matching } is highlighted, they must be matched.

Here is the program I have written. I haven't tried it with whole #s because I don't want the pitches to be off.....

Sketch_2.0.ino (2.37 KB)