Arduino Sound

Use this section to discuss your embedded Flowcode projects.
Post Reply
mnfisher
Valued Contributor
Posts: 2181
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 177 times
Been thanked: 1022 times

Arduino Sound

Post by mnfisher »

A slightly more involved project than my usual uploads - but if anyone is feeling brave would like to experiment here goes...

The idea:

I wanted to 'rig' an object to play a sound if it was moved. First obstacle - can an Arduino play a sound without additional hardware (and a DFPlayer setup probably would be little bulkier but a lot easier :-) - but not as much fun? ) - yes it can...

So using a single transistor (as an amplifier) and a small 8ohm loudspeaker - I connected the speaker (via the transistor) to Pin11 on a Nano (this code is very Arduino (Uno, Nano or Mega) specific) - and a 256kbit i2c eeprom (24lc256) to pins a4 and a5 (my original plan was to use an SD card - but I couldn't find an SD card small enough to work) - so we are limited to 4s (32k) of 8bit sound. (As an aside - it would be possible to use 8 x 256kbit eeproms for 32s sound - and create a 'mini' digital recorder)

I modified my sender (from a while ago - note the filename to send is in properties) to strip the 44 byte wav header and using a i2c_eeprom component from some time ago - programmed the eeprom with 32k of sound (found online - although audacity can also export in this format (8 bit 8000 samples per second - mono here)

The 'player' program uses a double buffer - one buffer playing and one being read from i2c - and seems stable.. Sound is not 'hi-fi' but surprisingly good (much better than a musical birthday card !)

If anyone would like to try with an SD card - the output pin can be changed to pin 9 with a little code 'surgery'

The sample length is currently hardcoded :geek: - it would be an easy 'fix' to pop the size into locations 0 and 1 of the eeprom.

The sound is output using PCM...
I2C_EEPROM.fcpx
(3.31 KiB) Downloaded 499 times
receive.fcfx
(14.28 KiB) Downloaded 626 times
(view online)
SENDER.fcfx
(13.5 KiB) Downloaded 543 times
(view online)
PCM.fcfx
(17 KiB) Downloaded 554 times
(view online)
Good luck.

Martin

Post Reply