NodeMCU8266驱动8×8点阵max7219

Since the awesome de.

Since the awesome devsaurus recently fixed important SPI issues (#50 is from Christmas 2014!) in NodeMCU it’s now possible to run MAX7219 8×8 LED matrix displays with an ESP8266 and the NodeMCU firmware.

Connect NodeMCU with MAX7219 display

According to the pin layout for the NodeMCU dev kit v1 and v2 (see comparison) you need to connect the MAX7212 as follows:

MAX7219 ESP8266 NodeMCU devkit
VCC +3.3V 3V3
GND GND GND
DIN HSPID/HMOSI D7
CS HSPICS/HCS D8
CLK HSPICLK/HSCLK D5

In the second column I listed commonly found names on pin layouts and schemas. The values in the third column signify the actual pin numbers as printed on the NodeMCU development boards.

Drawing on the MAX7219

Writing and drawing on those 8×8 matrix displays took some getting used to for me. Interestingly the fact that you can rotate them whichever way you like made it more difficult rather than less difficult. There is a way to identify pin 1 but eventually it doesn’t really matter. However, you need to understand how “characters” are represented.

In font files (e.g. cp437.h) you’ll usually see one character per line as an array of 8 hex values. This could look as follows for ‘0’ (zero) :

{ 0x3E, 0x7F, 0x71, 0x59, 0x4D, 0x7F, 0x3E, 0x00 }

MAX7219 8x8 LED matrix displaying 0x3EThere is one byte per column of the 8×8 matrix i.e. 8 bytes. One byte signifies which of the 8 LEDs in a column should be turned on. 0x3E in binary form is 00111110 and every bit represents the state of one LED. So, the first LED and the last two will be OFF while the others will be ON. Again, the notion of “first” and “last” of course depends on the orientation of the matrix but as long as all characters are defined consistently it doesn’t matter. 0x3E on the matrix will look as shown on the left.

 

Moody, cycling through smilys

Moody is a simple program that declares 3 smilys and an array which contains all of them. It shows how to initialize NodeMCU SPI for the MAX7219 8×8 LED matrix and how to cycle through the smilys array and display one face after the other in a loop.

Showtime, please