tecnologia:iot:panel_baterias
This is an old revision of the document!
Table of Contents
Panel led de 4 módulos: MAX7219
Esquema de conexión:
| LED | ESP32 |
|---|---|
| VCC | 3V3 |
| GND | GND |
| DIN | G23 |
| CS | G5 |
| CLK | G18 |
Utilizaremos la biblioteca (que no librería) md_max72xx
https://www.arduino.cc/reference/en/libraries/md_max72xx/
La podemos instalar con el manager de arduino, en tools > Manage Libreries
Yo he instalado MD_Parola que te deja hacer efectos. Te dirá que tiene dependencias y le decimos que instale todas.
Mensaje sencillo
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <WiFi.h>
#include <AsyncElegantOTA.h>
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 4
#define CS_PIN 5
const char* ssid = "mi_red_wifi";
const char* password = "mi_contraseña_wifi";
IPAddress ip(192,168,1,69);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress dns(8,8,8,8);
AsyncWebServer server(80);
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
Display.begin();
Display.setIntensity(0);
Display.displayClear();
Serial.begin(115200);
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet, dns);
Serial.print("Connecting to ");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "V1.0 Prueba Panel Led");
});
AsyncElegantOTA.begin(&server);
server.begin();
Serial.println("HTTP server started");
Display.print("V 1.0");
delay(1000);
}
void loop() {
Display.setTextAlignment(PA_LEFT);
Display.print("Hola");
delay(10000);
}
Explicación código:
Número de paneles:
#define MAX_DEVICES 4
Alineamiento y lo que queremos escribir.
Display.setTextAlignment(PA_LEFT);
Display.print("Hola");
SCROLL
Escribe lo que le pongas en el serial:
// Use the Parola library to scroll text on the display
//
// Demonstrates the use of the scrolling function to display text received
// from the serial interface
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.
// Scrolling direction is controlled by a switch on DIRECTION_SET digital in.
// Invert ON/OFF is set by a switch on INVERT_SET digital in.
//
// UISwitch library can be found at https://github.com/MajicDesigns/MD_UISwitch
//
// NOTE: MD_MAX72xx library must be installed and configured for the LED
// matrix type being used. Refer documentation included in the MD_MAX72xx
// library or see this link:
// https://majicdesigns.github.io/MD_MAX72XX/page_hardware.html
//
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
// 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
#define MAX_DEVICES 4
//#define CLK_PIN 13
//#define DATA_PIN 11
#define CS_PIN 5
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
// HARDWARE SPI
MD_Parola P = MD_Parola(HARDWARE_TYPE,CS_PIN, MAX_DEVICES);
// SOFTWARE SPI
//MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
uint8_t scrollSpeed = 25; // default frame delay value
textEffect_t scrollEffect = PA_SCROLL_LEFT;
textPosition_t scrollAlign = PA_LEFT;
uint16_t scrollPause = 2000; // in milliseconds
// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE 75
char curMessage[BUF_SIZE] = { "" };
char newMessage[BUF_SIZE] = { "Hello! Enter new message?" };
bool newMessageAvailable = true;
void readSerial(void)
{
static char *cp = newMessage;
while (Serial.available())
{
*cp = (char)Serial.read();
if ((*cp == '\n') || (cp - newMessage >= BUF_SIZE-2)) // end of message character or full buffer
{
*cp = '\0'; // end the string
// restart the index for next filling spree and flag we have a message waiting
cp = newMessage;
newMessageAvailable = true;
}
else // move char pointer to next position
cp++;
}
}
void setup()
{
Serial.begin(115200);
Serial.print("\n[Parola Scrolling Display]\nType a message for the scrolling display\nEnd message line with a newline");
P.begin();
P.displayText(curMessage, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}
void loop()
{
if (P.displayAnimate())
{
if (newMessageAvailable)
{
strcpy(curMessage, newMessage);
newMessageAvailable = false;
}
P.displayReset();
}
readSerial();
}
Mensaje de **conectando a wifi** mientras conecta
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <WiFi.h>
#include <AsyncElegantOTA.h>
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 4
#define CS_PIN 5
const char* ssid = "mi_red_wifi";
const char* password = "mi_contraseña_wifi";
IPAddress ip(192,168,1,69);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress dns(8,8,8,8);
AsyncWebServer server(80);
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
Display.begin();
Display.setIntensity(0);
Display.displayClear();
Display.displayScroll("CONECTANDO WIFI", PA_CENTER, PA_SCROLL_LEFT, 25);
Serial.begin(115200);
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet, dns);
Serial.print("Connecting to ");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED) {
if (Display.displayAnimate()) {
Display.displayReset();
}
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "V1.0 Prueba Panel Led");
});
AsyncElegantOTA.begin(&server);
server.begin();
Serial.println("HTTP server started");
delay(1000);
}
void loop() {
}
Muestra la IP una vez conectado
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <WiFi.h>
#include <AsyncElegantOTA.h>
// Uncomment according to your hardware type
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Defining size, and output pins
#define MAX_DEVICES 4
#define CS_PIN 5
const char* ssid = "mi_red_wifi";
const char* password = "mi_contraseña_wifi";
IPAddress ip(192,168,1,69);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);
IPAddress dns(8,8,8,8);
AsyncWebServer server(80);
MD_Parola Display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
String my_ip;
void setup() {
Display.begin();
Display.setIntensity(0);
Display.displayClear();
Display.displayScroll("CONECTANDO WIFI", PA_CENTER, PA_SCROLL_LEFT, 25);
Serial.begin(115200);
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet, dns);
Serial.print("Connecting to ");
Serial.print(ssid);
while (WiFi.status() != WL_CONNECTED) {
if (Display.displayAnimate()) {
Display.displayReset();
}
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(200, "text/plain", "V1.0 Prueba Panel Led");
});
AsyncElegantOTA.begin(&server);
server.begin();
Serial.println("HTTP server started");
delay(1000);
my_ip = WiFi.localIP().toString();
Serial.println(my_ip);
Display.displayClear();
Display.displayScroll(my_ip.c_str(), PA_CENTER, PA_SCROLL_LEFT, 25);
while(true){
if (Display.displayAnimate()) {
Display.displayReset();
break;
}
}
}
void loop() {
Display.setTextAlignment(PA_LEFT);
Display.print("Hola");
delay(10000);
}
Si cambiamos la parte del while por esto, lo muestra 2 veces
for (int muestra_ip = 1; muestra_ip <= 2; muestra_ip++) {
while (true) {
if (Display.displayAnimate()) {
Display.displayReset();
break;
}
}
}
tecnologia/iot/panel_baterias.1651177479.txt.gz · Last modified: by admin
