/*
** 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 6
#define Rw_pin 5
#define Rs_pin 4
#define D4_pin 11
#define D5_pin 12
#define D6_pin 13
#define D7_pin 14
// old code, also tried.
//#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.print("SainSmart I2C tester");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("F Malpartida library");
}
void loop()
{
// Backlight on/off every 3 seconds
lcd.setCursor (14,3); // go col 14 of line 3
lcd.print(n++,DEC);
lcd.setBacklight(LOW); // Backlight off
delay(3000);
lcd.setBacklight(HIGH); // Backlight on
delay(3000);
}
if i try the liquidtwi librarie and example code. the lcd is showing stuff, but not the characters. for my idea the only thing that works then is the backlight, and sending thing.
// include the library code:
#include <Wire.h>
#include <LiquidTWI2.h>
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI2 lcd(0);
void setup() {
// set the LCD type
lcd.setMCPType(LTI_TYPE_MCP23008);
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setBacklight(true);
}
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);
lcd.print("hello, world!");
}
the result is:
backlight is on
you can see a sort of sinus wave instead of characters
I have also been working on getting my 16X2 I2C LCD to work.
I am happy to say, after several hours, I have it working.
My solutions:
I am using a Leonardo board, and didn't realize that A4 and A5 don't work on that board (there are dedicated pins near AREF).
bperrybap, explained to me that;
There are many different i2c to hd44780 lcd libraries out there.
They do not work the same.
They use different constructors, have different capabilities, and have different
ways of initializing using different initialization functions and parameters.
Most of them them use hard coded output pin mappings.
And that makes things even more complex since I2C boards
don't all use the same pin mappings.
My recommendation is to use fm's library: https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
It replaces the LiquidCrystal library that ships with the IDE.
Some sites repost this library but this is the location for the original source.
This library works very well and offers the same capabilities across several interfaces,
including 4 bit parallel, 2 wire shift register, 3 wire shift register, and I2C using a PCF8574.
It is also faster than the others.
i noticed that already.
on the at mega 2560 i am using digital ports 20(SDA) and 21(SCL)
also already used that library. but still don;t get the right setup. so it is still not working
#include <Wire.h>
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
#define I2C_ADDR 0x20
#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
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin,BACKLIGHT_PIN,POSITIVE);
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600); // Used to type in characters
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
// ------- Quick 3 blinks of backlight -------------
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on
//-------- Write characters on the display ------------------
// NOTE: Cursor Position: (CHAR, LINE) start at 0
lcd.setCursor(0,0); //Start at character 4 on line 0
lcd.print("Hello, world!");
delay(1000);
lcd.setCursor(0,1);
lcd.print("HI!YourDuino.com");
delay(8000);
// Wait and then tell user they can start the Serial Monitor and type in characters to
// Display. (Set Serial Monitor option to "No Line Ending")
lcd.clear();
lcd.setCursor(0,0); //Start at character 0 on line 0
lcd.print("Use Serial Mon");
lcd.setCursor(0,1);
lcd.print("Type to display");
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
{
// 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());
}
}
}
}/* --(end main loop )-- */
/* ( THE END ) */
Are you getting backlight?
I noticed if I left off the back light and polarity, I did not get any back light, but if I used a flashlight, I could see it was changing characters. But, you said you do have backlight I think?
Some suggest, a pullup resistor on the two lines (data & clock). I had a 4k on both for a while, but when I got it working, I pulled the resistors, and saw no change. Your board may be different.
based on the fact that the LIQUIDTWI librarie is allmost working. i guess that if i change the code in the header file below it should work. but i don;t get the right settings
I found 2 reviews, that gave me some info to get started.
If you think it is the pin definations, look at http://arduino-info.wikispaces.com/LCD-Blue-I2C.
They have about 3 common pin configurations listed there, maybe one?
To be clear, the sketch compiles and uploads with no errors? The backlight is lit? You have your IDE set to the board you are using?
It is strange for that new code to do anything, since you don't even specify the I2C address. ? ?
an yeah all the code is compinling and uploading without any errors.
if i use your librarie, the backlight isn;t on.
my ide is set to the bord i;m using
Back stepping. If your scan got the address, then the clock and data pins must be hooked correctly.
At
they suggest several common pin settings for 3 different versions:
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // Set the LCD I2C address
LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
I can see there could be a lot of variations, but they seem to think these are some of the most common.
Try these three, and maybe?
This was really frustrating for me yesterday. I had to turn the computer off, and start again this morning.Often if we sleep on it, it gets more understandable in the morning.
// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI2 lcd(0);
0 is the default address witch is in the .h file of the librarie set to 0x20. as i set before.
but i tried to make it 0x20 an now i got the same situation.
the blacklight is on. but the text isn;t correct.
and he is putting everyting on the first line.
nothing on the seccond
Sounds to me like the pins arrangement on the physical device is not the same as what the library expects, so it sets the correct bits on the wrong pins.
i thought maybe of the this registers is wrong. but there not written in the normal way as in: "en, rw, rs, d1, d2, ...."" i don;t know witch i should change to get it right.
but this library is written for the: Adafruit I2C Backpack
and mine is a meeeno IIC LCD v1.0 i searched all over the internet but i heared nobody about this i2c module. only where to buy it from, not how to make it work.
These are the registers of the MCP chip, not the pins going to the LCD.
You need to get the datasheet for this chip (here)
Then check with a multimeter which GPIO pin on the MCP goes to which pin on the LCD.
Then you change this code to suit the implementation of your I2C PCB:
Have you tried putting pullup resistors on those two lines? I did, and then took mine off, but your board may require then. ?
Next suggestion: If you can't get this display to sync, tell DX.com you want them to send you another board that will work (the one I got). As of yet, there have been no reviews posted for that board. It is likely, no one has been able to get it to work. DX has been pretty reasonable with me about doa items.