connecting multiple serial LCDs via arduino

Hi guys...I'm trying to have arduino be able to split an input so that part of it goes to one LCD screen the other part goes to another LCD screen. I'm probably going to have 13-20 screens altogether.

I'm using the SparkFunSerLCD library to do this and I want to be able to send for eg; "hi my name is arduino" and have:

"hi" on the 1st LCD,
"my" on the 2nd LCD,
"name" on the 3rd LCD,
"is" on the 4th LCD,
"arduino" on the 5th LCD

So far, i've tried with 2 LCD screens, and it's not really working. I hope someone can assist me with this issue. (im a newbie)

I basically was testing if there's a space, and if there is, send to the next LCD =\

Here's what i have so far:

#include <SoftwareSerial.h>
#include <SparkFunSerLCD.h>

SparkFunSerLCD led_4(4,2,16);// desired pin, rows, cols
SparkFunSerLCD led_5(5,2,16);
char val; // Data received from the serial port
int col4=1;
int col5=1;

void setup () {

led_4.setup();
led_5.setup();
Serial.begin(9600);

}

void loop ()
{
if (Serial.available()>0) // If data is available to read,
{
val = Serial.read(); // read it and store it in val

col4++;
if (col4 == 16)
{
led_4.empty();
delay(100);
col4 = 1;
}

col5++;
if (col5 == 16)
{
led_5.empty();
delay(100);
col5 = 1;
}

if (val == ' ')
{
led_4.at(2,col4,val);
}
else
{
led_5.at(2,col5,val);
}

}
}

Any help would be greatly appreciated.
Thank you

Looks like you should be getting something. Please describe more about this "and it's not really working". What do you get as an output on the two LCDs? Have you tried getting one working by itself without an interaction from the serial port of the PC?

Yes i have. When i connect 1 LCD, i am able to send a sentence directly to it.

When i connect 2 LCDs and when i try to test if ' ' is present, send the rest to the next LCD, i think ' ' is sent to the next LCD, but the whole same sentence still appears on the first LCD.

For eg:

"hello my name is arduino"

LCD 1: "hello my name is arduino"
LCD 2: " _ _ _ _

I think the spaces are sent to the LCD2 but not the words after spaces.

   if (val == ' ')
   {
     led_4.at(2,col4,val);
   }
   else
   {
     led_5.at(2,col5,val);
   }

This part of your code does one thing or another... it sends spaces to one LCD, or if it's not a space, it sends that to the other LCD.

So it's working exactly as coded... no surprise there since that's what you are seeing.

What you need to do, is use a variable to toggle between the LCDs. Any time your code sees a space ' ', it toggles the variable from 0 to 1, and 1 to 0. Then just use that variable to determine which LCD to send the non-space vals to.

e.g.

   boolean which_lcd = 0;

   //...

   if (val == ' ')
     which_lcd = !which_lcd;

   if (which_lcd)  //switch between LCDs based on which_lcd state
   {
      led_4.at(2,col4,val);
   }
   else
   {
      led_5.at(2,col5,val);
   }

it still gives me the same results >.< and a boolean would only enable me to control 2 LCDs? =\

Hmm... I'm kind of stumped at the moment... I just tried this and it recognizes the ' ' just fine, and spits back "space" to the PC.

#include <SoftwareSerial.h>
char val; // Data received from the serial port
void setup () {
  Serial.begin(9600);
}

void loop ()
{
  if (Serial.available()>0)  // If data is available to read,
  {
    val = Serial.read(); // read it and store it in val
    if (val == ' ')
    {
      Serial.println("SPACE");
    }
  }
}

Yes boolean will only be good for two states.. but that's all I needed in MY example :wink: You wouldn't want me to code the whole thing for you would ya? Haha.

Change your delimiter to ',' comma and see if things become more clear. It's hard to SEE space on the LCD... right?

Describe what's happening after the changing the delimiter, and please post your code as it stands.

This is probably closer to what you want:

void loop() {
  boolean which_lcd = 0;

  if (Serial.available() > 0) { // If data is available to read,
    val = Serial.read(); // read it and store it in val

    if (val == ' ') { // space character, switch LCDs for next character, throw away space
      which_lcd = !which_lcd;
    }
    else { // any other character comes here
      if (which_lcd) { // switch between LCDs based on which_lcd state
        col4++;

        if (col4 == 16) {
          led_4.empty();
          delay(100);
          col4 = 1;
        }

        led_4.at(2,col4,val);
      }
      else {
        col5++;

        if (col5 == 16) {
          led_5.empty();
          delay(100);
          col5 = 1;
        }

        led_5.at(2,col5,val);
      } 
    }
  }
}

I can't guarantee it is bug free, and supporting even more screens isn't included (you could continue to expand this code as-is to do it, but a more scalable solution would use arrays for the column positioning, and a state machine for the LCD switching).

I also appologize for changing the bracing structure; I am just so used to using this style that anything else looks "wrong" to me...

Hope this helps in some way...

:slight_smile:

True, Cr0sh... you would want to only increment the column counter when that particular display was being written to.

Something else that will need to be thought through... when the space comes and forces the display pointer to switch, at some point you are going to end up at a display that already has a word output to it. Instead of overwriting that word, the display should be cleared first.

So we don't necessarily want to clear the display when it hits the 16th column, but really when we write to it again.

Of course, if a word is larger than 16 characters... what do you do? I say truncate... just because I don't know what the application consists of. I.e., if the displays are close enough together to spill a long word over to the next display, and it still be legible.