I2S to play sound on Particle P1/Photon

Hello,

I’ve got a Particle P1 device that I’m trying to get sounds playing on using an external amplifier.
The chip I’m using for the amplifier is the MAX98357A, which uses the I2S standard for operation.

I’ve currently got the amp connected to the SPI1 enabled pins, and I’m having some trouble figuring out how to reliably play sounds through the device.

My pinout is as follows:
Amp connection - Particle P1
Mode select (SD_MODE) - P1S4
Data Clock (BCLK) - D4 (SPI1 SCK)
Left/Right channel clock (LRCLK) - D5 (SPI1 SS)
Data in (DIN) - D2 (SPI1 MOSI)

One problem is that the amp requires a second clock for Left/Right channel selection, which operates a 1/16th of the Data clock, and I can’t seem to find a way to reliably set a secondary clock for for SPI1.

Also to be considered is that the RAM can barely hold a quarter of a second of audio at CD quality, but I’m just looking to play simple sounds, and I can reliably load content from an SD card attached to the device (which is on SPI0), so I can theoretically do some kind of multiple buffering trickery with RAM.

I was wondering if anyone had worked out any previous I2S implementations or done any work regarding playing sound out of the device that is ideally not too processor heavy (so ideally through DMA, interrupts are too processor intensive and the device is doing other things).

I’ve taken a look through the forums already and haven’t found anything applicable.

I’m also fine to not use that external amplifier or changing my approach if there’s an easier solution that I’m just missing completely.

Any help would be appreciated.
Thanks!

If you’re not set on using your existing setup, several people have had success using the DFPlayer mini to play sounds or full songs. It has an amplifier built in, though I’m not sure how loud you’re looking for.

Thanks for the suggestion! It looks like a very useful module.

We have a custom PCB printed atm which houses both the amp and the P1, so I’ll float the idea past the other people working on the PCB design.
Not looking to play sounds that are particularly loud, so it looks reasonable for our format at a first glance.

Ideally though I’d like to find a solution that either works with the amp we’ve got currently on-board or can be somehow run natively onboard.

I’ll keep it in mind if there isn’t any other solution found though, because it does look like it could be a lot more simple to work with!
Thanks for your help.

Edit:
On review, $8.10 a chip is pretty expensive, outpricing what the particle P1 itself costs, and having a seperate flash storage means that if we ever need to update the sounds on the device, we’d have to go to each device, dissasemble it and remove the SD card, and re-write its contents. As far as I’m aware there’s no nice way to do that through the chip.

It looks great for small applications but is probably not ideal for what we’re looking for.

That depends where you are sourcing them. You can get them at less than 1USD.
However the SD card issue doesn’t go away immediately, although with some fiddling you might be able to tap into the SD card slot (or even incoporate the mp3 chip directly).

2 Likes

That’s true, I’ll have to look for some lower level documentation.

I’m keen to see if we can find an answer that incorporates I2S though, as it’s the currently intergrated chip on our PCB, and would require less replanning and reprinting.

I see a lot of past questions on the forum in relation to I2S going dead in the water, so it might be more useful to future searchers as well to have a both answers, for those that need to operate with I2S, for say a specific microphone or speaker setup.