Connecting Spark Core to Adafruit Audio FX Sound Board

I’m working on a project where I want to add sound to it. I originally started with a WTV020SD16P, but man, these things are soooo temperamental I eventually gave up on it. Anyway, since then, I’ve gone ahead and purchased an Adafruit Audio FX Sound Board https://www.adafruit.com/product/2133.

My plan then was to control the device using UART to play back the specific sounds, however after reading the docs, it appears this feature is still in development so they don’t recommend connecting via UART until they have finished documenting it.

So, in the meantime then, my thought is to connect the Spark Cores IO pins direct to the trigger pins on the FX board, and trigger them as if they were connected to a button.

Having not done this before though, my question then is is this safe? If I connect the grounds together, then connect up each trigger pin to an output pin on the spark, should I just be able to set them high on startup and momentarily set them low and back high to trigger the sound? Do I need to throw any resistors into the mix? or should direct connection be ok?

Thanks for the help.

Matt

1 Like

@mattbrailsford, if I understand correctly, you want to:

  1. On boot, set Core pins to HIGH
  2. On trigger, set the Core pins to LOW then HIGH again.

There have been reports of “glitching” of some Core I/O pins on boot-up though I am not sure if that is glitching HIGH or LOW. However, disregarding this, I would recommend using a pull-up resistor on your trigger lines and then simply using digitialWrite() to set the trigger pin LOW then HIGH to trigger the FX board. :smile:

Correct.

The FX board already has internal pullups already though so shouldn’t need any additional pullups right?

@mattbrailsford, in that case, you don’t need them! How are you powering the Core and the FX board?

Currently 4xAA batteries, although they are also powering a bunch of servos so not sure that’s the best, but I’m seriously limited on space.

@mattbrailsford, that’s not a lot of power for the Core, the servos and the FX board. Does the FX board have an on-board audio amp? Do you expect to put the core to sleep? How often do you move the servos?

Yea, the board has it’s own amp, no I won’t be putting the spark to sleep and the servos will be used intermittently. It’s for a spark controlled robot, so it’s more of a show piece than something that has to be energy efficient. I guess once I have it working, I’ll just need to workout how long the batteries will roughly last. Unless you have any other ideas?

@mattbrailsford, assuming the FX board and the servos are not running often then it comes down to the Core which will consume about 150ma with WiFi on. With a set of goo Alkaline batteries, the Core will run less than a day (about 15 hours). Lithium batteries will only supply 4.8V instead of 6V which may still work for you but won’t give you much more run time, if at all.

You could go with a LiPo battery and charger/converter like these from Adafruit:


At 6600mAh for the LiPo, the Core would run for just over 36hrs. If you can do solar, you could even use this SeeedStudio LiPo charger to run your project:

:smile:

Oooh, very interesting. I’ll have to run some tests on how well the servos perform on 3.7v as the batteries are a bit of a pain to get to, so if I could charge them in situe, that would be a big plus.

In other news I successfully have the spark core triggering the sound effects :smile:

You were also correct that there is a bit of a startup issue where the pin doesn’t get set fast enough, so I’ll have another look through your initial links as I recall them having a work around (of sorts).

In the end, I ultimately have the two boards running from the same power source, with shared ground, and have the pins connected directly. In setup I set the pins as INPUT, then I then use the following function to trigger the sounds (I found another forum post saying this was the best way to “emulate” a tactile button).

void triggerSound(int pin)
{
    digitalWrite(pin, LOW);
    pinMode(pin, OUTPUT);
    delay(150);
    pinMode(pin, INPUT);
}

Thanks for all your feedback, it’s been a big help.

Matt

1 Like

Dude! Just caught your video… this is sweet! Please publish your OSC library… that will be super useful for all. I’ve been wanting to use the TouchOSC controller for a long time now as it lets you create UI’s very easily.

@BDub thanks. It’s part of an entry for the “Enchanted Objects” instructable converting a Wall-e toy into something a bit more real :smile: Here’s a pic I posted on twitter of the Spark in situe, and given he is a cube, and he has got a big servo inside to control his neck, you can understand why space is such a premium.

I’ve pretty much got everything working now (though the battery issue mentioned above could mean it won’t last too long on a fresh set of batteries).

Regarding the OSC library, I can’t take the credit for that one, I found it in another forum post on here. Not sure which post it was, but this is the github repo:

It’s says there are some issue with sending data, but seeing as I’m purely interested in receiving commands, it works great. I just copied the OSCData, OSCMessage and OSCMatch classes into my project and then copied bits out of the application.cpp file there aswell.

I’ve got a blog post half written for putting that all together so will have to get that released shortly (I know it’s just piecing code snippets together, but I find sometimes it takes seeing a library being used in different ways to think how else you might use it).

Anyway, thanks for the comments, I know I don’t post a lot, but nice to see people like what I’m doing.

Matt

1 Like

Here’s an updated video.

2 Likes

I found another way that does not consume so many pins. The Adafruit FX Module also has the option of a serial connections.

You need to ground the ‘UG’ pin on the module. Connected the TX pins to the RX pins to the Module, then provide 5V and GND as normal.

So a total of 2 pins connected to the core. TX and in my case A0 for reset.

So in my code I have this in setup()

Serial.begin(9600);
Serial1.begin(9600);

(Serial is for debugging and Serial1 is the link to the Module)

And to trigger a ‘track’ you have to send the file name without the dot then directly afterwards send a new line.

{Serial1.println("PT06RAND0OGG\n");Serial1.println("");

If the file name has less than 8 characters in the name, you need to offset that with spaces.

And to restart on boot and trigger a remote reset on the module I did this.

  pinMode(REBOOT, INPUT);
  digitalWrite(REBOOT, HIGH);

Then added this in the loop().

TriggerReset(REBOOT);

Then created a fuction for TriggerReset.

void TriggerReset(int pin)
{
    digitalWrite(pin, LOW);
    pinMode(pin, OUTPUT);
    delay(150);
    pinMode(pin, MODE);
    digitalWrite(pin, HIGH);
}

So on boot it will reset the module and I can also reboot the module via a Spark.function()

And example of the remote reboot.

else if (command == "reset")          {TriggerReset(REBOOT); Serial.println("REBOOT - ADAFRUIT_FX BOARD");return 25;}

You can do other things like pass the filename directly to the module via a Spark.function.

Here’s an example of it in use.

https://goo.gl/photos/WfYzENymUWk1j6K87

Some info about that hardware in the video.

Spark core /w a Shield Shield. An Adafruit FX Module. 36 Neopixels. And a inductive speaker that has been recessed into the body of the sign. This is all controlled by SmartThings. There are about 36 sound files all teamed up with a visual effect.

One of the behaviors (And my favorite) When I get home, SmartThings detects my presence tag on my keys. It opens the garage door, Unlocks the door. then the house numbers turn on and plays the theme song to air wolf.

If a random person come up to the door (trips a motion sensor) then the Star Trek tricorder effect plays with a slow rainbow effect.

Heh. Halloween was a blast last year. In combination of the lights (The sign itself and all the lights in the house) and sounds. It was awesome.

At anyrate, I hope the info above helps anyone out.

1 Like

One quick. You can also control the volume remotely with a Spark.function().

Within the same function- In my case Spark.function("sounds", Sounds); I’ve added -

else if (command == "+"){Serial1.println("+\n");Serial1.println(""); return 17;}
else if (command == "-"){Serial1.println("-\n");Serial1.println(""); return 18;}

So at night when a SmartThings time event happens I have a SmartApp reduce the volume a bit. The downfall is that it resets to default if the module is reset.