LCD3Wire and two displays.

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:

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.

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.

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.

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

The 3Wire library is located at Arduino Playground - 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.

In the .cpp file is this - the variables are external to the class - so they are global and instantiating a new instance of the class will overwrite them.

// --------- settings -------------------------------------

//Data, Clock and Strobe pins are set using the constructor
int dat_pin;
int str_pin;
int clk_pin;

//number of lines of the LCD, set using the constructor
int lcd_lines;

Try removing these 4 external declarations.

And putting them inside the class definition in the .h file. Delete the .o file and recompile the library. Hopefully that will get it to work for you. the class definition should look something like this

class LCD3Wire {
public:
  LCD3Wire(int lcd_lines, int dat_pin, int str_pin, int clk_pin);
  void commandWrite(int value);
  void init();
  void print(int value);
  void printIn(char value[]);
  //non-core---------------
  void clear();
  void cursorTo(int line_num, int x);
  void leftScroll(int chars, int delay_time);
  //end of non-core--------

private:
  void _pushByte(int value, bool command);
  void _pushNibble(int nibble, bool command);
  void _pushOut(int value);
  int dat_pin;
  int str_pin;
  int clk_pin;
  int lcd_lines;
};

Thanks a million Delta, that worked Unfortunately I've gotten rather rusty on my C.

no worrries, glad to help

FYI: Since the strobe pin is what latches the data from buffer to the LCD chip this is exactly the only pin you need to separate between the two displays to use them separately... If both displays share the same clock and data, but you only strobe the particular display you want to feed data to, that is the only one that will update.. it doesn't matter what data you clock to the other display it will ignore it until it receives its own strobe and then it will only accept the last byte it was sent, ignoring all previous data.