Hello,
Recently, I built a small animatronic project that used the Music Maker Shield + Mega to play audio synchronized to prerecorded servo movements. My original hope was to do this all with one Arduino, but in the end I couldn't get the Arduino to feed audio to the music maker shield and read from my sequence file. It did actually work but only for a bit then things would go south pretty quick (reads from the sequence stopped happening)
In the end, I added another uno with its own sd shield storing the sequence files and had the mega start the sequence via i2c. It worked ok, but it's clunky, takes a lot of work to keep the two boards in sync, and it's expensive.
I'm working on a new similar project and thought I check if anyone has any suggestions. Here's what I think is happening (could be flat wrong of course):
The vs1053 can safely accept 32 bytes per write, but it has an internal 2048 byte buffer. The shield code only reads 32 bytes from the sd card when the chip signals it needs data. I *think* this keeps the sd card tied up and holds up reads on the sequence file.
I'd like to modify the shield code to buffer sd card reads to a buffer and then feed the vs1053 as needed from the buffer. I played around with this a bit but ran out of time and never got it working.
Am I on the right track?
If it's helpful, the new project will drive 12 servos, one byte per channel that represents the servo positions, with one animation frame per 100ms, so it's not a ton of data I need to read from the sequence file and a small buffer should keep the servos happy for a while before needing to refill their buffer.
I don't have the code from my previous project, but I can slam it back together pretty quick if it's helpful.
Thanks!
Music Maker shield and servo sequence
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Music Maker shield and servo sequence
Under the hood, the SD library is reading data from the card in 512 byte blocks - because that is the minimum chunk you can read from an SD card. The SD library is managing the streaming from its own file buffer. On an UNO, with only 2K of SRAM, it is not really practical to keep 2 512 byte buffers around. A Leonardo would give you another 512 bytes to play with. The Mega has 8K of SRAM.The shield code only reads 32 bytes from the sd card when the chip signals it needs data. I *think* this keeps the sd card tied up and holds up reads on the sequence file.
- cmcpherson
- Posts: 2
- Joined: Sun Nov 30, 2014 1:30 am
Re: Music Maker shield and servo sequence
Thanks for the reply...
That makes sense. This is running on a mega, so I've got some room. So, except for memory limitations having the two files open and reading from them in the way I described should work fine?
That makes sense. This is running on a mega, so I've got some room. So, except for memory limitations having the two files open and reading from them in the way I described should work fine?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Music Maker shield and servo sequence
With a Mega, you should have plenty of room to buffer the data as you describe.
- ghgeoff
- Posts: 2
- Joined: Wed Aug 05, 2015 8:54 am
Re: Music Maker shield and servo sequence
Hi cmcpherson
I'd be interested to hear if you got this working please?
I plan to use a mega with the music maker shield to play a series of sound files while I read and simple images from the sd to display on neomatrix.
The plan being to read the images into memory then keep the sound buffer topped up.
I guess I'm really asking if the mega reading directly from the SD card could mess up the sound ?
Cheers
G
I'd be interested to hear if you got this working please?
I plan to use a mega with the music maker shield to play a series of sound files while I read and simple images from the sd to display on neomatrix.
The plan being to read the images into memory then keep the sound buffer topped up.
I guess I'm really asking if the mega reading directly from the SD card could mess up the sound ?
Cheers
G
Please be positive and constructive with your questions and comments.