maxresdefault

Wemos D1 Mini ESP8266 – Matrice a LED 32×8 MAX7219 (LED Matrix)

Ciao a tutti.

In questo post, come dice il titolo, vedremo come collegare ed utilizzare una Matrice a LED da 32×8 con chipset MAX7219 grazie alla scheda Wemos D1 Mini.

[amazon_link asins=’B01N9RXGHY’ template=’ProductAd’ store=’weblocale-21′ marketplace=’IT’ link_id=’2c44e825-ab65-11e8-b01f-d3801887965d’]

La matrice a LED 32×8 è composta da 4 singole  matrici LED da 8×8 (64 LEd) collegate in cascata.

[amazon_link asins=’B079HVW652′ template=’ProductAd’ store=’weblocale-21′ marketplace=’IT’ link_id=’43316fd1-ab65-11e8-aa0b-d579d1ba1b8d’]

Ogni matrice appunto è composta da 64 LED e per pilotare questa matrice ci viene in aiuto il MAX7219 che permette di pilotare 64 LED se questi vengono collegati a matrice. Per il pilotaggio sono necessari solo 3 fili più l’alimentazione. Ecco lo schema

.Ecco come si può pilotare una matrice di 64 LED con un MAX7219Risultati immagini per led matrix 32x8

I moduli che ho acquistato io possono essere collegati in cascata e quindi permettono di visualizzare dei messaggi più lunghi e complessi e ha questo aspetto e dimensioni:
Immagine correlata
Il collegamento tra la scheda e la matrice è molto semplice. Vanno collegati oltre a Ground e 5v altri 3 pin della scheda seguendo questo schema.
Risultati immagini per wemos d1 mini led matrix schema
Una volta effettuati i collegamenti non ci resta che caricare un programma di esempio per vedere se tutto funziona correttamente. Io personalmente utilizzo questa libreria md_max72xx .
Installiamo la libreria dall’ide ARDUINO e proviamo a caricare lo sketch di esempio opportunamente modificato per adattarsi al mio hardware e configurazione di pin.

[code lang=”c”]
// Use the MD_MAX72XX library to Print some text on the display
// Demonstrates the use of the library to print text.
// User can enter text on the serial monitor and this will display as a
// message on the display.

#include MD_MAX72xx.h;
#include SPI.h;

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted

// IMPORTANTE Dalla versione 3.0.0. della libreria per questo particolare
// hardware usare FC16_HW e non PAROLA_HW come in altri esempi altrimenti le scritte saranno
// al contrario o tutte casuali.
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN D5 // or CLK
#define DATA_PIN D7 // or DIN
#define CS_PIN D4 // or CS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Text parameters
#define CHAR_SPACING 1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char message[BUF_SIZE] = {"Hello!"};
bool newMessageAvailable = true;

void readSerial(void)
{
static uint8_t putIndex = 0;

while (Serial.available())
{
message[putIndex] = (char)Serial.read();
if ((message[putIndex] == ‘\n’) || (putIndex >= BUF_SIZE-3)) // end of message character or full buffer
{
// put in a message separator and end the string
message[putIndex] = ‘\0’;
// restart the index for next filling spree and flag we have a message waiting
putIndex = 0;
newMessageAvailable = true;
}
else
// Just save the next char in next location
message[putIndex++];
}
}

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
uint8_t state = 0;
uint8_t curLen;
uint16_t showLen;
uint8_t cBuf[8];
int16_t col = ((modEnd + 1) * COL_SIZE) – 1;

mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

do // finite state machine to print the characters in the space available
{
switch(state)
{
case 0: // Load the next character from the font table
// if we reached end of message, reset the message pointer
if (*pMsg == ‘\0’)
{
showLen = col – (modEnd * COL_SIZE); // padding characters
state = 2;
break;
}

// retrieve the next character form the font file
showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
curLen = 0;
state++;
// !! deliberately fall through to next state to start displaying

case 1: // display the next part of the character
mx.setColumn(col–, cBuf[curLen++]);

// done with font character, now display the space between chars
if (curLen == showLen)
{
showLen = CHAR_SPACING;
state = 2;
}
break;

case 2: // initialize state for displaying empty columns
curLen = 0;
state++;
// fall through

case 3: // display inter-character spacing or end of message padding (blank columns)
mx.setColumn(col–, 0);
curLen++;
if (curLen == showLen)
state = 0;
break;

default:
col = -1; // this definitely ends the do loop
}
} while (col >= (modStart * COL_SIZE));

mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}

void setup()
{
mx.begin();

Serial.begin(57600);
Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");
}

void loop()
{
readSerial();
if (newMessageAvailable)
{
PRINT("\nProcessing new message: ", message);
printText(0, MAX_DEVICES-1, message);
newMessageAvailable = false;
}
}
[/code]

3 commenti su “Wemos D1 Mini ESP8266 – Matrice a LED 32×8 MAX7219 (LED Matrix)”

  1. Do you mind if I quote a few of your posts as long as I provide credit and sources back to your website? My blog is in the very same niche as yours and my users would definitely benefit from a lot of the information you present here. Please let me know if this okay with you. Many thanks!

  2. I as well as my buddies have been examining the great helpful tips located on your site and then before long I had an awful suspicion I never expressed respect to you for those strategies. Those people came as a result stimulated to read all of them and now have definitely been taking advantage of those things. Appreciation for genuinely well thoughtful and then for making a decision on certain awesome subjects most people are really eager to know about. My personal honest regret for not expressing gratitude to sooner.

  3. I am also commenting to let you know what a cool encounter my friend’s child found studying the blog. She noticed several details, which included what it’s like to possess a wonderful coaching spirit to let other folks smoothly master certain tricky matters. You really did more than our expected results. Thanks for displaying the insightful, trustworthy, explanatory and even cool tips on this topic to Tanya.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Torna su