Using a MAX7219/MAX7221 LED display driver with a netduino
In a previous post, I described how to drive an LED matrix relying on persistence of vision. While beautifully minimalist, this method has drawbacks: it requires 11 digital pins on the netduino and takes constant CPU cycles to refresh the matrix. This can potentially put tough resource constraints on the rest of the application.
This is where a chip like the MAX7219/MAX7221 LED display driver comes in handy: all you need to do is to send it the data that you want to display over SPI and it will drive LEDs without further involvement from the micro controller.
The chip offers 2 display modes: ‘Decode Mode’ is intended to manage 7 segment displays (plus a dot) and another which displays raw bitmaps instead, perfect for controlling an 8×8 LED matrix.
Multiple MAX72xx chips can be daisy-chained together to form larger displays as well.
Being a popular chip, a great deal has been written about the Max7219 and after you familiarize yourself with the datasheet, you should check out this article on the Arduino Playground and come back here when you’re done.
Connecting the MAX72xx to the netduino
Here are the hardware components that you’ll need:
- 1 Max72xx chip
- 1 monochrome LED matrix (for example)
- 1 Logic-level shifter (DigiKey) (optional: see note below)
- 1 10K resistor minimum
- 1 100 uF capacitor
- 1 0.1 uF ceramic capacitor
- many hookup wires (as short as possible)
Note: The MAX72xx requires 3.5 volt logic levels minimum and because the netduino uses 3.3 volt logic level on its digital output pins, you may need to place a logic-level shifter between the netduino SPI interface and the Max72xx SPI interface. Check out this article if you’re not sure how this works.
While the Max72xx SPI clock can go up to 10 MHz based, I was unable to get stable communications above 2 MHz when using the MAX7219 with a logic-level shifter. Without the shifter, SPI @ 10 MHz works flawlessly but because this is out of the chip’s specifications, so your mileage may vary.
The following summarizes the connections. It doesn’t matter which pins you choose on the logic-level shifter provided that they’re matching low-level input/high-level output pins.
- SPI CLK: netduino pin 13 -> Logic-level shifter -> Max72xx pin 13 (CLK)
- SPI MOSI: netduino pin 11 -> Logic-level shifter -> Max72xx pin 1 (DIN)
- SPI CS: netduino pin 10 -> Logic-level shifter -> Max72xx pin 12 (LOAD/CS)
Note: the MAX72xx is extremely sensitive to EMI and power fluctuations. So, be sure to:
- Place the capacitors as close as possible to the V+ and GND pins of the chip
- Connect both GND pins to ground
- Use the shortest possible hookup wires
If EMI is an issue, reducing the speed for the SPI bus and/or using shorter hookup wires may help. If you still have EMI issues, the MAX7221 is likely the right alternative.
Connecting the Max72xx to the LED matrix
The LED matrix that I’m using is wired like this:
Connecting it to the MAX72xx is straight forward:
- The MAX72xx’s SEG pins correspond to the columns of the LED matrix
- The MAX72xx’s DIG pins correspond to the rows on the LED matrix
Using the netduino.helpers Max72xx C# driver
The C# driver attempts to stick to the Max72xx datasheet as closely as possible. It presents properties matching the various registers of the chip and a simple overloaded ‘Display’ method. Be sure to check out the unit tests in the /Samples for usage details.