Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
|
projets:lcd_status:start [2025/11/21 07:00] enseignant Créé depuis le formulaire creerunprojet |
projets:lcd_status:start [2025/11/21 07:24] (Version actuelle) enseignant |
||
|---|---|---|---|
| Ligne 12: | Ligne 12: | ||
| {{projets: | {{projets: | ||
| - | ==== Références et liens ==== | + | |
| - | * Notez ici les références artistiques et techniques, ou autres influences | + | |
| - | * | + | |
| - | * | + | |
| ===== Notes techniques et matériaux ===== | ===== Notes techniques et matériaux ===== | ||
| - | Liste de matériel et composants nécessaires | + | Code pour l'esp : |
| + | |||
| + | <code c+> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // ------------------------------------------------------- | ||
| + | // WiFi credentials | ||
| + | // ------------------------------------------------------- | ||
| + | const char* ssid = " | ||
| + | const char* password = " | ||
| + | |||
| + | // ------------------------------------------------------- | ||
| + | // Grove RGB LCD I2C addresses | ||
| + | // ------------------------------------------------------- | ||
| + | #define LCD_TEXT_ADDR 0x3E | ||
| + | #define LCD_RGB_ADDR | ||
| + | |||
| + | // 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, | ||
| + | i2cWriteRegister(LCD_RGB_ADDR, | ||
| + | i2cWriteRegister(LCD_RGB_ADDR, | ||
| + | } | ||
| + | |||
| + | 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, | ||
| + | i2cWriteRegister(LCD_RGB_ADDR, | ||
| + | i2cWriteRegister(LCD_RGB_ADDR, | ||
| + | |||
| + | setRGB(255, 255, 255); | ||
| + | } | ||
| + | |||
| + | void lcdPrint(const String &msg) { | ||
| + | lcdSendCommand(0x01); | ||
| + | delay(2); | ||
| + | |||
| + | uint8_t col = 0, row = 0; | ||
| + | lcdSetCursor(0, | ||
| + | |||
| + | for (int i = 0; i < msg.length(); | ||
| + | if (msg[i] == ' | ||
| + | row = 1; | ||
| + | col = 0; | ||
| + | lcdSetCursor(col, | ||
| + | continue; | ||
| + | } | ||
| + | lcdSendData(msg[i]); | ||
| + | col++; | ||
| + | if (col >= 16) { | ||
| + | if (row == 0) { | ||
| + | row = 1; | ||
| + | col = 0; | ||
| + | lcdSetCursor(col, | ||
| + | } else { | ||
| + | break; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // ------------------------------------------------------- | ||
| + | // WiFi + HTTP | ||
| + | // ------------------------------------------------------- | ||
| + | String downloadText() { | ||
| + | HTTPClient http; | ||
| + | http.begin(" | ||
| + | |||
| + | int code = http.GET(); | ||
| + | if (code != 200) { | ||
| + | Serial.println(" | ||
| + | http.end(); | ||
| + | return "HTTP error"; | ||
| + | } | ||
| + | |||
| + | String payload = http.getString(); | ||
| + | http.end(); | ||
| + | return payload; | ||
| + | } | ||
| + | |||
| + | // ------------------------------------------------------- | ||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | delay(200); | ||
| + | |||
| + | Wire.begin(SDA_PIN, | ||
| + | lcdInit(); | ||
| + | setRGB(0, 150, 255); | ||
| + | |||
| + | lcdPrint(" | ||
| + | Serial.println(" | ||
| + | |||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(300); | ||
| + | Serial.print(" | ||
| + | } | ||
| + | Serial.println(" | ||
| + | lcdPrint(" | ||
| + | } | ||
| + | |||
| + | // ------------------------------------------------------- | ||
| + | void loop() { | ||
| + | if (WiFi.status() == WL_CONNECTED) { | ||
| + | String txt = downloadText(); | ||
| + | Serial.println(" | ||
| + | Serial.println(txt); | ||
| + | |||
| + | lcdPrint(txt); | ||
| + | } else { | ||
| + | lcdPrint(" | ||
| + | WiFi.begin(ssid, | ||
| + | } | ||
| + | |||
| + | delay(5000); | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Coté FTP-php ===== | ||
| + | <code html> | ||
| + | < | ||
| + | <html lang=" | ||
| + | < | ||
| + | <meta charset=" | ||
| + | <meta name=" | ||
| + | < | ||
| + | < | ||
| + | body { | ||
| + | background-color: | ||
| + | color: white; | ||
| + | font-family: | ||
| + | font-size: 18px; | ||
| + | margin: 0; | ||
| + | padding: 20px; | ||
| + | } | ||
| + | h1 { | ||
| + | color: lightgray; | ||
| + | } | ||
| + | |||
| + | h5 { | ||
| + | color: #666; | ||
| + | font-size: | ||
| + | } | ||
| + | form { | ||
| + | background-color: | ||
| + | padding: 20px; | ||
| + | width: 60%; | ||
| + | border-radius: | ||
| + | margin-top: 20px; | ||
| + | } | ||
| + | label { | ||
| + | display: block; | ||
| + | margin-bottom: | ||
| + | } | ||
| + | input[type=" | ||
| + | width: 80%; | ||
| + | padding: 10px; | ||
| + | font-size: 16px; | ||
| + | margin-bottom: | ||
| + | border: 1px solid gray; | ||
| + | border-radius: | ||
| + | background-color: | ||
| + | color: white; | ||
| + | } | ||
| + | input[type=" | ||
| + | background-color: | ||
| + | color: white; | ||
| + | font-size: | ||
| + | padding: 10px 15px; | ||
| + | border: none; | ||
| + | border-radius: | ||
| + | cursor: pointer; | ||
| + | } | ||
| + | input[type=" | ||
| + | background-color: | ||
| + | color: | ||
| + | } | ||
| + | </ | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <form action="" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | |||
| + | <?php | ||
| + | if ($_SERVER[" | ||
| + | $texte = htmlspecialchars($_POST[' | ||
| + | |||
| + | // Effacer le contenu du fichier et y écrire le nouveau texte | ||
| + | file_put_contents(' | ||
| + | echo "< | ||
| + | } | ||
| + | ?> | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| ===== Photos et médias===== | ===== Photos et médias===== | ||
| Code pour afficher les images du projet : | Code pour afficher les images du projet : | ||