Difference between revisions of "Grove 16x2 LCD Series"

From
Jump to: navigation, search
(Code Affichage "Hello" LiquidCrystal_I2C_ESP32)
Line 256: Line 256:
 
void loop() {
 
void loop() {
 
   // Rien ici pour l'instant
 
   // Rien ici pour l'instant
 +
}
 +
</pre>
 +
 +
<br>
 +
----
 +
 +
=== Code "Compteur dynamique avec curseur" avec Wire ===
 +
 +
<pre>
 +
#include <Wire.h>
 +
 +
#define LCD_ADDR 0x3E
 +
#define COMMAND 0x00
 +
#define DATA    0x40
 +
 +
void sendCommand(uint8_t cmd) {
 +
  Wire.beginTransmission(LCD_ADDR);
 +
  Wire.write(COMMAND);
 +
  Wire.write(cmd);
 +
  Wire.endTransmission();
 +
  delay(2);
 +
}
 +
 +
void sendData(uint8_t data) {
 +
  Wire.beginTransmission(LCD_ADDR);
 +
  Wire.write(DATA);
 +
  Wire.write(data);
 +
  Wire.endTransmission();
 +
  delay(2);
 +
}
 +
 +
void setCursor(uint8_t col, uint8_t row) {
 +
  uint8_t pos = (row == 0) ? 0x80 + col : 0xC0 + col;
 +
  sendCommand(pos);
 +
}
 +
 +
void clearLCD() {
 +
  sendCommand(0x01); // Clear display
 +
  delay(2);
 +
}
 +
 +
void initLCD() {
 +
  delay(50);
 +
  sendCommand(0x38);
 +
  sendCommand(0x39);
 +
  sendCommand(0x14);
 +
  sendCommand(0x70); // contraste
 +
  sendCommand(0x56);
 +
  sendCommand(0x6C);
 +
  delay(200);
 +
  sendCommand(0x38);
 +
  sendCommand(0x0C); // affichage ON
 +
  clearLCD();
 +
}
 +
 +
void printText(const char* text) {
 +
  while (*text) {
 +
    sendData(*text++);
 +
  }
 +
}
 +
 +
void setup() {
 +
  Wire.begin();
 +
  initLCD();
 +
  setCursor(0, 0);
 +
  printText("Compteur:");
 +
}
 +
 +
void loop() {
 +
  static int count = 0;
 +
  setCursor(0, 1); // ligne 2
 +
  char buffer[16];
 +
  snprintf(buffer, sizeof(buffer), "Valeur: %4d", count++);
 +
  printText(buffer);
 +
  delay(1000);
 
}
 
}
 
</pre>
 
</pre>

Revision as of 21:51, 21 October 2025

Grove - 16x2 LCD Series

16 Characters * 2 Lines
Operating Voltage : 3.3V / 5V

images

ici on utilise le (White on Blue) V1.0

16x2 LCD White on Blue 01.jpg 16x2 LCD White on Blue 02.jpg

liens externes

http://wiki.seeedstudio.com/Grove-16x2_LCD_Series LCD wiki Grove-16x2

https://www.seeedstudio.com/Grove-16x2-LCD-White-on-Blue.html Shop Grove-16x2_LCD

Connectique

interface : I2C-bus
I2C Adresse: 0X3E

https://wiki.myows.top/index.php?title=I2cScanner I2cScanner

on va chercher l'adresse I2C, on regarde sur l'écran série

Scanning... I2C device found at address 0x3E  ! done
c'est la même indiqué par le constructeur.

16x2 LCD White on Blue Connect 01.jpg

Librairie Seed-Studio

install an Arduino library

https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight Librairie

https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight/archive/master.zip Librairie fichier Zip

Add Library Zip.png

HelloWorld Grove LCD.ino

Code 2

Affichage du texte "hello, world!" et dans la deuxième ligne affichage d'un compteur depuis zéro, +1 chaque seconde, 0,1,2, 3, ...51...

https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight Librairie

Seeeduino-nano-connect.png Pinout Grove Shield Arduino Nano.JPG 16x2 LCD White on Blue 01.jpg

Seeeduino-nano / (port i2c) ✅
16x2 LCD White on Blue

Grove Base for XIAO 1.PNG XIAO-ESP32S3 1.PNG 16x2 LCD White on Blue 01.jpg

Grove Base for XIAO (Port i2c) ✅
XIAO-ESP32S3
16x2 LCD White on Blue

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

/*
const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
*/

void setup() 
{
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    
    //lcd.setRGB(colorR, colorG, colorB);
    
    // Print a message to the LCD.
    lcd.print("hello, world!");

    delay(1000);
}

void loop() 
{
    // set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 1);
    // print the number of seconds since reset:
    lcd.print(millis()/1000);

    delay(100);
}

un léger changement

https://github.come/Seed-Studio/Grove_LCD_RGB_Backlight Librairie

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

void setup() {
  lcd.begin(16, 2); // 16 colonnes, 2 lignes
  lcd.setRGB(0, 128, 64); // Couleur de fond (vert doux)
  lcd.setCursor(0, 0);
  lcd.print("Hello ESP32S3!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
  delay(1000);
}



Code 3

ceci ne fonctionne pas ! ⊗ 🍎 avec :
Seeeduino-nano +
Port I2c +
16x2 LCD White on Blue

https://github.com/johnrickman/LiquidCrystal_I2C Librairy

https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c


#include <LiquidCrystal_I2C.h>

// I2C address of the LCD (check your specific LCD if it's different)
#define LCD_I2C_ADDRESS 0x01

// Define the LCD as an object
LiquidCrystal_I2C lcd(LCD_I2C_ADDRESS, 16, 2); // 16 columns, 2 rows

void setup() {
  // Initialize the LCD
  lcd.init();
  // Turn on the backlight
  // lcd.backlight();
  // Optional: Set custom characters if needed
  // lcd.createChar(0, custom_char_data);
  // You can use the custom_char_data array from a tool like LCD-Character-Creator (https://maxpromer.github.io/LCD-Character-Creator/)
}
void loop() {
  // Clear the LCD (optional)
  lcd.clear();
  // Set the cursor to the desired position (column, row)
  // 0,0 is the top-left corner
  lcd.setCursor(0, 0); 
  // Print text to the LCD
  lcd.print("Hello, World!");
  // Optionally, delay for a period
  delay(2000);
}



Code Affichage "Hello" avec LiquidCrystal_I2C_ESP32

https://github.com/iakop/LiquidCrystal_I2C_ESP32 Librairy

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3E, 16, 2); // Adresse I2C 0x3E pour Grove LCD

void setup() {
  Wire.begin(); // Initialise I2C
  lcd.init();   // Initialise l'écran
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Hello ESP32!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
  delay(1000);
}



Code Affichage "Hello" avec Wire

#include <Wire.h>

#define LCD_ADDR 0x3E  // Adresse I2C du Grove LCD
#define COMMAND 0x00   // Mode commande
#define DATA    0x40   // Mode données

void sendCommand(uint8_t cmd) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(COMMAND);
  Wire.write(cmd);
  Wire.endTransmission();
  delay(2);
}

void sendData(uint8_t data) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(DATA);
  Wire.write(data);
  Wire.endTransmission();
  delay(2);
}

void initLCD() {
  delay(50); // Attente après alimentation
  sendCommand(0x38); // Fonction : 2 lignes, 8 bits
  sendCommand(0x39); // Fonction étendue
  sendCommand(0x14); // Oscillateur
  sendCommand(0x70); // Contraste (ajuster si nécessaire)
  sendCommand(0x56); // Puissance + icône + contraste
  sendCommand(0x6C); // Activation du booster
  delay(200);
  sendCommand(0x38); // Retour mode normal
  sendCommand(0x0C); // Affichage ON, curseur OFF
  sendCommand(0x01); // Clear
  delay(2);
}

void printText(const char* text) {
  while (*text) {
    sendData(*text++);
  }
}

void setup() {
  Wire.begin();
  delay(100);
  initLCD();
  printText("Hello RA4M1!");
}

void loop() {
  // Rien ici pour l'instant
}



Code "Compteur dynamique avec curseur" avec Wire

#include <Wire.h>

#define LCD_ADDR 0x3E
#define COMMAND 0x00
#define DATA    0x40

void sendCommand(uint8_t cmd) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(COMMAND);
  Wire.write(cmd);
  Wire.endTransmission();
  delay(2);
}

void sendData(uint8_t data) {
  Wire.beginTransmission(LCD_ADDR);
  Wire.write(DATA);
  Wire.write(data);
  Wire.endTransmission();
  delay(2);
}

void setCursor(uint8_t col, uint8_t row) {
  uint8_t pos = (row == 0) ? 0x80 + col : 0xC0 + col;
  sendCommand(pos);
}

void clearLCD() {
  sendCommand(0x01); // Clear display
  delay(2);
}

void initLCD() {
  delay(50);
  sendCommand(0x38);
  sendCommand(0x39);
  sendCommand(0x14);
  sendCommand(0x70); // contraste
  sendCommand(0x56);
  sendCommand(0x6C);
  delay(200);
  sendCommand(0x38);
  sendCommand(0x0C); // affichage ON
  clearLCD();
}

void printText(const char* text) {
  while (*text) {
    sendData(*text++);
  }
}

void setup() {
  Wire.begin();
  initLCD();
  setCursor(0, 0);
  printText("Compteur:");
}

void loop() {
  static int count = 0;
  setCursor(0, 1); // ligne 2
  char buffer[16];
  snprintf(buffer, sizeof(buffer), "Valeur: %4d", count++);
  printText(buffer);
  delay(1000);
}