This is a list of tips and tricks I wish I knew before spending days programming the Arduino Audio Meter.
I'm sure that if you have a quick read you will learn and avoid traps!
1. The Encoder
The encoder also includes a push button, it uses 3 lines for the encoder and 1 for the push button:
Technically you only need 2 lines for the encoder, the third one is grounded. But to have more versatility you can wire the 3 lines to the Arduino board and then set one of the lines to the ground by software. So if in the future you want to experiment this line could be available.
Programming the Encoder:
To main ways of doing this: by pooling or interrupt:
Pooling: You put the encoder function in the main loop and the code check if the lines have changed. The
Interrupt: When the encoder changes, it generates an interruption and the encoder function is executed. Codes like the
My tip: to use the interrupt way: makes the main loop faster and generally works better.
You would need to install the EnableInterrupt.h libraries for using the encoder with interruptions, but it's simple: go to Tools/Manage Libraries.. and search for "EnableInterrupt"
2. The Analog Input Stage Circuit.
The plan is to amplify the analog audio signal so the Arduino ADC can read it. We use a rail-to-rail op amp (that means that can work powered in 5V and give a good output voltage).
Pros: The circuit is simple and can be used with almost any kind of audio source: guitar, keyboard, mp3, laptop, line level, etc.
Cons: The Gain potentiometer action is "logarithmic", that means that in the last half of the action the gain increases more. If you just know you will see that at the end of the pot action is when all really happens. It's a small price to pay for a simple circuit that works great.
note: The input is directly connected to the output, so you can use any jack as input or output.
3. The 8x8 LED Matrix:
There are many you can buy in the market, most of them with similar pinout and square but in different sizes: 20mm, 32mm, 60mm
In the Arduino Audio Meter, we use the 38mm: these are the ones we found easier to buy and used everywhere, the part number is "1588BS".
Common Anode vs Common Cathode
There are main categories again, the diodes are placed differently on each other:
The 1588BS used in this project are Common Anode .
You cannot use the other one (common cathode) and change the software
4. The Drivers:
You can directly connect the 8x8MAtrix to the Arduino board without a driver, but you would need 16 pins for each matrix. If you want to connect 4 matrices you run out of pins. This is why we use the MAX7219 to drive the 4 matrices. You just need 3 lines to drive all of them!
5. Libraries for the 8x8Matrix and Drivers:
You would need a library to use the MAX7219 drivers, there are many out there ("LedMatrixDriver", "MD_MAX72XX", "U8g2", etc). We tried many and the one that works the best is the "LedControl.h". This is the one we use in all the codes.
On top of that, we found in the Arduino Forums a super-fast variant of "LedControl.h": forum.arduino.cc/index.php?topic=350313.0
This 10x fast ledcontrol.h makes a huge difference when you want to represent fast audio signals or games, so we really recommend to use it. This library is included in the same folder as the codes and when you compile it the program will take it from the same folder.
6. Programming Tips
My last but best advice: don't reinvent the wheel.
As you will see, all my codes are based in existing codes I found online. There are hundreds of good codes out there using Arduino and 8x8 matrices.
What I usually do is search in google for "Arduino 8x8 matrix MAX7219" + "what I want to do like: "Arduino 8x8 matrix MAX7219 snake game" or Tetris, or spectrum analyzer. Most of the times the codes are done for one matrix or maybe 2.
My job is then just to adapt a working code to a 16x16matrix.
There are still great codes out there that I did not have time to adapt: