Go Down

Topic: LCD3Wire and two displays. (Read 792 times) previous topic - next topic

tkniques

Aug 07, 2008, 11:33 pm Last Edit: Aug 07, 2008, 11:42 pm by tkniques Reason: 1
Hi,
So I've got two 40x2 character lcds and I'm using the LCD3Wire library to drive them, via two 4094 shift registers.  My problem is that which ever lcd object is created last becomes the only on that gets used.  For example:
Code: [Select]
include <LCD3Wire.h>

// Arduino pins
#define LCD_LINES 2  // number of lines in your display
#define LCD2_LINES 2
#define DOUT_PIN  11  // Dout pin
#define STR_PIN   12  // Strobe pin
#define CLK_PIN   10  // Clock pin
#define STR2_PIN  9   // Strobe pin for lcd 2
#define DOUT2_PIN 8   // Dout pin for lcd 2
#define CLK2_PIN  7   // Clock pin for lcd 2

//create object to control an LCD.
LCD3Wire lcd2 = LCD3Wire(LCD2_LINES, DOUT2_PIN, STR2_PIN, CLK2_PIN);
LCD3Wire lcd = LCD3Wire(LCD_LINES, DOUT_PIN, STR_PIN, CLK_PIN);

void setup() {
 
 lcd.init();
 lcd2.init();
 
}

void loop() {  
 
 lcd.printIn("This is a test of display one.");
 delay(500);
 lcd.clear();
 lcd2.printIn("This is a test of display two.");
 delay(500);
 lcd2.clear();
}


Results in the first LCD, (using the object lcd) printing "This is display one" as well as "This is display two".  If the lcd2 object had been created last it would display the same thing while the other did nothing.  So somehow both the lcd objects end up pointing at the same physical device even though their constructors are given different values.  The last one created seems to overwrite the initialization of the previous.

I'm assuming that it is some sort of constructor issue with the library itself but I'm a little rusty.  Again I assume somehow the variables for the pins are being shared by both instantiations of the LCD3Wire objects, I just don't know where to go from here. Can anyone help or point me in the right direction.

EDIT: lcd and lcd2 are not static anymore, no change.

dnear1

Isn't the strobe pin used to tell the LCD that you are talking to that particular display?

If this is the case, try to mod the library to switch displays based on an extra value passed to the procedure..  have both the clock and dout pins tied to both displays but the strobe pins on a separate line.
In the case of 4-wire library we can just have two Enable pins..
Or you could modify the library so if the 'cursor' is set to line 5,6,7 or 8 instead of line 1,2,3 or 4 it will use the other pin(s) to the second screen..
After that you need to delete the .o file in the library so it will recompile.

tkniques

In this instance no, the strobe pin is used to tell the shift register to output its buffer to the pins.  But that gives me a idea.

I just can't seem to figure out how to make multiple unique instances of an class as I think that's the problem.

melka

Were can I find the LCD3Wire library ? I searched on google and my Arduino install folder, nothing...
I wanted to look in the file, maybe some global vars are declared (I was thinking about the pins you pass as parameters), which will obviously overwrite the previous settings if it's the case...

tkniques

The 3Wire library is located at http://www.arduino.cc/playground/Code/LCD3wires

Who knows, maybe I don't correctly know how to make two unique objects of the same class.  Bah.  I feel like I'm getting close but missing something that must be obvious.

Go Up