[SOLVED] I2C 20x4 LCD shuts off on temp display

I'm attempting to get the temperature to read out on my LCD and not having much success on my Mega2650.

If I replace the portion after the void loop with a simple lcd.print ("Hello World") type statement it pops right up but trying to switch over to the temp probe shuts it off.

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
int tempPin = 30;



void setup()
{
lcd.begin (20,4,LCD_5x8DOTS);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
}

void loop()
{
 int tempReading = analogRead(tempPin);
 float tempVolts = tempReading * 5.0 / 1024.0;
 float tempC = (tempVolts - 0.5) * 100.0;
 float tempF = tempC * 9.0 / 5.0 + 32.0;
 // ----------------
 lcd.print("Temp F ");
 lcd.setCursor(0,0);
 lcd.print(tempF);
 delay(1000);
}

I know there is probably something really obvious I'm doing wrong. I just don't know what it is. Any help?

For starters do you mind if I ask what kind of sensor you are using ?

I'm attempting to get the temperature to read out on my LCD and not having much success on my Mega2650.

Am I speaking english ?
What is your temperature sensor device (part #/ datasheet) ?

Let's get some ground rules straight here.
This is the way this works.
You're the one asking for help.
You ask a question then it's our turn.
You don't get to choose what questions we ask.
If we ask you for photos, you give us photos and like that.
You don't have to like our question or even understand it.
You're supposed to humor us.
There's a whole list of things you are supposed to supply us with on your FIRST posting.
I haven't asked you for any of that.
All I asked you was one simple question.
If you can't humor me and answer a simple question then this conversation is over.
I think I know what's wrong with your program but I am not going to tell you until
you answer my one simple question.
We're trying to help you .
If you don't want to cooperate. That's fine. That's your right.
But don't expect any help.
ok?
Incidently,

but trying to switch over to the temp probe shuts it off.

What does this mean "switch over" ?

raschemmel:
Let's get some ground rules straight here.
This is the way this works.
You're the one asking for help.
You ask a question then it's our turn.
You don't get to choose what questions we ask.
If we ask you for photos, you give us photos and like that.
You don't have to like our question or even understand it.
You're supposed to humor us.
There's a whole list of things you are supposed to supply us with on your FIRST posting.
I haven't asked you for any of that.
All I asked you was one simple question.
If you can't humor me and answer a simple question then this conversation is over.
I think I know what's wrong with your program but I am not going to tell you until
you answer my one simple question.
We're trying to help you .
If you don't want to cooperate. That's fine. That's your right.
But don't expect any help.
ok?

Its a One Wire DS18B20 in a waterproof housing and the datasheet can be found at http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

I apologize for the late reply. This is a hobby for me...something I do when my kids are taking a nap and/or in the late evenings when the family has gone to bed (which is why I'm at the computer now). I appreciate your willingness to help so please don't take my lack of reply till this point as some kind of 'brushing you off'.

Incidently,

but trying to switch over to the temp probe shuts it off.

What does this mean "switch over" ?

When I'm running just a static lcd.print ("Hello World") the LCD works fine.
When I attempt to display the temp probe information on the LCD the LCD shuts off.

I know there is probably something really obvious I'm doing wrong. I just don't know what it is. Any help?

So, let me see if I understand this correctly.
You're trying to read a 64 bit laser code from a ONE-WIRE DIGITAL DEVICE with an ANALOG READ statement of DIGITAL
PIN -30 (PC7)(A15) ?
Is that what I am to understand ?
If you don't me asking, how much Arduino interfacing experience do you have exactly ?

Oh, I forgot , OH MY GOD !?

Yeah, OK Raschemmel, he's apologised for the delayed response, answered your questions, admitted he's new to this. What more do you want from the guy? How about you come up with a bit less attitude? We were all beginners once upon a time.

That being said, Raschemmel's point is that you need to read the datasheet for your sensor. The signal coming from it is a digital signal and needs to be read in 1-bit at a time. You may also need to set up some registers in it, etc. I suggest you read through the datasheet and search the web for details on how others have interfaced with it. If you haven't done this sort of thing before, there's a bit of learning ahead of you.

Here's a starting point for you:

http://playground.arduino.cc/Learning/OneWire

HBPapa,
My apologies, I overreacted. I should have been more understanding.
You're right Arduinolb. That was rude of me. It won't happen again.

You know Raschemmel, I have the utmost respect for you and your Mea Culpa to HBPapa. Many people wouldn't have said what you just did. It gives one hope for humanity. Thank you for that, Sir. Peace.

Thank you for that.
I bought my first Arduino UNO on Oct 27, (almost exactly 3 weeks ago) and already I have a big
head. XD
I still feel I need to make it up to HBPapa so I just ordered a DS18B20 from Mouser for about $5.
To be completely honest, I am intrigued by the whole ONEWIRE concept and it wouldn't hurt to
know how to use them. We always need to measure temperature where I work because we build
equipment that handles huge amounts of power so there's several large heat sinks and lots of fans.
I looked at the example code and it's way beyond anything I have attemped so far. That parasitic
power concept blows my mind. I've never tried to read a string of bits before. I have 2 UNOs and
a Pro-Mini so do you think I could practice doing something similar to the ONEWIRE code but
by sending a datastream from one UNO to the other and reading the CRC (I've neve done that
before either) ? Do you know a link where I can learn to do that ?

raschemmel:
I bought my first Arduino UNO on Oct 27, (almost exactly 3 weeks ago) and already I have a big
head. XD

lol

That parasitic power concept blows my mind.

yeah, that looks pretty cute. Powering off a fully digital stream. Nice.

I've never tried to read a string of bits before. I have 2 UNOs and
a Pro-Mini so do you think I could practice doing something similar to the ONEWIRE code but
by sending a datastream from one UNO to the other and reading the CRC (I've neve done that
before either) ? Do you know a link where I can learn to do that ?

Unfortunately, I'm the wrong person to ask, but hopefully someone here will chip in (although it does sound quite doable). My Arduino work was a TFT based project to control some motors, so I just needed a bit of research, the right shields, the right motors, and to do some coding. But, I have been doing some initial work for a friend who wants to do the whole LED stairs thing, so that's interesting. I haven't tried to do any comms yet with the arduinos, but I'll be interested to hear how yours goes. :slight_smile:

lcd.print("Temp F ");
 lcd.setCursor(0,0);
 lcd.print(tempF);
 delay(1000);

Oh, I almost forgot.
HBpapa,
Do you remember when I said I thought I knew what was wrong with your program ?
The reason I asked you what kind of sensor device you were using is because there are
a myriad of types of devices and even though I saw that you were doing an analog
read, I wanted to first confirm that you weren't using and I2C or SPI device.
It never occurred to me that you would be using ONE WIRE. Anyway, if it turned
out that you were in fact using an analog device (like an LM34) I was going to tell you
that the problem with your program is that you are performing lcd.print("Temp F ");
statement BEFORE the lcd.setCursor(0,0); statement. I have a 31855 thermocouple
module and a program to print the temperature on my LCD. The program works
perfectly and the code looks like this:

// basic readout test, just print the current temp
   lcd.setCursor(0, 0);
   lcd.print("Int. Temp = ");

with the set cursor BEFORE the print, not the other way around.
Obviously, now you have much bigger fish to fry but FYI, I thought you should know anyway
so you wouldn't go through all that trouble learning the code for a DS18B20 only
to have it not display correctly.

Thanks all for the replies.

I was able to get the coding figured out. I started looking at my One Wire Serial.print example against the static lcd.print example I had and then started looking at how others were making use of the libraries. In case anyone comes up against this in the future here is the code:

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire ds(30);

#define I2C_ADDR    0x27
#define BACKLIGHT_PIN     3
#define ONE_WIRE_BUS 30
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
DeviceAddress Probe01 = { 0x28, 0x6B, 0xE5, 0xE3, 0x03, 0x00, 0x00, 0x08 };
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);




void setup(void)
{
  Serial.begin(9600);
  lcd.begin(20, 4);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  sensors.begin();
  sensors.setResolution(10);
}

void loop(void) 

{
  sensors.requestTemperatures();
  lcd.setCursor(0,1);
  lcd.print("C= ");
  lcd.print(sensors.getTempCByIndex(0));
  lcd.print(" ");
  lcd.setCursor(0,0);
  lcd.print("F= ");
  lcd.print(sensors.getTempFByIndex(0));
  lcd.print(" ");
  delay(1200);
}

Congratulations on getting it up and running.

arduinodlb:
Congratulations on getting it up and running.

Thank you. Its my first time getting anything other than the 'Hello World' example to work on an LCD. I just started a month ago and have no previous experience with any kind of code or electrical circuits. I want to build an automation system for my reef aquarium and my oldest daughter wants me to build her a robot (a WALL-E).

One again I appreciate the help. It got me to look at things with a more critical eye.

CONGRATULATIONS !
That was quick. You didn't waste any time. Your code will come in handy when I get my DS18B20 from Mouser.
Here's a link to a tutorial on installing libraries, which is something that has caused a lot of grief to people who
had perfectly good code but did not install the library correctly.

And again, sorry I overreacted.

I got my DS18B2O today and got it working with two different programs.(see attached).
DS18B20 Temperature came from here:

The above program has serial output, the two have LCD output, i2c , the other 4-bit parallel.
Some have serial out , some don't . I only ordered one sensor but now that I have several different
ways to use it I wish I had ordered 3. I guess I'll just have order two more...
HBpapa,
I tried your code and it didn't work with my lcd. I haven't figured out why yet.

DS18x20_Temperature_I2C_LCD.ino (4.24 KB)

ONEWIRE_DS18B20_4_bit_LCD.ino (3.74 KB)

DS18x20_Temperature.pde (2.96 KB)

I posted the wrong program for the I2C lcd last night. The one I posted "works" as far as DB18B20
is concerned but I had not finished editing the lcd.print statements and the information was not
showing up where it should. I corrected that so that it only shows the device type and the temp
and doesn't overwrite anything . So here it is. I like this program because it also has very detailed
serial output. The ONEWIRE_DS18B20_4_bit_lcd does not. Of course you "port" (I don't know
exactly what that means but I have a general idea) all of the serial.print commands from the
i2c_lcd program to the 4_bit_lcd program one line at a time since that's a lot easier than
trying to figure out how to position a long string of ROM hex values on a 16 character display.
I've also included another one for a 4-bit display (ds18b20_temp_sensor_ok) It displays
both celsius and Fahrenheit . I realized while doing this that I need to initiate a protocol for myself
whereby I put all the information pertaining to a program in a single folder, (like pasting the website
URL into a notepad file named [prognm_origin].txt.

ds18b20_temp_sensor_ok.ino (2.44 KB)