(solved) LiquidCrystal_I2C library+TinyWireM+ATTiny85.LCD don't work

Hello guys,

I have beeen searching for a long time but didn’t find any solution to my problem.
So I’m writing here with the hope to find some help, or at least new ways to investigate.

I have a LCD wich I think is a I2C LCD DISPLAY VERSION 3. I has for sure an i2c adapter.
I can use it along with F Malpartida LiquidCrystal library (the only one which works well for me) and a Duemilanove Arduino using i2c.
I would like to use it with an ATTiny85.
To do that I have modified the I2CIO.cpp file of the library to add some #ifdef AVR_ATtiny85 to use TinyWireM in spite of Wire, and to change “read” to “receive” and “write” to “send”.
Sketch compiles well, executes well for sentences relates to leds, but does nothing on the LCD. Even the LCD blink sequence does nothing.
Here’s the small test sketche :

#include “LiquidCrystal_I2C.h”
#include <TinyWireM.h>

#define LED1_PIN 4 // ATtiny Pin 3
#define LED2_PIN 1 // ATtiny Pin 6

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

void setup()
{
pinMode(LED1_PIN,OUTPUT);
pinMode(LED2_PIN,OUTPUT);
Blink(LED1_PIN,5);
lcd.begin(16,2); // initialize the lcd
// ------- Quick 3 blinks of backlight -------------
for(int i = 0; i< 3; i++)
{
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(250);
}
lcd.backlight(); // finish with backlight on

Blink(LED2_PIN,2);
lcd.setCursor(3,0);
//lcd.home (); // go home
Blink(LED2_PIN,3);
lcd.print(“Salut Noury”);
Blink(LED2_PIN,4);
}

void loop()
{
}

void Blink(byte led, byte times){ // poor man’s GUI
for (byte i=0; i< times; i++){
digitalWrite(led,HIGH);
delay (400);
digitalWrite(led,LOW);
delay (175);
}
delay(1000);
}

Led1 and led2 blink as expected, but not the LCD. And of course there’s no display.

All works well with a “real” Arduino and changing the bord to Duemilanove in the ide
I must add that I’m using pull-ups resistors on the CLK and SDA pins.

Really hope to find some help here.

Regards

nb

I see

#define LED1_PIN 4 // ATtiny Pin 3
#define LED2_PIN 1 // ATtiny Pin 6

Which appears to use pin 6, and then

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

Which appears to use pin 6 again?

I see … Which appears to use pin 6, and then … Which appears to use pin 6 again?

I’m not positive about this but I believe that the pin numbers in the LiquidCrystal constructor (your second quote) refer to the pins on the I2C adapter, not on the Arduino. If I am correct then there is no conflict with pin 6.

Don

Gotcha.

So, rather than hacking I2CIO.cpp, why not use the "Modified LiquidCrystal_I2C for the ATtiny" from Arduino Playground - USIi2c by BroHogan?

floresta:

I see ... Which appears to use pin 6, and then ... Which appears to use pin 6 again?

I'm not positive about this but I believe that the pin numbers in the LiquidCrystal constructor (your second quote) refer to the pins on the I2C adapter, not on the Arduino. If I am correct then there is no conflict with pin 6.

Don

Correct. The "pins" in the constructor, are output pins on the PCF8574. i.e. p0, p1, .... p7.
But in reality they are actually bit positions on the i/o expander output port.

--- bill

tylernt:
Gotcha.

So, rather than hacking I2CIO.cpp, why not use the “Modified LiquidCrystal_I2C for the ATtiny” from http://playground.arduino.cc/Code/USIi2c by BroHogan?

Thanks for this idea.

For a reason I can’t explain, this lib never worked for me. Even with the Duemilanove.
I’ve tried it once again now with no success :frowning:

The modifications I’ve made are exactly the same that BroHogan did on the LiquidCrystal_I2C.cpp

First step, use a I2C scanner to verify your address, and to verify that the wire is working. If there is a problem here, then fix it first. I used the one by Nick Gammon.

Do you have a url for that LCD I2C board? They are not all created equal (actually many are not).

Do you know if the I2C chip is PCF8574 , or maybe MCP23008 ?

I see ... Which appears to use pin 6, and then ... Which appears to use pin 6 again?

I agree with Don.
The I2C chip, is a port expander. It provides more ports (I believe 8 more), and are addressed separate from the arduino pins.

You could check this. There are different models with different conections:

http://arduino-info.wikispaces.com/LCD-Blue-I2C

jackwp:
First step, use a I2C scanner to verify your address, and to verify that the wire is working. If there is a problem here, then fix it first. I used the one by Nick Gammon.

The address is 0x27.
It works that way with a Duemilanove board.
I’ve added the “SoftwareSerial” lib, and a piece of the scanner. It shows :
Scanning…
I2C device found at address 0x27 !
That means the address is correct and the i2c bus works fine!

jackwp:
Do you have a url for that LCD I2C board? They are not all created equal (actually many are not).

I have bought it in China via ebay. Here’s the url, but we don’t have much informations :
http://www.ebay.com/itm/IIC-I2C-TWI-SP-I-Serial-Interface1602-16X2-Character-LCD-Module-Display-Blue-/310565065847?

jackwp:
Do you know if the I2C chip is PCF8574 , or maybe MCP23008 ?

I don’t know…
I have attached a photo to this post.
Is there a way to know that by the mean of some commands?

Thanks for your interest.

Erni:
You could check this. There are different models with different conections:

http://arduino-info.wikispaces.com/LCD-Blue-I2C

Hello,

I had done that, and chosen "version 3" wich is the closest one.
In fact all is ok with an Arduino.
The only difference I have are :

  • I use an ATTiny85 in spite of an ATMega328
  • I have modified the I2CIO.cpp to use TinyWireM library whereas it used the Wire one.

All ATTiny pins seem to work well, i2c bus too. Even TX and RX serial works fine with SoftwareSerial lib.

It is a real headache...

You are right, the URL didn't help much (sometime they do).

Do you know if the I2C chip is PCF8574 , or maybe MCP23008 ?

I used a magnifying glass and looked at the main chip on the backpack board, and found PCF8574 written on it.

In fact all is ok with an Arduino.

. I now see you said that before, and I missed it!

When you compile/upload using the IDE, do you have the correct board set?

Have you seen this article "I2C (master and slave) on the ATtiny85", Arduino Playground - USIi2c

jackwp:

In fact all is ok with an Arduino.

. Maybe you said that before, and I missed it!

When you compile/upload using the IDE, do you have the correct board set?

Have you seen this article "I2C (master and slave) on the ATtiny85", Arduino Playground - USIi2c

Of course I read that article. It's the first one that appears in Google search with certain keywords.
I use that TinyWireM lib.
I use the core files from High Low Tech, those from google arduino-tiny didn't work for me.

I must say I didn't understand everything about the frequencies...

In the ide I can see 3 ATTiny85 boards (1MHz internal, 8MHz internal and 20MHZ external). I use 8MHz.
If I use 1MHz, everything goes very fast, and LCD doesn't work. SotwareSerial refuses 1MHz.

it is said :
By default the I2C master library (TinyWireM) is set to run at 1MHz. To run at 8MHz, #defines in USI_TWI_Master.h / .cpp must be changed
I don't understand well what to do. I have changed nothing.

It looks like you may be on the right track with the 1MHz and 8MHz thing. Sorry I don't know what needs changed. Maybe someone else on here has a suggestion for that. Good luck.

@ nbenm
I have a 20x4 LCD with that module, it has a PCF8574.
Try this library: Arduino Playground - HomePage
You'll need TinyWireM installed to run it on an ATtiny85.

TheCoolest:
@ nbenm
I have a 20x4 LCD with that module, it has a PCF8574.
Try this library: http://playground.arduino.cc/uploads/Code/LiquidCrystal_I2C_85V1.zip
You’ll need TinyWireM installed to run it on an ATtiny85.

Thank you TheCoolest, it’s the one I use, the only one that works for me on a Duemilanove.

nbenm:

TheCoolest:
@ nbenm
I have a 20x4 LCD with that module, it has a PCF8574.
Try this library: http://playground.arduino.cc/uploads/Code/LiquidCrystal_I2C_85V1.zip
You’ll need TinyWireM installed to run it on an ATtiny85.

Thank you TheCoolest, it’s the one I use, the only one that works for me on a Duemilanove.

The problem is now partally solved.
I have tried some libraries before posting here. Since then, I have found that some of them have very small differences.
This library http://playground.arduino.cc/uploads/Code/LiquidCrystal_I2C_85V1.zip doesn’t work in my case, but this one DigisparkArduinoIntegration/libraries/DigisparkLCD at master · digistump/DigisparkArduinoIntegration · GitHub works.
LiquidCrystal_I2C.cpp and “.h” files are slightly different.
Furthermore, the code that works is the following :

#include “LiquidCrystal_I2C.h”
#include <TinyWireM.h> // original lib include

LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
lcd.init(); // this is necessary
lcd.backlight();
lcd.print(“Hello World!”);
}
void loop(){}

Malpartida’s lib, seem to be much better. It has many advanced and interesting possibilities.
The problem is that it works with a Duemilanove and not an ATTiny, even with I2CIO.cpp modified to use TinyWireM.
That’s why I tag this post as “partially solved”.
I’m not satisfied with this, and I’m going to try to understand what’s happening.
For that I need to debug or trace the lib, but I don’t know how to do that. I’ve used the SoftwareSerial lib with the ATTiny, but don’t know if it’s possible to use it from inside lib classes.
If someone could point me to some method…

Regards

nbenm

I have been trying the same thing (using the tiny85 wich I2C library), on and off for a while.
Funny thing is that I just reached the same solution as you: It works with the Digispark library.

If you want an easy way to get debugging information I would recommed Coding Badly's TinyISP and TinyDebugKnockbang.

http://forum.arduino.cc/index.php/topic,123388.15.html

http://www.ernstc.dk/arduino/tinycom.html

@nbenm
The main difference between the two libraries is that the order of the bits is different. Seems like one thing I forgot to mention was that you have to know which GPIO pins go to what pins on the LCD. Seems like the guys at digispark had the same module and the pinout was the same so it works.

@ Erni
Same goes for other libraries, you may want to take a look at how data is arranged before it is transmitted to the port expander, open the CPP file and look. Maybe you can modify it to work with your module as well.