Go Down

Topic: Please Help me!!!! DS18B20 I2C LCD board problem (Read 890 times) previous topic - next topic

lp250isme

//==========================================
//1-Wire  Library
#include <OneWire.h>
#include <DallasTemperature.h>
//==========================================
//I2C + I2C LCD Library
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LCD.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // set the LCD address to 0x27 for a 16 chars and 2 line display
/*==========================================
SDA - 接 Arduino 的 Analog Pin 4 (Arduino Mega 為 Pin 20)
SCL - 接 Arduino 的 Analog Pin 5 (Arduino Mega 為 Pin 21)
GND - 接 GND
VCC - 接 +5V
==========================================*/

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

String lcdDegC="" , lcdDegF="";  //, SerialDegC="" ,SerialDegF="";

void setup(void)

  lcd.begin(16,2);
  delay(1000);
  //start reading
  sensors.begin();
  //lcd.begin(16,2);
  lcdDegC += char(223);              // Setup a Degrees C LCD Symbol
  lcdDegC += "C ";
  lcdDegF += char(223);              // Setup a Degrees F LCD Symbol
  lcdDegF += "F ";
 
  /*
  SerialDegC += char(167);           // Setup a Degrees C Serial symbol
  SerialDegC += " C ";
  SerialDegF += char(167);           // Setup a Degrees F Serial symbol
  SerialDegF += " F ";
  */
  //LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);                  // initialize the lcd
  // Print a message to the LCD.
  //lcd.backlight();
    // 輸出初始化文字
  //lcd.setCursor(0, 0); // 設定游標位置在第一行行首
  //lcd.print("Hello, world!");
  delay(1000);
  lcd.clear();
  //lcd.begin(16, 2);
}

void loop(void)
{

  // Send the command to get temperatures
  sensors.requestTemperatures(); 
  float celsius = sensors.getTempCByIndex(0);
  float fahrenheit = (1.8 * celsius) + 32; 
 
 
  lcd.setCursor(0, 0);                   // 設定游標位置在第1行行首
  lcd.print("Temperature is: ");
  lcd.setCursor(0, 1);                   // 設定游標位置在第2行行首
  lcd.print(celsius);
  lcd.setCursor(5, 1);         
  lcd.print(lcdDegC);
 // lcd.print(Serial.println(celsius));
  //lcd.setCursor(9, 1);                 
  //lcd.print(fahrenheit);
  //lcd.print(lcdDegF);
 Serial.println(celsius);

  // Serial.println("degree C");
   
  //Serial.print("Fahrenheit: ");
  //Serial.println(fahrenheit);

  // Serial.println("degree F");
  /*
  Serial.print("Temperature is: ");
  Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  //Update value every 1 sec.
  */
 
  delay(1000);
 
}




I can't display temperature on my I2C LCD board.
It always shows -127c

can anyone solve this?

But without line: lcd.begin(16,2);
It will show on the serial window with the actually temperature ,but I2c board doesn't show anything.
 :'(  :'(  :'(  :'(  :'(  :'(  :'(


thank you very much!

Nick_Pyner


lp250isme

Bad sensor connections.
what that mean??

How can i solve the problem please...

Nick_Pyner

It means exactly what it says - bad connections - and the solution is to make good connections.

To elaborate: returning 127 means Arduino cannot see the sensor, and therefore thinks it is not present. If it is there but improperly connected, it means the same thing to Arduino - no sensor, hence -127. 

They may have the same problem where the connections per se are actually kosher, but you are using cheapo cable, and the end result is the same. It could be that the cable is simply too long, but normal practice should be good for about 10m.


floresta

#4
Nov 03, 2016, 03:04 pm Last Edit: Nov 03, 2016, 03:05 pm by floresta
Quote
. . . But without line: lcd.begin(16,2);
It will show on the serial window with the actually temperature ,but I2c board doesn't show anything. . . .
Wouldn't this indicate an I2C problem as opposed to a sensor problem?

There have only been a few dozen of these I2C problems reported recently (possibly in the last few hours) so he can probably find a solution by looking through the recent forum posts in the Displays section.

Don

Nick_Pyner

It might mean he has an I2C problem and a sensor problem, but I don't think fixing the former will fix the latter, and it depends on what he really means by "actually". I am only commenting on the sensor and it is not on I2C bus.

el_supremo

Code: [Select]

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
...
#define ONE_WIRE_BUS 2


Looks like you're using pin 2 for the LCD and for the DS18B20. The DS18B20 must not use one of the pins that the LCD is using.

Pete
Don't send me technical questions via Private Message.

lp250isme

Code: [Select]

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
...
#define ONE_WIRE_BUS 2


Looks like you're using pin 2 for the LCD and for the DS18B20. The DS18B20 must not use one of the pins that the LCD is using.

Pete

Thank!!!!!!!!!!!!!!!!!!!!!!

I solve it .

you really help me so much .

I love u

Go Up