ascii string from serial

hi

I try to put some text from Max5 to a 16x2 LCD display, via an arduino board, using LCD3Wire lib. All is right with hardware but i'm not fluent in C and C++. So i need help to find a way to tell arduino to understand ASCII data string like "hello world!". I suppose i need to declare this string, read it from serial, and then load it to LCD via lcd.print...

thanks a lot for your help !

fxw

I suppose i need to declare this string, read it from serial, and then load it to LCD via lcd.print...

Yes, that's exactly what you need to do! Declare:

char str[32];

Read:

int i = 0;

...

str[i] = ch;
i++;

You'll need to read 'ch' from the serial port, and also you'll need to loop until a newline character is received (so that you know where the string ends).

Printing to LCD:

lcd.print (str);

You'll need to ensure there's a '\0' character in the str buffer. It should be after the newline, or instead of the newline, that you receive. Whenever you advance the index into the buffer, you should also make sure you're not going past the end of the allocated buffer space.

Reads to the first newline, or until the buffer is full, whichever comes first. Then squirts whatever was read into the LCD.

int i = 0;
char str[32];
while (1)
{
    if (i >= sizeof(str))
        break;
    while (!Serial.available())
        ;
    char ch = Serial.read();
    str[i++] = ch;
    if (ch == '\n')
        break;
}
str[i] = '\0';

lcd.print(str);