Sending a "newline" to an I2c 20x4 lcd

I am transmitting temperature/humidity via an Apc220 to an Arduino with a 20x4 I2C LCD. The text being received as a single string, and is "Temperature: xx.xxC Humidity: xx%". What i am getting on the LCD is:

Temperature: xx.xxCH

umidity: xx%


I need to insert a newline char between the C and H,in the transmitted signal, to put humidity on it's own line. I also need to eliminate the extra blank line in between temperature and humidity. I've tried all the newline characters I can figure out but have not found any that work. Is there an easy to separate the string into 2 smaller strings at the CH boundary? Then I could send the LCD to line 1,0 and the humidity line should fit.

Jim

I've tried all the newline characters I can figure out but have not found any that work.

There is no 'newline' character or command inherent in the LCD controller or in the LiquidCrystal library.

I also need to eliminate the extra blank line in between temperature and humidity.

The extra blank line is due to the unique characteristics of the LCD controller. Follow the LCD Addressing link at http://web.alfredstate.edu/weimandn for an explanation.

Is there an easy to separate the string into 2 smaller strings at the CH boundary?

Probably. One of the 'C' programmers will have to help you out here.

Then I could send the LCD to line 1,0 and the humidity line should fit.

That's the simplest solution.

Don

Is there an easy to separate the string into 2 smaller strings at the CH boundary?

If the string always has the same format

char str [] = "Temperature: xx.xxC Humidity: xx%"

char * ptr_to_Hstr;  // create a pointer to char

ptr_to_Hstr = str + 19;  // point it to the space between C and H

*ptr_to_Hstr++ = '\0';   // stick a NULL byte there and move the pointer to the next char (the H)

// now we have two separate strings

Serial.println (str);
Serial.println (ptr_to_Hstr);

Rob

To Graynomad

The string could be possibly be:

"Temperature: xx.xxC Humidity: xx%"
or
"Temperature: xxx.xxC Humidity: xx%"

depending on the temperature. However, as I live at 6000 feet(1900 meters), I don't think it's too likely, so I'll use your provided code. I am an old VB programmer, and don't know using pointers that well, I'm used to VB's string functions.

THANKS A LOT
Jim

What about when it is cold? Like 9 or less?
No need to hard code the position, there are many standard C functions
for doing this kind of work for you.
Use strstr() instead to locate the correct position rather than assume it is 19.
http://www.cplusplus.com/reference/clibrary/cstring/strstr/

Assuming it is a character between the C and H,
In Graynomad's example it would be:

ptr_to_Hstr = strstr(str, " H"); // point it to the space between C and H

To locate the position of the space character.

--- billl

I implemenmted Graynomad's code, it half worked. Now I get:

T|| |||
H|| |||

on the LCD. Obviously it does not respond like a serial device.

bperrybap, how about -29F(-34C), I've seen that here. Actually, if it is below 20F(-7C), I not going out there anyway. Seriously though, how do I get that string.h into the ICD? I would prefer making my program as flexible as possible.

Thanks for the reply!

Jim

20x4 I2C LCD.

Jim - I totally missed the 'I2C' part of your title. Depending on how the device has been implemented it is possible that some sort of newline routine has been implemented in the interface. There are no standards for these interfaces, each controller is different, so we will need some documentation in order to help with that part.

Even if you find such an implementation you may be better off getting this current technique working.

Don

Now I get:

T|| |||
H|| |||

Do you get the right values of you send them to the serial port?


Rob