Sending bytes to a serial GLCD

Hello everyone,

I have this GLCD ( http://www.eio.com/admin/images/Downloads/DX300INST.pdf)

using the hardware serial on the UNO board I am able to connect by sending byte 85. the issue is printing text to the screen. each string has to be terminated with a ( 0 ). It seems the I am unable to send multiple bytes at one time. For example:

Serial.write("HelloWorld",0); // send HelloWorld to display

I get these error messages:

" SerialGLCD.ino:24: error: invalid conversion from 'const char*' to 'const uint8_t*'
SerialGLCD.ino:24: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
Error compiling"

Any help on this would be greatly appreciated.
Thanks
Charlie

Serial.write("HelloWorld",0);

Serial.write() usually sends one byte out the serial interface, you probably want to use the version that sends out arbitrary data. But even that interfaces needs a pointer to the data and it's length as parameters. What should your statement do? Printing the characters to the display? Why don't you use the print() method for that?

Try:

Serial.print("HelloWorld");

Hi Pylon,

Thanks for the reply. When printing anything to the SGLCD the string has to be terminated with a null character. I tried using print instead of Serial.write, but the compiler still complains. any other ideas?

Charlie

Serial.print("HelloWorld");
Serial.write(0);

How does that work then?

Thanks Python, but that won't work.

Thanks Python, but that won't work.

There's the lamest statement anyone can make on this forum, again.

Something happened. What?

There's the lamest statement anyone can make on this forum, again.

Something happened. What?

Whats lame about thanking someone for trying?

What part of the string has to be terminated with a 0 don't you get. If the string is not terminated then nothing shows on the display.

What part of the string has to be terminated with a 0 don't you get. If the string is not terminated then nothing shows on the display.

Serial.print("HelloWorld");

IS sending a NULL terminated string to the Serial port.

I don't understand your question, or why you think you need to send another NULL.

For example:
Serial.write("HelloWorld",0); // send HelloWorld to display

The second argument to Serial.write() is the number of bytes to send. Why you have that set to 0 is a mystery.

" SerialGLCD.ino:24: error: invalid conversion from 'const char*' to 'const uint8_t*'
SerialGLCD.ino:24: error: initializing argument 1 of 'virtual size_t Print::write(const uint8_t*, size_t)'
Error compiling"

The solution is to lie to the compiler:
Serial.write((const uint8_t *)"HelloWorld", 10);

Note the correct number of values to send.

Thanks Paul,

I don't understand your question, or why you think you need to send another NULL.

This is taken from the link in my original post. Thats why its there.

" Text strings are limited to 40 characters at a time and must be terminated with a null byte[0] "

Is this possible with arduino?

" Text strings are limited to 40 characters at a time and must be terminated with a null byte[0] "

That says NOTHING about you needing to send a NULL to the LCD.

Is this possible with arduino?

Of course, but I'm starting to have my doubts about it being possible for you.

" Text strings are limited to 40 characters at a time and must be terminated with a null byte[0] "
That says NOTHING about you needing to send a NULL to the LCD.

That is directly from the SGLCD. it says the string has to be terminated with a Zero.

Of course, but I'm starting to have my doubts about it being possible for you.

Now Paul why the smart comments. I see you live is Washington. Let me guess... you are 15 living with a single parent and all you do is play with arduino and smoke weed. I just needed some clarification on a problem. I would appreciate if you don't have anything constructive to contribute then don't post on my thread.

That is directly from the SGLCD. it says the string has to be terminated with a Zero.

But, where does it say that you have to send an additional NULL/zero to the device? The NULL tells Serial.print() when to stop sending data. It does NOT result in Serial.print() sending a NULL anywhere.

Let me guess... you are 15 living with a single parent and all you do is play with arduino and smoke weed.

About as accurate as any other statement you've made so far. That is wrong on all assumptions.

Paul, the backpack document is a bit vague but it seems to imply that the backpack
wants to see a byte of zero to terminate the character string processing on the
backpack. It has nothing to do with the code running on the AVR.

Chaz,
As far as actually sending the extra 0 byte,

Serial.print("Hello World");
Serial.write((uint8_t) 0);

Or optionally to make it easier or clearer create a global constant variable up top
outside all your functions:

const uint8_t NULLBYTE=0;

Then down in your code:

Serial.print(F("Hello World")); // puts string in AVR pgm space to save ram
Serial.write(NULLBYTE); // send a null byte to the backpack

Note: don't try to use NULL as that is already defined to be something else.

Or to make it even easier use a macro:

#define lcdStringOut(_str) \
do { \
    Serial.print(_str); \
    Serial.write((uint8_t) 0);\
} while(0)

Put this up top above your code.
Then in your code simply use it:

lcdStringOut("HelloWorld");
lcdStringOut(F("HelloWorld"));  // to use AVR progmem and save RAM.

You can name the macro whatever you want.

--- bill