====== LCD status ====== * Porteur du projet : Ap * Fichiers utiles : //mettre un lien vers un code ou un fichier// {{tag>esp, arduino, ftp, php}} ===== Note d'intention ===== Il s'agit simplement d'un afficheur LCD branché sur un esp. Un formulaire en php, logé sur un ftp. permet de mettre a jour le texte affiché. Ainsi avec son telephone sur internet on peut mettre a jour l'ecran à distance. {{projets:lcd_status:start:comfyui_00131_.png?800|LCD status}} ===== Notes techniques et matériaux ===== Code pour l'esp : #include #include #include // ------------------------------------------------------- // WiFi credentials // ------------------------------------------------------- const char* ssid = "ESDAMM-Pedagogie"; const char* password = "P3daGog!e"; // ------------------------------------------------------- // Grove RGB LCD I2C addresses // ------------------------------------------------------- #define LCD_TEXT_ADDR 0x3E #define LCD_RGB_ADDR 0x62 // ESP32 I2C pins #define SDA_PIN 21 #define SCL_PIN 22 // ------------------------------------------------------- // LCD low-level functions // ------------------------------------------------------- void lcdSendCommand(uint8_t cmd) { Wire.beginTransmission(LCD_TEXT_ADDR); Wire.write(0x80); Wire.write(cmd); Wire.endTransmission(); } void lcdSendData(uint8_t data) { Wire.beginTransmission(LCD_TEXT_ADDR); Wire.write(0x40); Wire.write(data); Wire.endTransmission(); } void i2cWriteRegister(uint8_t addr, uint8_t reg, uint8_t val) { Wire.beginTransmission(addr); Wire.write(reg); Wire.write(val); Wire.endTransmission(); } void setRGB(uint8_t r, uint8_t g, uint8_t b) { i2cWriteRegister(LCD_RGB_ADDR, 0x04, r); i2cWriteRegister(LCD_RGB_ADDR, 0x03, g); i2cWriteRegister(LCD_RGB_ADDR, 0x02, b); } void lcdSetCursor(uint8_t col, uint8_t row) { uint8_t pos = (row == 0) ? 0x00 : 0x40; lcdSendCommand(0x80 | (pos + col)); } void lcdInit() { lcdSendCommand(0x38); lcdSendCommand(0x39); lcdSendCommand(0x14); lcdSendCommand(0x70); lcdSendCommand(0x56); lcdSendCommand(0x6C); delay(200); lcdSendCommand(0x38); lcdSendCommand(0x0C); lcdSendCommand(0x01); lcdSendCommand(0x06); // Init RGB i2cWriteRegister(LCD_RGB_ADDR, 0x00, 0x00); i2cWriteRegister(LCD_RGB_ADDR, 0x01, 0x00); i2cWriteRegister(LCD_RGB_ADDR, 0x08, 0xAA); setRGB(255, 255, 255); } void lcdPrint(const String &msg) { lcdSendCommand(0x01); // clear delay(2); uint8_t col = 0, row = 0; lcdSetCursor(0, 0); for (int i = 0; i < msg.length(); i++) { if (msg[i] == '\n') { row = 1; col = 0; lcdSetCursor(col, row); continue; } lcdSendData(msg[i]); col++; if (col >= 16) { if (row == 0) { row = 1; col = 0; lcdSetCursor(col, row); } else { break; } } } } // ------------------------------------------------------- // WiFi + HTTP // ------------------------------------------------------- String downloadText() { HTTPClient http; http.begin("https://wikibam.com/XP/fichier.txt"); int code = http.GET(); if (code != 200) { Serial.println("Erreur HTTP : " + String(code)); http.end(); return "HTTP error"; } String payload = http.getString(); http.end(); return payload; } // ------------------------------------------------------- void setup() { Serial.begin(115200); delay(200); Wire.begin(SDA_PIN, SCL_PIN); lcdInit(); setRGB(0, 150, 255); lcdPrint("Connexion\nWiFi..."); Serial.println("Connexion WiFi..."); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(300); Serial.print("."); } Serial.println("\nWiFi OK !"); lcdPrint("WiFi OK!\nLecture..."); } // ------------------------------------------------------- void loop() { if (WiFi.status() == WL_CONNECTED) { String txt = downloadText(); Serial.println("Mis à jour:"); Serial.println(txt); lcdPrint(txt); } else { lcdPrint("WiFi perdu!\nReconnexion"); WiFi.begin(ssid, password); } delay(5000); // <<< mise à jour toutes les 5 secondes } ===== Coté FTP-php ===== Formulaire de mise à jour

♻ Status

:) Le fichier a été mis à jour avec succès."; } ?>
===== Photos et médias===== Code pour afficher les images du projet : {{gallery>?&crop&lightbox }}