sainsmart LCD2004 I2C error code (SOLVED)

I am using a Sainsmart LCD2004 I2C display and the hd44780 library as suggested elsewhere on this forum. The display is connected to an Arduino UNO. I am using 4.7Kohm pull ups for SDA and SCL. Using the library's diagnostic, I get a good compile and upload to Arduino. The display flashes a few times and finally says something like: "LCD 0: 0x27". That's fine because there is only one I2C device and its address is 0x27. So I figured I was communicating with the display and it was working properly. Not only that but the library figured out which address was needed and which Arduino pins it was connected to (A4 & A5).

Next step. I used hd44780 library's "Hello World". Compiled fine and uploaded. Nothing on the display and the Arduino diagnostic LED is flashing 4 times. When I looked up error code 4 in hd44780.h I find the following line: "static const int RV_ENXIO=-4; // no such device or address"

So now I am at a loss. The library has both found and not found my LCD display. I tried both specifying the address in Hello World and not specifying the address, to no avail. The only other thing I changed in the code is the geometry. My display is 20x4.

Now the question. Why can't the display be detected? In spite of the diagnostic, do I have a bad display?

A Google search didn't reveal an answer and neither have I found anything in this forum.

If you modify your thread title to include the term 'I2C' and/or 'HD44780 library' you are more likely to attract the attention of Bill, the author of that library. I'm sure he can answer your questions.

Don

I used hd44780 library’s “Hello World”. Compiled fine and uploaded.

There are “Hello World” sketches for all the different io classes of the library. Did you run the sketch from the
hd44780_I2Cexp.h class.

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config exapander chip

cattledog, Not sure now. There are 4 under "C:\Users\Pilot\Documents\Arduino\libraries\arduino_453074\examples\ioClass\"

Which one are you talking about? I think I used hdd44780_I2Clcd\HelloWorld.

Floresta. I'd be happy to modify the title. Outside of starting a new thread, I don't know how to do that.

Which one are you talking about? I think I used hdd44780_I2Clcd\HelloWorld.

You should be running the example from hd44780_I2Cexp

dmalcolm: cattledog, Not sure now. There are 4 under "C:\Users\Pilot\Documents\Arduino\libraries\arduino_453074\examples\ioClass\"

This location "C:\Users\Pilot\Documents\Arduino\libraries\arduino_453074\examples\ioClass\" seems to indicate that the library was not installed properly. It looks like you have done some kind of manual library installation which does not properly install the library. The easiest (and, IMO, best way to install) is to use the IDE library manager as it it easier, faster, and will properly install the library. There are even instructions for how to use the IDE library manger on the main github repository page it if you are unfamiliar.


hd44780 is a library package that supports multiple i/o classes to support different h/w interfaces that are used to communicate with a hd44780 LCD. Each i/o class has its own examples in a separate subdirectory that is named according to its i/o class name. While all the examples for all the i/o classes are always available regardless of what h/w you actually have, if you select an example that is not for the h/w you have, it will compile but obviously it will not work.

It sounds like you have run an example that uses an i/o class that is not for the h/w you have.

Given the odd looking installation and the issues running examples, I recommend that you spend a little time reading the information on the github repository web page and the readme files on the github repository down under the examples directory. You can view them in your browser by simply clicking on the directories on the repository. They provide some information about the examples and the i/o classes.

Also, if you are unsure about an example, you can read the comments of each example. Each example has a note that explains what hardware it works on right at the top of the sketch just below the copyright information.

NOTE: If you manage to get the hd44780 library and examples you have already installed up and working, I'd still HIGHLY recommend that you correct the hd44780 library library installation. Using the IDE library manager is the way to go as it is super easy and will allow you to do updates to the library in the future. The easiest fix is to simply remove the one you have installed and re-install it using the IDE library manager. If you don't correct the installation and use the library manager later or do another manual install to yet another directory location, there can be issues, some of which can be hard to track down as it can create compilation or linker errors as the IDE can potentially grab pieces of the library from multiple different "hd44780" libraries that have been installed.

--- bill

cattledog: You should be running the example from hd44780_I2Cexp

It's always good to ask the right guy. That worked perfectly. One remaining question. How should I have known this one would work? Should I have just tried them all. More likely I missed something in the documentation. Thanks.

bperrybab, Thanks for your reply. Cattledog pointed me to the right one. Silly me I was looking for something that said "this will work for a Sainsmart LCD2004". That probably doesn't exist. If I look at the chip model nomenclature on the chip itself, there it is PCF8574T. The very chip noted in the preamble for the "Hello World" that worked.

BTW I followed your instructions when I installed the library. I also spend time reading the included text, but probably not enough time.

Thanks.

dmalcolm: BTW I followed your instructions when I installed the library.

I don't understand what you mean by this. The hd44780 library should end up in a directory called hd44780 From your previous description it appears to have ended up in a directory called arduino_453074

There are 4 under "C:\Users\Pilot\Documents\Arduino\libraries\arduino_453074\examples\ioClass\"

The IDE does allow a library be placed in a directory by any name; however, when it isn't the same name as the master library header file, there can be issues if multiple copies of the library get installed using different directory names.

If this is still the case, I would fix it to avoid any issues related to this library in the future, particularly if you re-install or update the hd44780 library using the IDE library manager.

--- bill

Floresta. I'd be happy to modify the title. Outside of starting a new thread, I don't know how to do that.

If I remember correctly you do that by editing your original post. Try it now and also add "[SOLVED]" at the beginning of the title.

Don