tecnologia:iot:panel_baterias
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tecnologia:iot:panel_baterias [2022/04/28 17:05] – admin | tecnologia:iot:panel_baterias [2022/04/30 13:55] (current) – jose | ||
|---|---|---|---|
| Line 19: | Line 19: | ||
| Yo he instalado MD_Parola que te deja hacer efectos. Te dirá que tiene dependencias y le decimos que instale todas. | Yo he instalado MD_Parola que te deja hacer efectos. Te dirá que tiene dependencias y le decimos que instale todas. | ||
| - | Código de proba: | + | ====== Mensaje sencillo ====== |
| < | < | ||
| #include < | #include < | ||
| Line 101: | Line 102: | ||
| + | ====== 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:// | ||
| + | // | ||
| + | // 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:// | ||
| + | // | ||
| + | #include < | ||
| + | #include < | ||
| + | // 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 | ||
| + | //#define DATA_PIN | ||
| + | #define CS_PIN | ||
| + | #define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | |||
| + | // HARDWARE SPI | ||
| + | MD_Parola P = MD_Parola(HARDWARE_TYPE, | ||
| + | // SOFTWARE SPI | ||
| + | //MD_Parola P = MD_Parola(DATA_PIN, | ||
| + | |||
| + | |||
| + | |||
| + | 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 | ||
| + | # | ||
| + | char curMessage[BUF_SIZE] = { "" | ||
| + | char newMessage[BUF_SIZE] = { " | ||
| + | bool newMessageAvailable = true; | ||
| + | |||
| + | |||
| + | |||
| + | void readSerial(void) | ||
| + | { | ||
| + | static char *cp = newMessage; | ||
| + | |||
| + | while (Serial.available()) | ||
| + | { | ||
| + | *cp = (char)Serial.read(); | ||
| + | if ((*cp == ' | ||
| + | { | ||
| + | *cp = ' | ||
| + | // 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(" | ||
| + | |||
| + | |||
| + | P.begin(); | ||
| + | P.displayText(curMessage, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | |||
| + | |||
| + | if (P.displayAnimate()) | ||
| + | { | ||
| + | if (newMessageAvailable) | ||
| + | { | ||
| + | strcpy(curMessage, | ||
| + | newMessageAvailable = false; | ||
| + | } | ||
| + | P.displayReset(); | ||
| + | } | ||
| + | readSerial(); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Mensaje de **conectando a wifi** mientras conecta ===== | ||
| + | |||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | // Uncomment according to your hardware type | ||
| + | #define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | //#define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | |||
| + | // Defining size, and output pins | ||
| + | #define MAX_DEVICES 4 | ||
| + | #define CS_PIN 5 | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | IPAddress ip(192, | ||
| + | IPAddress gateway(192, | ||
| + | IPAddress subnet(255, | ||
| + | IPAddress dns(8, | ||
| + | |||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | MD_Parola Display = MD_Parola(HARDWARE_TYPE, | ||
| + | |||
| + | |||
| + | void setup() { | ||
| + | Display.begin(); | ||
| + | Display.setIntensity(0); | ||
| + | Display.displayClear(); | ||
| + | Display.displayScroll(" | ||
| + | |||
| + | Serial.begin(115200); | ||
| + | delay(10); | ||
| + | Serial.println(' | ||
| + | | ||
| + | WiFi.begin(ssid, | ||
| + | WiFi.config(ip, | ||
| + | Serial.print(" | ||
| + | Serial.print(ssid); | ||
| + | |||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | if (Display.displayAnimate()) { | ||
| + | Display.displayReset(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Serial.println(' | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | |||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | | ||
| + | | ||
| + | AsyncElegantOTA.begin(& | ||
| + | server.begin(); | ||
| + | Serial.println(" | ||
| + | delay(1000); | ||
| + | |||
| + | |||
| + | | ||
| + | |||
| + | } | ||
| + | |||
| + | |||
| + | void loop() { | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Muestra la IP una vez conectado ===== | ||
| + | |||
| + | |||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | // Uncomment according to your hardware type | ||
| + | #define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | //#define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | |||
| + | // Defining size, and output pins | ||
| + | #define MAX_DEVICES 4 | ||
| + | #define CS_PIN 5 | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | IPAddress ip(192, | ||
| + | IPAddress gateway(192, | ||
| + | IPAddress subnet(255, | ||
| + | IPAddress dns(8, | ||
| + | |||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | MD_Parola Display = MD_Parola(HARDWARE_TYPE, | ||
| + | String my_ip; | ||
| + | |||
| + | void setup() { | ||
| + | Display.begin(); | ||
| + | Display.setIntensity(0); | ||
| + | Display.displayClear(); | ||
| + | Display.displayScroll(" | ||
| + | |||
| + | Serial.begin(115200); | ||
| + | delay(10); | ||
| + | Serial.println(' | ||
| + | | ||
| + | WiFi.begin(ssid, | ||
| + | WiFi.config(ip, | ||
| + | Serial.print(" | ||
| + | Serial.print(ssid); | ||
| + | |||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | if (Display.displayAnimate()) { | ||
| + | Display.displayReset(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Serial.println(' | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | |||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | | ||
| + | | ||
| + | AsyncElegantOTA.begin(& | ||
| + | server.begin(); | ||
| + | Serial.println(" | ||
| + | delay(1000); | ||
| + | |||
| + | my_ip = WiFi.localIP().toString(); | ||
| + | Serial.println(my_ip); | ||
| + | |||
| + | Display.displayClear(); | ||
| + | Display.displayScroll(my_ip.c_str(), | ||
| + | | ||
| + | while(true){ | ||
| + | if (Display.displayAnimate()) { | ||
| + | Display.displayReset(); | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | void loop() { | ||
| + | |||
| + | Display.setTextAlignment(PA_LEFT); | ||
| + | Display.print(" | ||
| + | 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; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Muestra mensaje leido de internet ===== | ||
| + | Lee el texto que le indicamos en la web que tengamos en: | ||
| + | serverPath = " | ||
| + | |||
| + | Al leer la cadena le pone un símbolo raro al final solo en la pantalla led, en el serial monitor no. | ||
| + | |||
| + | Le quitamos el último carácter con: | ||
| + | payload.substring(0, | ||
| + | |||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | // Uncomment according to your hardware type | ||
| + | #define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | //#define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | |||
| + | // Defining size, and output pins | ||
| + | #define MAX_DEVICES 4 | ||
| + | #define CS_PIN 5 | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | IPAddress ip(192, | ||
| + | IPAddress gateway(192, | ||
| + | IPAddress subnet(255, | ||
| + | IPAddress dns(8, | ||
| + | |||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | const int lectura=5; | ||
| + | String power=""; | ||
| + | |||
| + | String serverPath = " | ||
| + | |||
| + | MD_Parola Display = MD_Parola(HARDWARE_TYPE, | ||
| + | |||
| + | void setup() { | ||
| + | |||
| + | Display.begin(); | ||
| + | Display.setIntensity(0); | ||
| + | Display.displayClear(); | ||
| + | Serial.begin(115200); | ||
| + | delay(10); | ||
| + | Serial.println(' | ||
| + | | ||
| + | WiFi.begin(ssid, | ||
| + | WiFi.config(ip, | ||
| + | Serial.print(" | ||
| + | Serial.print(ssid); | ||
| + | |||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(500); | ||
| + | Serial.print(' | ||
| + | } | ||
| + | |||
| + | Serial.println(' | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | | ||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | | ||
| + | | ||
| + | AsyncElegantOTA.begin(& | ||
| + | server.begin(); | ||
| + | Serial.println(" | ||
| + | Display.print(" | ||
| + | delay(1000); | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | AsyncElegantOTA.loop(); | ||
| + | |||
| + | Display.setTextAlignment(PA_LEFT); | ||
| + | |||
| + | |||
| + | if(WiFi.status()== WL_CONNECTED){ | ||
| + | HTTPClient http; | ||
| + | | ||
| + | // Your Domain name with URL path or IP address with path | ||
| + | http.begin(serverPath.c_str()); | ||
| + | | ||
| + | // Send HTTP GET request | ||
| + | int httpResponseCode = http.GET(); | ||
| + | | ||
| + | if (httpResponseCode> | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | String payload = http.getString(); | ||
| + | Serial.println(String(payload.toInt())); | ||
| + | | ||
| + | Serial.println(strlen(payload.c_str())); | ||
| + | |||
| + | Display.setTextAlignment(PA_CENTER); | ||
| + | Display.print(payload.substring(0, | ||
| + | delay(1000); | ||
| + | } | ||
| + | else { | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | } | ||
| + | // Free resources | ||
| + | http.end(); | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Muestra mensaje leido de internet con scroll ===== | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | |||
| + | // Uncomment according to your hardware type | ||
| + | #define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | //#define HARDWARE_TYPE MD_MAX72XX:: | ||
| + | |||
| + | // Defining size, and output pins | ||
| + | #define MAX_DEVICES 4 | ||
| + | #define CS_PIN 5 | ||
| + | |||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | IPAddress ip(192, | ||
| + | IPAddress gateway(192, | ||
| + | IPAddress subnet(255, | ||
| + | IPAddress dns(8, | ||
| + | |||
| + | AsyncWebServer server(80); | ||
| + | |||
| + | String mensaje=""; | ||
| + | |||
| + | String serverPath = " | ||
| + | |||
| + | |||
| + | MD_Parola Display = MD_Parola(HARDWARE_TYPE, | ||
| + | |||
| + | void setup() { | ||
| + | |||
| + | Display.begin(); | ||
| + | Display.setIntensity(0); | ||
| + | Display.displayClear(); | ||
| + | String mensaje = " | ||
| + | Display.displayScroll(mensaje.c_str(), | ||
| + | | ||
| + | Serial.begin(115200); | ||
| + | delay(10); | ||
| + | Serial.println(' | ||
| + | | ||
| + | WiFi.begin(ssid, | ||
| + | WiFi.config(ip, | ||
| + | Serial.print(" | ||
| + | Serial.print(ssid); | ||
| + | |||
| + | while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect | ||
| + | if (Display.displayAnimate()) { | ||
| + | Display.displayReset(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Serial.println(' | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(WiFi.localIP()); | ||
| + | |||
| + | server.on("/", | ||
| + | request-> | ||
| + | }); | ||
| + | | ||
| + | | ||
| + | AsyncElegantOTA.begin(& | ||
| + | server.begin(); | ||
| + | Serial.println(" | ||
| + | Display.print(" | ||
| + | delay(1000); | ||
| + | |||
| + | // | ||
| + | Display.setTextAlignment(PA_CENTER); | ||
| + | Display.displayScroll(" | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | AsyncElegantOTA.loop(); | ||
| + | | ||
| + | if(WiFi.status()== WL_CONNECTED){ | ||
| + | |||
| + | HTTPClient http; | ||
| + | | ||
| + | // Your Domain name with URL path or IP address with path | ||
| + | http.begin(serverPath.c_str()); | ||
| + | | ||
| + | | ||
| + | // Send HTTP GET request | ||
| + | int httpResponseCode = http.GET(); | ||
| + | | ||
| + | if (httpResponseCode> | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | String payload = http.getString(); | ||
| + | |||
| + | Serial.println(payload); | ||
| + | const char* mensaje=payload.c_str(); | ||
| + | Serial.println(mensaje); | ||
| + | Display.displayClear(); | ||
| + | Display.displayScroll(mensaje, | ||
| + | | ||
| + | while(!Display.displayAnimate()) | ||
| + | { | ||
| + | Serial.println(" | ||
| + | } | ||
| + | } | ||
| + | else { | ||
| + | Serial.print(" | ||
| + | Serial.println(httpResponseCode); | ||
| + | } | ||
| + | // Free resources | ||
| + | http.end(); | ||
| + | } | ||
| + | else { | ||
| + | Serial.println(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
tecnologia/iot/panel_baterias.1651165530.txt.gz · Last modified: by admin
