I'm trying to let my hd44780 Display with i2c print 'Hello World' but it doesn't work. I'm searching since a few days for a solution and other posts didn't helped me.
The address of my display is 0x27 which I found out by executing the following code:
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000);
}
Next I try running a simple programm to print 'Hello World'. The display just shows black boxes in the first row instead of the text. To check if I have the right adress and to see if it does something I put the backlight change in the loop too. The display changes it backlight but not the text.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
void setup()
{
// activate LCD module
lcd.begin (16,2); // for 16 x 2 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop()
{
lcd.home (); // set cursor to 0,0
lcd.print("Hello World");
delay(1000);
lcd.setBacklight(LOW); // Backlight off
delay(250);
lcd.setBacklight(HIGH); // Backlight on
delay(1000);
}
I also tried multiple librarys and adjusted the potentiometer on the i2c adapter. I connected GNC to ground, vcc to 5V, SDA to A4 and SCL to A5
Thanks for every help.
The problem could be in that line of code. That defines the pin mapping between the I2C expander chip pins and the LCD pins. They are not all the same. You could figure out the pin mapping by following the PCB traces or by running a I2C guesser program. The simplest way, in my opinion, is to use the hd44780 library. That library will automatically determine the pin mapping and I2C address and is compatible with the LiquidCrystal library command syntax. Use the hd44780_I2Cexp class. The library is available to install from the library manager in the IDE.
There are several examples and a trouble shooting sketch if you have problems. Also the author of the library is often here to answer questions.
In my opinion, the hd44780 library is the best one available at this time.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LED_PIN 3
LiquidCrystal_I2C lcd(0x27, 16, 2); //when you define the lcd object of the LiquidCrystal_i2c library, write only this
void setup()
{
lcd.init();
lcd.backlight();
analogWrite(LED_PIN, 100); //as PIN 3 is a PWM its value goes from 0 to 255, the lower the value, the less the display will be illuminated
}
void loop()
{
lcd.setCursor(3,0);// column 3 row 0
lcd.print("Hello, world!");
delay(1000);
analogWrite(LED_PIN, 0); // Backlight off
delay(250);
analogWrite(LED_PIN, 100); // Backlight on
delay(1000);
}
mircolicausi, that may work if the actual pin mapping is the library default. If it isn't, then you sill have to figure it out and put the right mapping in the constructor. The hs44780 library does that for you.
groundFungus:
The simplest way, in my opinion, is to use the hd44780 library. That library will automatically determine the pin mapping and I2C address and is compatible with the LiquidCrystal library command syntax. Use the hd44780_I2Cexp class. The library is available to install from the library manager in the IDE.
There are several examples and a trouble shooting sketch if you have problems. Also the author of the library is often here to answer questions.
In my opinion, the hd44780 library is the best one available at this time.
I tried this library and run the HelloWorld example but the Display still shows the boxes.
mircolicausi:
Hi,
Try this
#include <Wire.h>
#include <LiquidCrystal_I2C.h> #define LED_PIN 3
LiquidCrystal_I2C lcd(0x27, 16, 2); //when you define the lcd object of the LiquidCrystal_i2c library, write only this
void setup()
{
lcd.init();
lcd.backlight();
analogWrite(LED_PIN, 100); //as PIN 3 is a PWM its value goes from 0 to 255, the lower the value, the less the display will be illuminated
}
You are still relying on the pin mapping of the expander to LCD wiring to be the library default. If the default wiring is not the same as the wiring of your LCD it will never work.
Can you post the code that you ran to test the hd44780 library? I have used that library with several different LCDs with no problems.
Can you load and run the I2CexpDiag sketch and copy and paste the output here? This is the path to the right sketch. Note that this is also the path to the proper examples to test the LCD and learn about the API of the library.
groundFungus:
Can you post the code that you ran to test the hd44780 library? I have used that library with several different LCDs with no problems.
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
void setup()
{
int status;
status = lcd.begin(LCD_COLS, LCD_ROWS);
if(status) // non zero status means it was unsuccesful
{
status = -status; // convert negative status value to positive number
// begin() failed so blink error code using the onboard LED if possible
hd44780::fatalError(status); // does not return
}
lcd.print("Hello, World!");
}
void loop() {}
Thats the HelloWorld example I used to test.
groundFungus:
Can you load and run the I2CexpDiag sketch and copy and paste the output here?
********************************************************************
Serial Initialized
--------------------------------------------------------------------
I2CexpDiag - i2c LCD i/o expander backpack diagnostic tool
--------------------------------------------------------------------
hd44780 lib version: 1.0.1
--------------------------------------------------------------------
Reported Arduino Revision: 1.8.6
CPU ARCH: AVR - F_CPU: 16000000
--------------------------------------------------------------------
SDA digital pin: 18 A4
SCL digital pin: 19 A5
--------------------------------------------------------------------
Checking for required external I2C pull-up on SDA - YES
Checking for required external I2C pull-up on SCL - YES
Checking for I2C pins shorted together - Not Shorted
--------------------------------------------------------------------
Scanning i2c bus for devices..
i2c device found at address 0x27
Total I2C devices found: 1
--------------------------------------------------------------------
Scanning i2c bus for all lcd displays
LCD at address: 0x27 | config: P01245673H | R/W control: Yes
Total LCD devices found: 1
--------------------------------------------------------------------
LCD Display Memory Test
Display: 0
Walking 1s data test:
Compare error: addr: 0 read 22 != wrote 1
Compare error: addr: 0 read 22 != wrote 2
Compare error: addr: 0 read 22 != wrote 4
Compare error: addr: 0 read 22 != wrote 8
Compare error: addr: 0 read 22 != wrote 10
Compare error: addr: 0 read 22 != wrote 20
Compare error: addr: 0 read 22 != wrote 40
Compare error: addr: 0 read 22 != wrote 80
Compare error: addr: 40 read 22 != wrote 1
Compare error: addr: 40 read 22 != wrote 2
Compare error: addr: 40 read 22 != wrote 4
Compare error: addr: 40 read 22 != wrote 8
Compare error: addr: 40 read 22 != wrote 10
Compare error: addr: 40 read 22 != wrote 20
Compare error: addr: 40 read 22 != wrote 40
Compare error: addr: 40 read 22 != wrote 80
Compare error: addr: 10 read 22 != wrote 1
Compare error: addr: 10 read 22 != wrote 2
Compare error: addr: 10 read 22 != wrote 4
Compare error: addr: 10 read 22 != wrote 8
Compare error: addr: 10 read 22 != wrote 10
Compare error: addr: 10 read 22 != wrote 20
Compare error: addr: 10 read 22 != wrote 40
Compare error: addr: 10 read 22 != wrote 80
Compare error: addr: 50 read 22 != wrote 1
Compare error: addr: 50 read 22 != wrote 2
Compare error: addr: 50 read 22 != wrote 4
Compare error: addr: 50 read 22 != wrote 8
Compare error: addr: 50 read 22 != wrote 10
Compare error: addr: 50 read 22 != wrote 20
Compare error: addr: 50 read 22 != wrote 40
Compare error: addr: 50 read 22 != wrote 80
FAILED
Address line test:
Compare error: addr: 0 read 22 != wrote 0
Compare error: addr: 1 read 22 != wrote 1
Compare error: addr: 2 read 22 != wrote 2
Compare error: addr: 3 read 22 != wrote 3
Compare error: addr: 4 read 22 != wrote 4
Compare error: addr: 5 read 22 != wrote 5
Compare error: addr: 6 read 22 != wrote 6
Compare error: addr: 7 read 22 != wrote 7
Compare error: addr: 8 read 22 != wrote 8
Compare error: addr: 9 read 22 != wrote 9
Compare error: addr: B read 22 != wrote B
Compare error: addr: C read 22 != wrote C
Compare error: addr: E read 22 != wrote E
Compare error: addr: F read 22 != wrote F
Compare error: addr: 10 read 22 != wrote 10
Compare error: addr: 11 read 22 != wrote 11
Compare error: addr: 12 read 22 != wrote 12
Compare error: addr: 13 read 22 != wrote 13
Compare error: addr: 14 read 22 != wrote 14
Compare error: addr: 15 read 22 != wrote 15
Compare error: addr: 16 read 22 != wrote 16
Compare error: addr: 17 read 22 != wrote 17
Compare error: addr: 18 read 22 != wrote 18
Compare error: addr: 19 read 22 != wrote 19
Compare error: addr: 1A read 22 != wrote 1A
Compare error: addr: 1B read 22 != wrote 1B
Compare error: addr: 1C read 22 != wrote 1C
Compare error: addr: 1D read 22 != wrote 1D
Compare error: addr: 1E read 22 != wrote 1E
Compare error: addr: 1F read 22 != wrote 1F
Compare error: addr: 20 read 22 != wrote 20
Compare error: addr: 21 read 22 != wrote 21
Compare error: addr: 23 read 22 != wrote 23
Compare error: addr: 24 read 22 != wrote 24
Compare error: addr: 25 read 22 != wrote 25
Compare error: addr: 26 read 22 != wrote 26
Compare error: addr: 27 read 22 != wrote 27
Compare error: addr: 40 read 22 != wrote 40
Compare error: addr: 41 read 22 != wrote 41
Compare error: addr: 42 read 22 != wrote 42
Compare error: addr: 43 read 22 != wrote 43
Compare error: addr: 44 read 22 != wrote 44
Compare error: addr: 45 read 22 != wrote 45
Compare error: addr: 46 read 22 != wrote 46
Compare error: addr: 47 read 22 != wrote 47
Compare error: addr: 48 read 22 != wrote 48
Compare error: addr: 49 read 22 != wrote 49
Compare error: addr: 4A read 22 != wrote 4A
Compare error: addr: 4B read 22 != wrote 4B
Compare error: addr: 4C read 22 != wrote 4C
Compare error: addr: 4D read 22 != wrote 4D
Compare error: addr: 4E read 22 != wrote 4E
Compare error: addr: 4F read 22 != wrote 4F
Compare error: addr: 50 read 22 != wrote 50
Compare error: addr: 51 read 22 != wrote 51
Compare error: addr: 52 read 22 != wrote 52
Compare error: addr: 53 read 22 != wrote 53
Compare error: addr: 54 read 22 != wrote 54
Compare error: addr: 55 read 22 != wrote 55
Compare error: addr: 56 read 22 != wrote 56
Compare error: addr: 57 read 22 != wrote 57
Compare error: addr: 58 read 22 != wrote 58
Compare error: addr: 59 read 22 != wrote 59
Compare error: addr: 5A read 22 != wrote 5A
Compare error: addr: 5B read 22 != wrote 5B
Compare error: addr: 5C read 22 != wrote 5C
Compare error: addr: 5D read 22 != wrote 5D
Compare error: addr: 5E read 22 != wrote 5E
Compare error: addr: 5F read 22 != wrote 5F
Compare error: addr: 60 read 22 != wrote 60
Compare error: addr: 61 read 22 != wrote 61
Compare error: addr: 62 read 22 != wrote 62
Compare error: addr: 63 read 22 != wrote 63
Compare error: addr: 64 read 22 != wrote 64
Compare error: addr: 65 read 22 != wrote 65
Compare error: addr: 66 read 22 != wrote 66
Compare error: addr: 67 read 22 != wrote 67
FAILED
Memory test failures are usually due to poor solder connections
Most common cause is poor solder joints on pins soldered to the LCD
--------------------------------------------------------------------
No working LCD devices
Memory test failures are usually due to poor solder connections
Most common cause is poor solder joints on pins soldered to the LCD
I can do no more than suggest that you examine the solder joints on the expander to LCD connection and the solder joint on the expander chip on the PC board. We have seen some problems in those areas of late.
Note that no matter what was written it always read back 0x22
that could mean that the control lines between the LCD and the PCF chip have issues and so the PCF chip is not able to control the LCD to be able to do writes or reads and the data read and reported is what happens to be on the PCF data pins.
This could be the solder connections of the LCD to the backpack or it could be solder connections of the actual PCF chip to the backpack PCB.
Can you post some clear close up photos of the solder connections of the backpacks pins and the LCD.
And then of the backpack itself.
I'd like to take a look at the solder connections of the PCF chip to the PCB. I've seen a few where some of the pins on the chip
were soldered to the PCB.