Accéder au contenu principal
Publicités

Arduino LCD I2C simple use and direct write from serial monitor

Quick use of LCD i2c display with Arduino:

Wiring

If you have any problem with the libraries used here’s the link to download them:

Download LCD i2c library here

Download i2c Scanner here

Codes:

First code to test with:

//16*2 LCD Display Code
//SurtrTech channel

//Code for displaying a message on the screen for 2s then erase the screen for 2s

 

#include <Wire.h> //Libraries needed #include <LCD.h> #include <LiquidCrystal_I2C.h>

 

#define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here

#define BACKLIGHT_PIN 3 // Declaring LCD Pins

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

 

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); void setup() { lcd.begin (16,2); lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); //Lighting backlight lcd.home (); }

 

void loop() {

lcd.setCursor(0,0); //Setting the position where you want to start writing the message (0,0) is top left

lcd.print("SurtrTech "); //Message to display

lcd.setCursor(10,1); //Start writing on the position (10,1)

lcd.print("Hello");

delay(2000); //Display time

lcd.clear(); //Clearing the screen

delay(2000); //Blank screen time

}

Seconde code to write something on the serial monitor and see it on the screen:

//16*2 LCD Display from serial monitor

//Modified from "YourDuino.com"

//SurtrTech channel (LEBOUIHA)

//Code for displaying a message from the serial monitor

#include <Wire.h> //Libraries needed

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here

#define BACKLIGHT_PIN 3 // Declaring LCD Pins

#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {

  Serial.begin(9600); //Serial used

  lcd.begin (16,2);

  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

  lcd.setBacklight(HIGH); //Lighting backlight

  lcd.home ();

  lcd.print("Hello");

  delay(2000);

  lcd.clear();

}

void loop()

  {

    // when characters arrive over the serial port...

    if (Serial.available()) {

      // wait a bit for the entire message to arrive

      delay(100);

      // clear the screen

      lcd.clear();

      // read all the available characters

      while (Serial.available() > 0) {

        // display each character to the LCD

        lcd.write(Serial.read());

      }

    }

  }
Publicités

Yassine Tout afficher

Electronics, Automation engineering student... I try to share my little experience with other electronics amateur.

11 commentaires sur “Arduino LCD I2C simple use and direct write from serial monitor Laisser un commentaire

Répondre

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google

Vous commentez à l'aide de votre compte Google. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

%d blogueurs aiment cette page :