LiquidCrystal_I2C_Spark

An updated version of this library has been uploaded to the Spark web IDE.

The update deals with correcting timing issues of the library to accommodate Spark’s I2C communication versus Arduino’s.

There is more on it in this thread, but we have tested it and it can be accessed at GitHub

3 Likes

BulldogLowell

I have tried using this library and the example on the web IDE (clock example.ino) and I am still getting errors from the start. I am using a 20x4 LCD (would this impact the timing?) and I am wondering whether the quality of I2C board on my LCD display or the wiring from the breadboard to the I2C board could be a cause. This is really blocking me with a project. Any suggestions?

I have just tried the pull-up resistor - have used 4.7Kohm and this seems to work reliably for me. Please ignore post above.

Thanks Armor

1 Like

@armor, can you give more details on the errors you are getting? A lot has changed with the firmware since @BulldogLowell published the library and it may need some lovin’. Also, which I2C backpack are you using with the LCD?

YwRobot Arduino LCM1602 IIC VI is what is on the board on the back of the LCD board.

I started getting errors with 4.7kohms so have gone back to 10K ohms for the pull-ups and it seems better but still get errors. Errors can be eliminated if I am very careful with the rate at which I write lcd->print() and I don’t write long strings too often.

@armor, it is really unclear if pull-ups are included on the board. If they are, adding pull-ups off-board would simply drop the effective value of the total resistance. How are you powering the LCD and what voltage are you pulling up to?

It is a 5V supply VCC and I am pulling up to 3.3V. The write rate seems to be the main factor on error generation.

@armor, if there are pull-ups on the board, they will go to 5V and compete with the 3.3V pull-ups you set-up. What happens when you remove the pull-ups? If you are powering the display/backpack with 5V, then pull-up to that value as well. The D0/D1 pins are 5V tolerant.

Write rate is always an issue with displays. The library may already had delays built-in for certain operations.

Thanks - I will try these options out and see if it gives me a more reliable experience.

Since pullup resistor(s) should only be at one location (not every slave), I thought that the slaves would not provide a pullup resistor.
If you had 6 slaves on the wire, that would become a problem.
I thought you are responsible to place the pullup resisters yourself. I could be wrong.

@armor, are you using the Core, or the Photon?

@Jack, when you look around you’ll find plenty break-out-boards that do come with pull-ups and you’ll find others without (and very few with jumpers to detach/attach on-board pull-ups).

It’s true, that the user should be responsible for providing the pull-ups, but if you browse some threads, this is one of the things that gets forgotten just too often, so some board suppliers tend to build for out-the-box-only-one-slave users :wink:
Maybe they think, if one is seriously building something, they’d rather go for the chip and not a break-out-board.

1 Like

Thanks for the heads up.
Is there a way to tell, like with an ohm meter, what your slave is setup for?

It depends on the boards again.
You might be able to measure, but I usually try to figure by looking at the traces and components on the board :wink:

2 Likes

@Jack, @ScruffR is dead on. Some breakouts even have cut-away tracks for disabling the pull-ups. I usually try to find schematics for the board and go from that. If not, visual inspection is my preferred way. :smiley:

3 Likes

Sorry I am back on this Liquid Crystal I2C track - I have got the whole thing working reliably using the Clock Example - I figured I had a poor connection on the SDA and SCL wires from the bread board to the display module and changing these seems to have eradicated the issue.

However, I have tried to use createChar() function and have found that just including this creates the same problems with odd characters appearing at random on the screen. I can’t see any examples of using this command to create custom characters and write them to screen. I have looked at the library .cpp and .h and I am using the function in the right way. Could someone share a working example to set where I am going wrong? Thanks

How are you using createChar() and print the custom characters to the screen?
Just stating you do all things right does not leave any room for improvement :wink:

This is the code;

#include "LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.h"

byte a[8] =        {0X0E,
                    0X15,
                    0X15,
                    0X17,
                    0X11,
                    0X11,
                    0X0E,
                    0X00}; // clock face

byte i = 0X00;

LiquidCrystal_I2C *lcd;

int lastSecond = 0;

void setup(void)
{
  lcd = new LiquidCrystal_I2C(0x27, 20, 4);
  lcd->init();
  lcd->backlight();
  lcd->clear();
  lcd->createChar(i,a);
  lcd->print("**** Spark ");
  lcd->write(byte(0));
  lcd->print("****");
}

void loop(void)
{
  if (Time.second() != lastSecond)
  {
    lcd->setCursor(0,1);
    lcd->print(Time.hour() < 10? "   0" : "    ");
    lcd->print(Time.hour());
    lcd->print(Time.minute() < 10? ":0": ":");
    lcd->print(Time.minute());
    lcd->print(Time.second() < 10? ":0": ":");
    lcd->print(Time.second());
    lastSecond = Time.second();
  }
}

ScruffR: I have reformatted your code block - in future please use this format

code block here

I use the createChar() function with no trouble, but I am using it like this edit to your code, which I presently cannot test.:

// This #include statement was automatically added by the Spark IDE.
#include "LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.h"

uint8_t myClockFace[8] = {
    0X0E,
    0X15,
    0X15,
    0X17,
    0X11,
    0X11,
    0X0E,
    0X00};

LiquidCrystal_I2C *lcd;

int lastSecond = 0;

void setup(void)
{
  lcd = new LiquidCrystal_I2C(0x27, 20, 4);
  lcd->init();
  lcd->backlight();
  lcd->clear();
  lcd->createChar(0, myClockFace);
  lcd->print("**** Spark ");
  lcd->write(0);
  lcd->print("****");
}

void loop(void)
{
  if (Time.second() != lastSecond)
  {
    lcd->setCursor(0, 1);
    lcd->print(Time.hour() < 10 ? "   0" : "    ");
    lcd->print(Time.hour());
    lcd->print(Time.minute() < 10 ? ":0" : ":");
    lcd->print(Time.minute());
    lcd->print(Time.second() < 10 ? ":0" : ":");
    lcd->print(Time.second());
    lastSecond = Time.second();
  }
}

Thanks - it was as simple as the data type/declaration - uint8_t.

1 Like

Hi, i try to compile this library (example code) to Photon, but there is error when compiling:

[code]LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.cpp: In member function ‘void LiquidCrystal_I2C::init_priv()’:

			This looks like an error in LiquidCrystal_I2C_Spark library.
			Would you like to create an issue on GitHub to let the author know?
			
		
		LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.cpp:48:23: error: 'CLOCK_SPEED_100KHZ' was not declared in this scope
     Wire.setSpeed(CLOCK_SPEED_100KHZ);
                   ^
	



	make[1]: *** [../build/target/user/platform-6LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.o] Error 1

make: *** [user] Error 2[/code]

It’s photon specific (With Core it compiles OK). Anyone has idea how to fox it?

Hi all,

reopening this (I hope briefly!)

I have a couple of 16 x 2 displays of this type and trying to use the library (from the IDE) and the associated “clock.ino” example with a photon.
The interface board on the back of the 1602 module is labelled only “MH” and has VCC GND SDA and SCL pins.
The seller (eBay) says that VCC should be +5V

I can’t get it to display anything.

My assumptions:

D0 and D1 are to be used for SCL and SDA respectively? BTW: Would be useful to add the pin numbers in the library or example comments…I had to hunt around forums to find that out and so still not sure if they are right! Yes, in desperation I have tried reversing these in case the display pin labels are transposed.

I need pull-up resistors on the pins to match the 3.3v Photon pins to the display. I’ve run out of 4K7s so have used 5K1s - but also tried 3K9s - all to no avail.

My Activities so Far
I’ve tried powering the display from the VIN pin (+5V coming into the Photon’s USB connector from a 1A USB mains power brick) and also tried giving it its own separate +5V supply with common ground to the Photon pin 2 ground.

No matter what I do, the display does diddly. the backlight comes on with the power and looks normal brightness, but that’s it. no characters display at all. As I said, I bought two of these displays and have tried both - so less likely to be a product fault (though not impossible) and now I am out of ideas.

Plainly, I am missing something fundamental. Can anyone help?