I am using Processing to control inputs and outputs from several Arduino Unos at once. I have StandardFirmata loaded up on the Arduino Unos. When a button is pressed for any one Arduino, I would like to play a tone on a speaker driven by that Arduino. This was relatively straightforward from within Arduino using the tone function, however, due to the need to interact more easily with computer files at a higher time resolution I've moved into Processing, which is great in a lot of ways, but doesn't appear to have easy access to an analogous tone function for the Arduino.
Does anyone have any suggestions on how to do this? It seems like I'd have to code something of a hack of my own PWM type function without the benefit of using internal timers to play asynchronously, but I would think there would be something simpler out there that I haven't found yet.
Take a look at my code in this thread "piano tones micros"
I think that you could easily adapt that to have an Arduino play a tone based on serial input.
@CrossRoads: Very nice work. I think this is ultimately more complex audio wise than I need, but I'll certainly keep it in mind.
@PaulS: I was really hoping that was not the case.
Am scratching my head as to what is the best solution here. Basically I'm setting up a couple of auditory reaction time studies (a sound goes off, subject has to press a button). I want to be able to run at least 4 subjects simultaneously, nearly independently (each with a separate arduino uno). I started to incorporate Processing since it seemed like a good way to display summary info and to move data to and from the computer for longer term storage.
I think I have a few options:
Reimplement the tone() function in Processing and keep all the code in processing
Hack StandardFirmata to add a few lines in to include a trigger to play a tone
Ditch StandardFirmata and write my protocol in Arduino and use Processing for some hopefully simple file management over serial.
Come up with a hardware hack/solution for the tone portion
I'm thinking 2 (hack StandardFirmata with an extra line or two) could be really easy if it would work, otherwise 3 (share the load between Arduino & Processing) might be best?
I'm thinking 2 (hack StandardFirmata with an extra line or two) could be really easy if it would work, otherwise 3 (share the load between Arduino & Processing) might be best?
Firmata turns the Arduino into an idiot. There isn't an easy way to make it "an idiot, except it can sing", since the firmata library for Processing doesn't have a way to tell the Arduino to sing. Option 3 will be simpler.
I mostly started to use processing to save session data to a file that is automatically named according to the date and time. This seemed easier to do via Processing than to do within Arduino. Once I started using processing for one thing, I started to put more of my code in it since it seemed easiest to code everything in one place and interact with the Arduino via StandardFirmata. But I guess I'll have to share the load a bit more.