Pages: 1 [2]   Go Down
Author Topic: (solved) LiquidCrystal_I2C library+TinyWireM+ATTiny85.LCD don't work  (Read 4977 times)
0 Members and 1 Guest are viewing this topic.
Israel
Offline Offline
Sr. Member
****
Karma: 5
Posts: 291
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@ 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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ 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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@ 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 https://github.com/digistump/DigisparkArduinoIntegration/tree/master/libraries/DigisparkLCD 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
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 37
Posts: 1095
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: August 24, 2013, 11:45:12 am by Erni » Logged

Israel
Offline Offline
Sr. Member
****
Karma: 5
Posts: 291
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I think I've found what was happening with the Malpartida library.
The problem seem to be in the use of TinyWireM library.

In the I2CIO class begin function, there's the following call:
_initialised = Wire.requestFrom ( _i2cAddr, (uint8_t)1 );
It is said in I2CIO.h about the begin function:
"@result     1 if the device was initialized correctly, 0 otherwise"
In the case of an Attiny85 this calls the USI_TWI class requestFrom function located in TinyWireM.cpp file.

The reason I still use the word "Wire" is that I had added in I2CIO.cpp:
#if defined(__AVR_ATtiny85__) || (__AVR_ATtiny2313__)
#include "TinyWireM.h"      // include this if ATtiny85 or ATtiny2313
#define Wire TinyWireM
#else
#include <Wire.h>           // original lib include
#endif

In the requestFrom function we can read:
  xferOK = USI_TWI_Start_Read_Write(USI_Buf,numBytes); // core func that does the work
  // USI_Buf now holds the data read
  if (xferOK) return 0;
  else {                                  // there was an error
    errorCode = USI_TWI_Get_State_Info(); // this function returns the error number
    return errorCode;

This means that in case of success, we return 0
This value is then used as a return value in the begin function.

To solve my problem I have changed "if (xferOK) return 0;" to "if (xferOK) return 1;"
The requestFrom function is not used in the Digispark library, that's why it worked.

I'm not sure of the solution, but I'm quiet happy to have found the reason.
It's hard for a beginner to choose between all thes libs having same name.

BTW, to use 8MHz with ATtiny85 we must change:
#define SYS_CLK   1000.0 to #define SYS_CLK   8000.0
in USI_TWI_Master.h and
#define F_CPU 1000000UL to #define F_CPU 8000000UL
in USI_TWI_Master.cpp
It is also necessary after that to install the bootloader.

Regards
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks nbenm and all!

However I'm stumped. So please help if you can.

I remember reading somewhere in the maelstrom of pages I read in the last 24hrs, about changing the read and write value but I can't find it.  Any ideas?

C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp: In member function 'int I2CIO::begin(uint8_t)':
C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp:74: error: 'class USI_TWI' has no member named 'read'
C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp: In member function 'uint8_t I2CIO::read()':
C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp:127: error: 'class USI_TWI' has no member named 'read'
C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp: In member function 'int I2CIO::write(uint8_t)':
C:\Users\Win 7\Documents\Arduino\libraries\LiquidCrystal\I2CIO.cpp:150: error: 'class USI_TWI' has no member named 'write'

Arduino Uno
1.5.4
ATTiny85
LCD LCM1602 IIC 20x4

Thanks
Ciaran
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello folks !

Sorry for reviving this older thread but i thought it would be better then creating another.
I´ve been trying to get my Attiny861@8mhz to work with TinyWireM and a lcd library, i´m using the black i2c adapter.

http://playground.arduino.cc/uploads/Code/LiquidCrystal_I2C_85V1.zip
Couldn´t get this lib to work aswell smiley-sad

I succeeded in getting it to work with the Digispark library the way nbenm did but the lcd only initializes after i flash my chip !?!
If i power my chip it does not initialize and shows 1 row of bars. I´ve tried adding delay and using lcd.begin and .display after init() call but i dont get it to work.

@nbenm: You said you succeeded in using fmalpartidas library, could you post your modified version so i can give it a try ?
« Last Edit: April 21, 2014, 07:17:26 pm by smithy » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem solved, seems like Tinyisp configured with knockbang is sending something like a heartbeat over spi and since i use the same pins for usi communication it breaks the initialisation of the lcd when powering via usb.
When i power up via battery it works but its very slow resulting in a delay over 1 sec before you can read the display.
I´ll try set Tinywire to 8 mhz and see if it still works.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 52
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For those interested was able to remove the delay by decreasing the delay of 1 sec at following line of LiquidCrystal_I2C.cpp
Code:
expanderWrite(_backlightval); // reset expanderand turn backlight off (Bit 8 =1)
delay(10);
Furthermore i decreased the 3 tries to 1 some lines beneath.
Code:
write4bits(0x03 << 4);
delayMicroseconds(4500); // wait min 4.1ms
Now the display initializes instantly and there is pretty much no difference regarding usage, i even used the 2 remaining pins of the I2C adapter and attached 2 buttons to it and it all works !
Now it is possible to have 1 side only for input readings and the other for output communication, even with a crystal (without 5) you have 3 pins left (4 with reset) and already 2 buttons and a display attached to it wich is a big improvement regarding more complex projects with the attiny series.

BIG THANKS to this awesome community !
Logged

Pages: 1 [2]   Go Up
Jump to: