projets:lcd_status:start

Ceci est une ancienne révision du document !


LCD status

  • Porteur du projet : Ap
  • Fichiers utiles : mettre un lien vers un code ou un fichier

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.

LCD status

  • Notez ici les références artistiques et techniques, ou autres influences

Liste de matériel et composants nécessaires (documents avec photo si possible…)

#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
 
// -------------------------------------------------------
// 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
}

Code pour afficher les images du projet :

  • projets/lcd_status/start.1763704918.txt.gz
  • Dernière modification: 2025/11/21 07:01
  • de enseignant