Over the years NVIDIA have released a line-up of Jetson Developer Kits, small, power-efficient AI computers. With models including the Jetson Nano, Xavier NX, and the AGX Xavier, NVIDIA have produced a line of compact computers capable of efficiently deploying AI solutions in various environments to meet diverging needs and expectations.
The Jetson Nano Developer kit is a small, powerful computer which allows users to run multiple neural networks simultaneously for applications of image classification, object detection, segmentation, and speech processing — all in a compact device consuming as little as 5 watts. The Jetson Nano development kit comes equipped with various peripheral devices including USB, Ethernet and HDMI connections. One missing but common peripheral is some form of audio input or output. Numerous devices these days come equipped with audio jacks, and some even carry on-board microphones.
There are many ways to go about adding audio capabilities to a Jetson device. USB speakers and USB microphones are an easy solution, but they do take up valuable USB slots which may be better served for keyboards, adding Bluetooth capability, Internet Keys, and other accessories.
On the Jetson devices, NVIDIA provides access to a range of peripherals such as I2C, SPI, and I2S via a 40-pin GPIO expansion header. For the sake of working with audio, we are most interested in the I2S peripheral, an electrical serial bus interface used to connect digital audio devices. We do not need to create an I2S functionality from scratch, but knowing the ins and outs of common communication protocols is always useful, so for more information on the I2S check out this great article.
The Jetson’s 40-pin expansion header allows us to access the I2S peripheral easily, and with the appropriate additional Electronics — we can quickly take advantage of the I2S functionality.
Our Hardware of Choice
The Adafruit I2S MEMS Microphone breakout board (SPH0645LM4H) is a compact audio recording solution with an input frequency range of 50 Hz to 15 kHz. The board does not feature an analog output but rather a purely digital one.
Many micro-controllers typically come equipped with an analog input, making the addition of an analog audio signal a straightforward task. For larger and more complex micro-controllers and micro-computers, an analog input is not guaranteed. To compound the issue, analog microphone systems are known to have noise seep into them. In place of an analog input, an I2S peripheral may commonly be found.
The microphone is a single mono element — you can opt to make use of the left or right channel. For those who would prefer/require stereo, a simple configuration using two microphones can be easily implemented with one microphone set to the left channel, and a second microphone set to the right channel. It is also worth nothing that this device is a slave device, and must be fully driven using an external logic.
The Adafruit MAX98357 I2S Class-D Mono Amp is suited to micro-controllers and microcomputers which have digital audio capability. It can receive a standard I2S digital audio input, and decode it into analog signal before amplifying directly into a speaker. This compact breakout board solves two common tasks for digital audio outputs: I2S digital to audio conversion (DAC) and amplification. The amplification gain can also be modified with the addition of well chosen resistors or variable resistors.
The output is an approximate 300kHz square wave PWM which is averaged out by the speaker coil — high frequencies are not heard. It is in fact capable of driving a generic speaker directly without any intermediate steps.
This small mono amplifier punches above its weight — able to deliver up to 3.2 Watts of power into a 4 ohm impedance speaker (5V power @ 10% THD). The amp is incredibly efficient, given its class D architecture, making it easy run from 2.7V to 5.5V DC supplies — perfect for portable and battery-powered projects.
Setting up the Jetson Nano
The Jetson Nano is the heart and center piece of this project. Setting up the Jetson Nano is a well-documented process. You can find various resources as to how to accomplish this task. One such guide would be the following: https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit
For our task, the Jetson Nano will need a USB to UART cable for power and programming, a keyboard, mouse, and HDMI monitor. Furthermore, we need to wire up our breakout boards to the Jetson Nano:
MAX98357A Board -> Jetson Nano PinsLRC -> 35
DIN -> 40
BCLK -> 12
GND -> GND
VIN -> 3V
SD -> 3V (can be changed)
GAIN -> 100k resistor connected to GND (can be changed)
Make sure to also connect your MAX98357A outputs to a speaker. We used an 8 Ohm, 15 Watt speaker with a 3.3V supplied from the Jetson Nano.
Configuring the I2S
Once you have Jetson Nano booted up, it is a very straightforward process to configure your I2S pins in the Jetson 40-pin GPIO expansion header:
- ) On the developer kit, open a command line terminal and run the following:
$ sudo /opt/nvidia/jetson-io/jetson-io.py
- ) Jetson will launch and its main display shown. In our case we want to Configure the Jetson 40pin Header and Configure header pins manually.
- ) On the “Select desired functions (for pins):” page, select the i2s4 option.
- ) Afterwards, you will be taken back to the main page and asked to reboot and save the re-configurations you have made, so go ahead and reboot.
Should you require further guidance on configuring your Jetson pins, please check out this link.
After you have rebooted and logged back into your Jetson Nano, you’ll want to install to install any updates, and download a couple of libraries.
$ sudo apt update
$ sudo apt install python3-pip
$ sudo pip3 install Jetson.GPIO
$ sudo apt-get install alsa-utils
Let’s initialize our microphone settings: all we have to do is reset our sound card, set our volume, and specify the path we would like our audio signal to use.
$ alsactl init tegrasndt210ref
$ amixer -c tegrasndt210ref cset name="MVC1 Vol" 13500
$ amixer -c tegrasndt210ref cset name="ADMAIF1 Mux" I2S4
After setting the sampling rate (48kHz), and specifying the desired length of recording (in this case 30 seconds), we can finally begin recording!
$ arecord -D hw:tegrasndt210ref,0 -r 48000 -f S32_LE -c 1 -d 30 test.wav
After recording you’ll notice that we now have a file called “test.wav”, this is the recorded audio. We’re not quite done yet though, we can also play the recorded audio back. Let’s reset the sound card and set our volume.
$ alsactl init tegrasndt210ref
$ amixer -c tegrasndt210ref cset name='I2S4 Mux' MVC1
$ amixer -c tegrasndt210ref cset name='MVC1 Mux' ADMAIF1
$ amixer -c tegrasndt210ref cset name='MVC1 Vol' 16000
All that’s left to do now is input the command to play the generated audio file.
aplay -D hw:tegrasndt210ref,0 test.wav
Be sure to take a moment to sit back and enjoy listening to the speaker. Please feel free to check out our-mini demo. We recorded a song via the SPH0645 microphone and played it back using the MAX98357.
Mission accomplished! We’ve successfully built an end-to-end audio system for the Jetson Nano development kit, powered by nothing but a USB cable. You could possibly include a machine learning model next and playback an altered version of the recording. Consider translating from one language to another, adding audio effects such as filtering and compression, or creating a voice mapping (who wouldn’t want to sound like Darth Vader or Morgan Freeman?)
If anyone would really like to get into possibilities of audio, conversational, and vision AI, there is no better place to start than right here. SmartCow has decided to go ahead and design the Apollo Development Kit.
About the Author
Luke Abela is an AIoT Engineer working with SmartCow AI Technologies Ltd. at their Malta office. He obtained his Bachelor of Engineering from the University of Malta before pursing a Master of Science in Artificial Intelligence at Queen Mary, University of London.
- ) https://developer.nvidia.com/embedded/jetson-developer-kits
- ) https://hackaday.com/2019/04/18/all-you-need-to-know-about-i2s/
- ) https://learn.adafruit.com/adafruit-max98357-i2s-class-d-mono-amp
- ) https://www.adafruit.com/product/3421
- ) https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit
- ) https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/hw_setup_jetson_io.html