For complete info on the sound board, see https://learn.adafruit.com/adafruit-audio-fx-sound-board/overview
This is a simple test of a direct trigger of the Audio FX Sounds Board from an Arduino.
For my test, I used an Arduino Pro Mini running at 3.3v & 8mHz. Digital pin #4 of the Arduino was connected to trigger pin #0 of the Sound Board, and I tied them to a common ground. I powered the Sound Board via a USB external battery for the initial tests, and the Arduino via the FTDI cable. For later tests, I powered the Sound Board via the Arduino's VCC (3v) pin directly.
The Audio FX board pins are triggered when connected to ground (they're set up this way so they'll work with simple normally open push buttons connected directly to the board's ground). This has a couple of implications:
- To trigger a given pin on the Audio FX board, we need to bring the Arduino pin tied to it to
LOW
, then back toHIGH
. - I've found that adding a delay of 100ms after setting to
LOW
is long enough for the Audio FX board to register the trigger event with my 3v3 Arduino. The documentation stats that the board should be able to detect the trigger in 50ms. Not sure if the discrepency is due to the slower clock speed (8mHz) on the Arduino. I'll try it with a 5v Arduino running at 16mHz to see if that has any effect.- It turns out even 100ms might not be enough. In another project that I've got going, I had to hold the pin
LOW
for 250ms to consistently get a trigger to fire.
- It turns out even 100ms might not be enough. In another project that I've got going, I had to hold the pin
- When the board is first powered on, the Arduino pins get set to
OUTPUT
mode. When that happens, the pins are triggered, causing the sounds to play. I'm not sure of the best way to suppress this, but it bears investigating. UPDATE: I don't think this is actually the case. I added a button to trigger the beginning of the playback. There is no trigger until that button is pressed. Yay! - Don't forget to tie the sound board and Arduino's ground together! :)
@tinker424 sure, there's a few things you'd want to change to do that. If you're using this example (which probably could use a re-write).
First, you would need to define all the pins you want to trigger. Might as well define the fixed interval, too. Based on your scenario:
Second, in
setup()
, you want to make sure all the pins are configured, and set up arandomSeed()
so that your sequence is not the same every time (note: I've removed the button setup code, since you want to trigger on random intervals).Let's add a little function to give us random intervals:
Lastly, you need to setup the triggers in
loop()
:This example will wait between 1 and 5 seconds, trigger the first sound, wait another 1.5 seconds, then trigger the second sound. Then the main loop will come back around again. You might need to tweak the fixed interval, to give the sound board enough time to reset. If you wanted to tweak the first delay at startup, add a call to
randomInterval()
to the end ofsetup()
and move the call torandomInterval()
inloop()
to the end of that function (it can go at the top or bottom of the function, since it's just defining a gap between the activations).This code could be better, including dropping
delay()
and using a non-blocking timing mechanism.I hope this helps.