Pages: [1]   Go Down
Author Topic: Compatibility issue with LiquidCrystal.h and Wire.h  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have an issue with the usage of LiquidCrystal.h and Wire.h in the same sketch:

This is the minimal sketch to reproduce the error:
The issue is: as soon as I uncomment the line with the code Wire.begin() my LCD is totally corrupted (both lines).
If this line is commented everything is fine and the LCD displays all characters in both lines perfectly.

I work under Arduino 1.0.1 and I use the libraries LiquidCrystal.h and Wire.h from this installation.

The sketch is here:
Code:
#include "Wire.h"

// include the LCD library code
#include "LiquidCrystal.h"

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup() {
     
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
   
    // as soon as I uncomment the next line my LCD gets corrupted
    // Wire.begin();
   
}

void loop() {
    // Print a message to the LCD.
    lcd.setCursor(0, 0);
    lcd.print("LCD Test");

    lcd.setCursor(0, 1);
    lcd.print("ax=");
   
    // delay
    delay(500);               // wait for 500ms
}

Any idea how to fix this ?

Thanks in advance.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What Arduino board do you have?
Logged

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

I have a new Olimexino-32u4 (Leonardo compatible), operated and power supplied from the USB port.
Under Arduino IDE it appears correctly as Arduino Leonardo.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It would be helpful to mention that in the original post.

http://arduino.cc/en/Main/ArduinoBoardLeonardo

From that page:

Quote
TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library.

Code:
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

The Wire hardware on that board uses pins 2 and 3. You are using them for the LCD. Once initialized, the Wire library "takes over" those pins. Choose different ones for the LCD.
« Last Edit: November 25, 2012, 04:43:04 pm by Nick Gammon » Logged

Georgia, US
Offline Offline
Jr. Member
**
Karma: 2
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My first thought was conflicting pin assignments but that looks ok. (Wire.h looks like it only uses A4/A5) As a test, try changing to
Code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
to something like
Code:
[s]LiquidCrystal lcd(A5, A4, A3, A2, 3, 2);[/s]
Hell scratch that. I just got Warning - while you were reading 3 new replies have been posted. You may wish to review your post. Nick beat me to it. smiley-cry
Logged

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

Thank you very much Nick for the fast reply. Now I understand the issue and I think I can easily resolve it.
My wrong assumption was that  SCA and SCL lines are separate from the Dxy pins.
Now I have also seen in the schematic of the board that they are connected to each other
but also put to different board headers. So in effect we have them duplicated on the headers ?
Does it make sense ?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

They brought them out to separate pins because on the Uno SDA/SCL are A4/A5. By doing that manufacturers of shields can get the SDA/SCL from those extra pins, without worrying about which pins on the underlying board they should use.
Logged

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

Hi Nick,
o.k. understood and thank you again: By changing the pins I got my program and LCD working as expected.
I am very happy that I got so fast the issue resolved with your help.
Logged

Pages: [1]   Go Up
Jump to: