Photon 2 speaker / analog audio output

I recently got my hands on a Photon 2 and was hoping to play some audio with it. With the first generation Photon, I was able to use the speaker library, which uses the Photon's DAC with DMA defined by the STM32 library under the hood.

The Photon 2 is based on a RTL8721DM chip however, and not only that but I realized it doesn't come with an onboard DAC (the migration guide suggests hooking up an external one).

So the first thing I tried was to use PWM and play some 8 bit audio with analogWrite(), by exporting signed 8 bit PCM from Audacity and modifying the tool here to output an 8 bit array. However, it sounds terrible and the sound is nearly unrecognizable. While I could try to put some low-pass filter on the end, it seems like the best thing is to get some true analog output with a DAC. Or I could fall back to much simpler Atari-style tones but where's the fun in that? :slight_smile:

Anyone have recommendations for a DAC that would work, and also any library like speaker that would work for playing audio?

One of the least painful methods is the DFMiniPlayer. It has an SD card socket and communicates by UART serial to select what to play. Cheap and easy. See this very long community thread.

There currently isn't a driver for the P2/Photon 2, but it should be possible to use I2S (S as in sound, not I2C). This is the best option if you need to generate sounds in software, as opposed to just playing pre-recorded sounds, but also the software doesn't exist yet. You could look at the MicrophonePDM library. It's PDM not I2S but it does show how to access the audio peripheral on the RTL872x from user firmware.

Using a DAC would work, but is not the best solution for audio because of the amount of data you'll need to stream to it over I2C or SPI. It's just not a very efficient way to do it.

Thanks! I'll give the DFMiniPlayer approach a shot. Seems pretty easy to find those boards on Amazon (fastest) or other stores (cheapest).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.