Help need with 4BitLCD and Serial data

I thought the DS18B20 was acurrate to thousandths? Isn't it 9 bit or greater? (can't remember off the top of my head).

I'll have to work on this later, it's getting too late here (almost 2AM!)

Thank you for your help thus far mem!

I thought the DS18B20 was acurrate to thousandths? Isn't it 9 bit or greater? (can't remember off the top of my head).

the datasheet says its ±0.5°C accuracy from –10°C to +85°C

So, I swapped in your function mem on the sensor module, and no such luck :( Same issues (cycling/wrapping, and black blocks). pulls out tuft of hair Any thoughts?

Did you try the code posted in reply #6? if that still has a problem, paste the output you get so I can have a look.

Now it consistantly cycles. I had to modify your code a bit (ammended '||(i>=6)' to the conditional) as the sensor is no longer sending carridge returns or line feeds. (Verified this by running your code unmodified, and nothing displayed at all as no line feed was sent).

Here's what I mean by cycles:

Say the sensor is sending "12.345" on every update.

What will be displayed is: "12.345" then next update: "2.3451" then ".34512" then "34512." and so on and so forth.

However, the black blocks are not showing up anymore.

I just did another test to narrow down the problem. I hard coded the sensor arduino to just send the string "12.345". No such luck. The LCD still cycles the number, so the problem isn't on the sensor side. Which is good because now I know there isn't an issue with that side, but bad in that I'm still completely flummoxed as to what's going on :(

Ok, so the rotation of the data is definitely happening inside the buffer. Since char 2 should always be a decimal point, I put a little check in to pass true only if it is indeed a decimal point. It only returns true 1 out of every 6 times. I'm at a complete loss on how to fix this though :'( insert plea for help here. I have no idea why or where in the process the buffer data is getting rotated.

This sketch may help you debug your code. It waits for a message of exactly 6 characters preceded by a single character header and displays the message on the LCD.

You can test it by sending messages using the serial monitor. The header is the > char and if you send >12.345 from the Arduino IDE you should see the correct value displayed on the LCD.

Because the code waits for a valid header, it will strip out any unexpected characters that may be on the serial port.

If it doesn’t work as expected, try it with the library LCD code just to make sure the problem is not in your version of the LCD library.

Once you verify that the display side is working ok you can check to see if there is any difference from what you get from the sensor.

Good luck!

#include <LCD4Bit.h> 
#define MSG_HEADER  '>'   // message  header 
#define MSG_LEN  6      //  nbr of chars excluding header i.e. 12.345


LCD4Bit lcd = LCD4Bit(2); 

void setup() { 
  Serial.begin(19200);
  lcd.init();
  lcd.printIn("Ready");
  //  lcd.backlightOn(); 
}

boolean getMessage(char * buffer) {
  boolean gotMsg = false;

  if( Serial.available() && (Serial.read() == MSG_HEADER) ) {                  
    while(Serial.available() < MSG_LEN)
       ; // wait for all characters in msg       
    for(int i =0; i < MSG_LEN; i++)
      buffer[i] = Serial.read(); // fill the buffer
    buffer[MSG_LEN] = 0;  // null terminate the string  
    gotMsg = true;  // set the return code to indicate we have a valid message
  }      
  return gotMsg; // returns true only if valid message received 
}

void loop(){
  char message[MSG_LEN + 1]; // array holding the received message and terminating null

  if( getMessage(message) ){
    lcd.clear();
    lcd.printIn("Temperature:");
    lcd.cursorTo(2,0);
    lcd.printIn(message);
    lcd.printIn(" F");
  }   
}

Success!!! The using the header did the trick! I can now send and receive data and it remains properly aligned! (and black blocks are nowhere to be seen!). Thank you very much mem!

Now to try and figure out how to turn a string back into a double... :D (need to make some alarms based on the received temperature. If you've got any thoughts on this, I'd love any ideas, but I realize you may be a bit sick of helping me out at this point ;) )

Here is a hint if your alarm trigger points will ignore the fractional values. You can treat the value as an int if you know where the decimal point is. There are a number of threads here that have examples of converting a string to an int.

Cool, thanks :slight_smile:

Just an update. Doing what you suggested works perfectly for this application mem: I'm just using the whole number for the alarm triggers. I ended up using the atoi function to turn the two characters into an integer. Works wonderfully. Now if I can just figure out why on earth the arduino consistently resets itself if I try and do Serial.print or Serial.println calls... ::)

but I realize you may be a bit sick of helping me out at this point ;) )

Don't bet on it--I am frequently amazed at the amount of time Mem invests in helping people out on this board. :D

--Phil.

but I realize you may be a bit sick of helping me out at this point ;) )

Don't bet on it--I am frequently amazed at the amount of time Mem invests in helping people out on this board. :D

--Phil.

I am equally amazed about the effort Phil must have put in to provide all the useful information here: http://code.rancidbacon.com/ :D

Hehe. I too am amazed (and thankful! Thanks mem!)

I am equally amazed about the effort Phil must have put in to provide all the useful information here: http://code.rancidbacon.com/ :D

Thanks for the positive feedback--it's appreciated. :D

I have to say deciding to document things on a personal wiki/lab notebook like that site has been a great thing--I'm sure it helps me at least as much as it helps anyone else. :) And since it's only a little bit of effort at a time it doesn't seem like I'm really doing much. I recommend doing the same to everybody!

I feel like I provide more of a drive-by style of assistance whereas you will camp out and provide detailed assistance to the same person for seemingly weeks or months on end... :o

But hey, let's face it the Arduino community in its entirety is just pretty jolly cool... :)

--Phil.