I am a noob to Arduino and find it very interesting and am hoping to get into more.One of my first endevers was gonig to be using a lcd to display text however I am stuck and not sure what I am doing wrong.
I have checked oit the othwr forums relating o thos topic with out sucess.
Iam using an ARDUINIO MEGA 2560 and a SainSmart IIC/I2C/TWI Serial 2004 20x4 LCD Module.
The lcd has an I2C chip number PCF8574T.
I am using Ardrino 1.0.3 to upload.
I have the lcd powered and grounded and attached to the SDA and SCL ports on the Mega accordingly.
I have tried several liquidcrystal librarys along with different code without success.
Using LiquidCrystal_I2C an the hello world code I was able to get the lcd to turn the display on and off essentially blink however no characters were displayed.
I have been using the I2C location of 0x3F in the code
Using the library LiquidCrystal_V1.2.1 I was unable to get the lcd to respond in any way with any code I tried. What am I missing.
Thank you in advance for any help
Josh
Many of us have been there. To get a display working for the first time can be troublesome. No matter how it is connected or with what interface.
Can you give a few links to what you are using, like the libraries.
The sainsmart display, http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html
Can you be more precise how it is connected ? Do you use the SDA and SCL near the AREF pin ?
As fas as I can tell, only four connections are needed (5V, GND, SDA, SCL).
Use the sketch of sainsmart to start with.
But first you have to know if it the I2C communication is any good. Use the i2c scanner to see if the device is recognized, Arduino Playground - I2cScanner
You can try this adapting to your lcd, intead of "lcd.begin(16, 2);" you will have "lcd.begin(20, 4);" and then if you have sucess you can change the program. With this you can learn how to program a lcd.
This is a working test sketch that I use with my SainSmart I2C LCD The only variable may be that your I2C address may be 0X27 instead of 0X3F. The I2C scanner here Arduino Playground - I2cScanner will tell you the correct address.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F // 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
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
lcd.begin (20,4);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.print("If you can read this");
lcd.setCursor ( 0, 1 ); // go to the 2nd line
lcd.print("Your LCD is working!");
lcd.setCursor ( 0, 2 ); // go to the third line
lcd.print("Congratulations!");
lcd.setCursor ( 0, 3 ); // go to the fourth line
lcd.print("Enjoy your I2C LCD");
}
void loop()
{
// Backlight on/off every 3 seconds
lcd.setCursor (14,3); // go col 14 of line 3
lcd.setBacklight(LOW); // Backlight off
delay(3000);
lcd.setBacklight(HIGH); // Backlight on
delay(3000);
}
Thank you everyone for the suggestions so far.
As an update, I have the lcd connected to the arduino mega as follows.
GND to negative of power supply
VCC to 4.5V power supply
SDA to SDA pin 20 on mega
SCL to SCL pin 21 on mega
I just tried tunning the I2C scanner an got the folloing message
Scanning...
Unknow error at address 0x3F
No I2C devices found
(side note for anyone new using the i2c scanner, after running the code you need to open the serial monitor under the tools tab to view results )
I currently have liquidcrystal_I2C installed in the library folder
its structure is as follows
Examples (folder)
Info (folder)
Keywords.txt
liquidCrystal_I2C.cpp
liquidCrystal_I2C.h
Using the following code and above library the lcd blinked.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,20,4);
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
}
void loop()
{
}
I tried uninstalling the above library and replacing it with the download link on the bottom of the page at http://www.sainsmart.com/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html
and tried the sample codes in the sketch folder as well as the one provided by kd7eir in his post without success.
Thank you for the code by the way im sure it would work great if i was able to connect to my lcd.
Any ideas why i am getting the I2c error message??
It should work without errors.
Continue with the i2c scanner, until that is okay without error.
Perhaps you can add pull-up resistors for the I2C signals ?
Two resistors of 4k7 to the 5V if the I2C bus is for 5V, or to the 3.3V if the signals of the bus are for 3.3V.
Why a 4.5V power supply ? The Arduino Mega is the most critical Arduino board for a good 5V.
Or is the Mega powered with something else ?
Did you connect the ground of the Mega to the ground of the display ?
Thank you a million, that worked.
It had nothing to do with the library or code I was using as they were correct rather the way i had it attached was apparently incorrect.
I had the Ground and power being supplied from a power supply however the display only works now when recieveing ground from the arduino.
Not exactly certain why that is, id be interested to know though...
Thanks for the code provided as it is functional now on the unit.
I appreciate everyones help and hope to be on my way with learning im sure ill be back soon.
We are glad to help.
The SDA and SCL signals need a ground, else they would be floating signals without any reference.
The I2C bus is actually a three-wire bus: SDA, SCL and GND.