Jetson Nano audio output
My nanny bot should be able to play some sound effects. The problem here is that there’s no audio output on the Jetson Nano developer kit board. To be more precise, there’s HDMI/DP, but I do not want additional attach adapters and make the bot bigger (wider).
I²S, SPI, … what is this
Couple of options. I²S (it’s not I²C, see, S vs C) or SPI. If you don’t know what it is, I recommend to read linked Wikipedia articles. What are the differences?
There is a lot more to audio than bandwidth. The way I²S works, the data are provided just in time to be converted to analog. So the I²S DAC or codec doesn’t need to buffer data or maintain any type of complex synchronization. It relies on the incoming clock to determine the sample rate. This also means that the data must be sent continuously, meaning that the I²S bus will be completely utilized at all times while audio is playing.
If you wanted to use SPI the same way, you would have to run it at exactly the right rate, always delivering data just in time to be converted to analog. This means that the bus would be 100% occupied during audio playback and unavailable for anything else. Otherwise you would need to work out a complex buffering scheme and hardware flow control to tell the host when to send more data, etc.
I guess a simple way of answering the question is that I²S is specifically deisgned to send audio to a DAC. SPI is more general purpose. Most SPI implementations do not support the type of fine-grained clock speed control that would be needed to interface directly to a DAC the way I²S does.
Source: https://electronics.stackexchange.com/a/384342
I²S is clearly the winner here.
SFIO
There’s another problem. By default, all those pins on the Jetson Nano are GPIO. But we need SFIO (Special Function I/O), which is a dedicated function within the SoC. This must be set before or during the boot.
To achieve this, we have to:
- decompile DTB,
- patch DTS,
- compile DTB,
- flash DTB.
gpio-to-i2s
I’m going to stop now. It’s more complicated and it has no sense to cover all those details. So, if you’d like to use I²S DAC (digital to analog converter) + amplifier + speaker, check the gpio-to-i2s folder (be aware, jetbot
branch).
It contains all the steps you have to proceed with and there’s also patch-and-flash.sh
script, which automatically patches the DTB and flashes Jetson Nano for you.
But before you proceed, please, read the whole README. You have to put Jetson Nano into recovery mode, etc.
HW
I’d like to keep nanny bot as small as possible and I’m throwing away previously purchased amplifier. Did order Adafruit I²S 3W Class D Amplifier Breakout - MAX98357A for £6.23.
From the description:
… Perfect for adding compact amplified sound, it takes 2 breakouts (I²S DAC + Amp) and combines them into one …
In other words, I have a very small board, which combines I²S DAC + amplifier.
Photo source: https://www.adafruit.com/product/3006
Just ordered it, so, all these things I mentioned here are untested. I mean, I flashed the Jetson Nano with patched DTB, it boots, /sys/kernel/debug/tegra_gpio
looks good, … but … Will test it next week when the DAC + amp will arrive.