Arduino

I2C LCD scherm 2×16 karakters

Monday, November 25, 2013
I2C LCD scherm 2×16 karaktersLike0

In tegenstelling tot de fader was het 2×16 karakter LCD scherm een stuk moeilijker aan de praat te krijgen. Uiteindelijk is het wel gelukt – en ik heb er een filmpje van gemaakt:

De volgende informatie zal je een hoop tijd schelen.

Het gebruikte LCD scherm:

https://www.iprototype.nl/products/components/led-lcd/lcd16x2-I2C-BL

Het topic waarin belangrijke problemen worden aangekaart en opgelost:

http://forum.arduino.cc/index.php/topic,128635.0.html

Met deze sketch kun je zien welke poort je LCD scherm gebruikt:

http://playground.arduino.cc/Main/I2cScanner

Vergeet niet de benodigde libraries te installeren. Gebruik hiervoor niet de libraries op de site van iPrototype maar de deze:

https://bitbucket.orghttps://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

Een update over de Mega 2560 vind je hier.

En uiteindelijk de sketch zoals te zien in het filmpje.


/*
** Example Arduino sketch for SainSmart I2C LCD2004 adapter for HD44780 LCD screens
** Readily found on eBay or http://www.sainsmart.com/
** The LCD2004 module appears to be identical to one marketed by YwRobot
**
** Address pins 0,1 & 2 are all permenantly tied high so the address is fixed at 0x27
**
** Written for and tested with Arduino 1.0
** This example uses F Malpartida's NewLiquidCrystal library. Obtain from:
** https://bitbucket.org/fmalpartida/new-liquidcrystal
**
** Edward Comer
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
**
** NOTE: TEsted on Arduino NANO whose I2C pins are A4==SDA, A5==SCL
*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x20  // Define I2C Address where the PCF8574A is
#define BACKLIGHT_PIN     3
#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

int n = 1;

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);

// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();                   // go home

lcd.setCursor ( 0, 0 );        // go to the 1st line
lcd.print("Lucas van Tol");
lcd.setCursor ( 0, 1 );        // go to the 2nd line
lcd.print("Arduino n00b");

}

void loop()
{
// Backlight on/off every 3 seconds
//lcd.setCursor (14,1);        // go col 14 of line 3
//  lcd.print(n++,DEC);
//  lcd.setBacklight(LOW);      // Backlight off
lcd.setCursor ( 0, 0 );        // go to the 1st line
lcd.print("info@           ");
lcd.setCursor ( 0, 1 );        // go to the 2nd line
lcd.print("lucasvantol.nl");
delay(3000);
lcd.setBacklight(HIGH);     // Backlight on
lcd.setCursor ( 0, 0 );        // go to the 1st line
lcd.print("Lucas van Tol");
lcd.setCursor ( 0, 1 );        // go to the 2nd line
lcd.print("Arduino n00b  ");
delay(3000);
}

0

Leave a Reply

Your email address will not be published.

Follow @ Guerrilla Games
Instagram has returned invalid data.