This button will download a folder containing all the code needed for this project:
The code can also be found on Github.
After uncompressing the ZIP file, inside you’ll find a folder called Piccolo. This can be moved to your Arduino documents folder if you like. The Piccolo.ino file in there is the main project source code — open this in the Arduino IDE.
Two libraries are required for this: Adafruit_LEDBackpack and Adafruit_GFX. If you worked through the basic LED matrix backpack guide first, these should already be present. Otherwise, both can be found in the Arduino Library Manager (Sketch→Include Library→Manage Libraries…)
If there’s no response from the device, try the following:
- Test the matrix using the example code from the Adafruit_LEDBackpack Library. If there’s no response, the clock and data pins might be swapped, or the matrix may have been soldered to the board backwards.
- Double-check all wiring against the diagrams. Did you include the 3.3V-to-AREF connection? D and C pins from the matrix backpack should connect to SDA and SCL on newer Arduinos, or analog pins 4 and 5 on older boards.
- The gain on the mic amplifier may be set low. There’s a dial on the back of the board that can be adjusted with a small screwdriver.
- Try increasing the music volume.
Using the normal Arduino analogRead() function would be much too slow for sampling audio. Instead, a feature of the microcontroller’s analog-to-digital converter called free-run mode is utilized. This automatically takes repeated analog samples at precise intervals…about 9.6 KHz for this project, the maximum a 16 MHz Arduino can handle with 10-bit samples.
This is strictly mono. There isn’t enough RAM or processor oomph for stereo.
The raw audio samples are converted into a frequency spectrum using a fast Fourier transform or FFT. There are a number of Arduino FFT libraries out there, but we keep finding ourselves returning to the venerable ELM-ChaN ffft library for its speed and good looks.
The FFT output still needs a bit of massaging to make for a good presentation on the limited 8x8 matrix. Several tables of scales and weights de-emphasize certain frequency ranges as they’re reduced to just eight columns. The software works at keeping the graph interesting, but some columns will always be less lively than others, especially comparing live speech against music of varying genres. If everything seems to stick toward one end of the graph, try another musician, musical genre, or different speakers.