#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3A,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
int ledPin = 13; // LED connected to digital pin 13
int ditLength = 150;
int dahLength = 350;
int charPause = 400;
void setup()
{
//pinMode(ledPin, OUTPUT); // sets the digital pin as output
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("hello everyone");
lcd.setCursor(1,1);
lcd.print("konichiwaa");
}
void loop()
{
//digitalWrite(ledPin, HIGH); // sets the LED on
//delay(2000); // waits for a second
//digitalWrite(ledPin, LOW); // sets the LED off
//delay(200); // waits for a second
shortFlash();
shortFlash();
shortFlash();
longFlash();
pause();
}
void pause()
{
digitalWrite(ledPin, LOW); // sets the LED off
delay(charPause); // wait in ms
}
void shortFlash()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(ditLength); // waits for 500ms
digitalWrite(ledPin, LOW); // sets the LED off
delay(150); // wait after
}
void longFlash()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(dahLength); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(100); // wait after
}
If the I2C backpack is one of the usual PCF8574 I2C expanders it can have on of two addresses, 0x27 or 03f. It would be very unusual if the address was any other unless someone purposely changed it by bridging some of the solder pads.
Post clear photos that show the wiring and soldering of the backpack to LCD, please.
For an I2C LCD display to work, the I2C address and the I2C backpack to LCD pin mapping must be correct. If the library default settings for either or both are not correct the LCD will not work. You can try to figure out the right pin mapping and use an I2C scanner to find the address, but if you install and use the hd44780 library that is done automatically by the library.
To install the hd44780 library. The hd44780 library is the best available for I2C LCDs. The library is available in the Library Manager. Go to Library Manager (in the IDE menus, Sketch, Include Libraries, Manage Libraries) and in the Topics dropdown choose Display and in the Filter your search box enter hd44780. Select and install the hd44780 library by Bill Perry.
The class that you want to use is the hd44780_I2Cexp class. There are examples to show how to use the library. The nice thing about the hd44780 library is that it will autodetect the I2C address and the I2C backpack to LCD pin mapping.
In the examples, there is a diagnostic sketch that will help us to help you if you still have trouble with the display. Run the diagnostic sketch and post the results.
I'd trust the scanner more than the doc (especially because they say "I2C address defaults to 58 (0x3A) but can be set to any valid I2C address in the range 1 - 127").
Said that, if the LCD works fine while nothing happens when connected to I2C adapter, I suspect either a bad library (there are dozens of LiquidCrystal_I2C libraries,, with the exact same name, what is yours?), or a bad connection (you soldered it? Are you sure every pin has been properly soldered?) or a bad adapter (in this case, you'd ask for a replacement).
EDIT: please describe the connections you made, that backpack doesn't seem to me a standard/common one...
So, that is not the ubiquitous PCF8574 I2C enabled LCD. The standard LiquidCrystal_I2C library or hd44780 library with hd44780_I2Cexp class may not work with that display.
I would suggest that you take a look at this page from the maker:
In the documents section, of the page above, is a download with a library and Arduino example code for that display.
@bperrybap may be able to tell you if there is a class of the hd44780 library that works with that display.
The photo in post #5 shows a board that seems to be missing the pullup resistors on SCL and SDA; I'm not 100% sure if they are needed, the Arduino might enable the internal ones when using I2C.
The internal pullups (30K-50K) on an Uno or a Nano are too weak be reliable pullups on the I2C bus so external pullups are necessary if not on any of the devices on the bus. 4.67K is the standard suggested value. The Mega has 10K pullups on SDA and SCL so those should be OK for short wires. For other boards, check their data sheets or documentation.
There is no i/o class in the hd44780 library to support that device.
While it would not be difficult to write one, it does not exist today.
While the product itself seems ok,
IMO, the Arduino library they provided for using the product with I2C is a bit retarded.
It is foolish, imo, to have to specify the i2c address in every single API call, particularly given it is not changing for a given lcd object.
It could have and should have been passed in with the constructor.
Having to pass in the address on each API call makes the API incompatible with the LiquidCrystal API, which is what nearly all libraries for hd44780 based LCDs are providing.
I would not recommend this product. (unless there is a better library)
There are other products for either i2c or serial that, imo, are easier to use, which, imo, makes them better.
For i2c mode, i see no advantage of this backpack to one of the simpler PCF8574 based ones.
The PCF8574 based backpacks are cheaper, and there are several options for full featured LiquidCrystal API compatible libraries.
It is base on a PIC. Not on a PCF8574. So a library made for a PCF8574 will not work. In order to use this backpack you have to use THEIR library. THEIR code because of the "homemade" PIC. According to their datasheet, the address of the device is 58.
Oh ... one more thing .... check to make sure the voltage at Vcc and GND of the display have more than 4.5 V. Below that voltage, the display and code will not work.
As sterretje mention, you may need to solder two 4.7 K resistors as pull up for the SCL and SDA.
What I would do ... I will take their code and libraries, place the address 58, if that is not working, I will replace address 58 with 0x6F. and re-check. According to the datasheet, the PIC have to be re-program in order to change the device address.
PS ... 8.40 pound ... that is about $16.80 Can ... That is not a cheap LCD backpack.
It is a standard; but at a low level. It does not specify the language (read: commands and/or data) that needs to be used in the communication, only how to transfer the words (read: bytes).
I can see that the commands in the libraries differ but I had assumed that any i2c library would control any i2c card and that it didn't need a specific one for each make/model of card.
They already told you why with THIS backpack you can't drive your display:
So if it doesn't work we can't help you more than the original manufacturer do. Either check that library and examples, or move to a "standard" I2C LCD adapter.
If i2c differs from manufacturer to manufacturer then it's not a standard at software level. This should be made a lot clearer.
Looking at pull-up resistors suggests it needs a 4.7k Ohm or higher between 5V and A4 and the same on A5. Surprisingly none of the 20 odd examples I've like at have such resistors.
Thanks for the help. I've been struggling with this for a long time and I've got a bit frustrated with it. All the example projects make it sound so easy, plug and play.
@sterretje already explained that I2C is a standard, but as a general purpose communication level.
See that like OSI stack for serial communications: I2C defines just the lower levels, where an application compatibility depends on lower layers implementation.
Hope it helps.
#include <Wire.h>
#include <HTI2CLCD.h>
HTI2CLCD lcd; // Create an instance of the HTI2CLCD
int LcdAddr = 0x6F;
int ledPin = 13; // LED connected to digital pin 13
int ditLength = 150;
int dahLength = 350;
int charPause = 400;
void setup()
{
delay(800);
Wire.begin();
//pinMode(ledPin, OUTPUT); // sets the digital pin as output
lcd.setType(LcdAddr,2,16); // Define rows and columns for LCD
lcd.clear(LcdAddr);
lcd.backLight(LcdAddr,60);
lcd.write(LcdAddr,0);
lcd.print(LcdAddr,"Line 1 hello "); // Print a message to the LCD.
lcd.write(LcdAddr,1);
lcd.print(LcdAddr,"Line 2 working ?");
}
void loop()
{
//digitalWrite(ledPin, HIGH); // sets the LED on
//delay(2000); // waits for a second
//digitalWrite(ledPin, LOW); // sets the LED off
//delay(200); // waits for a second
shortFlash();
shortFlash();
shortFlash();
longFlash();
pause(charPause);
}
void pause(int pLen)
{
digitalWrite(ledPin, LOW); // sets the LED off
delay(pLen); // wait in ms
}
void shortFlash()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(ditLength); // waits for 500ms
pause(100); // wait after
}
void longFlash()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(dahLength); // waits for a second
pause(100); // wait after
}