Hi Folks,
New to arduino, really enjoying the learning experience .
I have a project reading 2 ds18b20 temp probes displaying on to a i2c 16x2 LCD. the code has been copied and changed to suit my project needs and is probably a mess with all the tweeks I have made to get to where I am now.
I hope to add LED's at some point reacting to temp changes within set ranges, but for now I am stuck on stripping a decimal place on the ds18b20 displayed reading.
I have managed to get what I am after via serial but the lcd display refuses to play ball within my very limited knowledge.
here is the code I have (please forgive the mess and structure, im sure there is more efficient ways but I am only at the beginning of my learning).
I should add,
it currently displays as
20.68
i would like
20.7
if poss
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 4 on the Arduino
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress redprobe = { 0x28, 0x47, 0xAF, 0xC8, 0x1A, 0x13, 0x01, 0x50 };
DeviceAddress blackprobe = { 0x28, 0xAA, 0x49, 0x65, 0x13, 0x13, 0x02, 0x2D };
#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#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
int n = 1;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup(void)
{
lcd.begin (16,2); // <<----- My LCD was 16x2
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.setCursor(2,0);
lcd.print("Testing temps");
lcd.setCursor(5,1);
lcd.print("DS18B20");
delay(3000);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("Fetching");
lcd.setCursor(2,1);
lcd.print("Temperatures");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("R Temp:");
lcd.setCursor(13,0);
lcd.print((char)223);
lcd.setCursor(14,0);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("B Temp:");
lcd.setCursor(13,1);
lcd.print((char)223);
lcd.setCursor(14,1);
lcd.print("C");
delay(1000);
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(redprobe, 12);
sensors.setResolution(blackprobe, 12);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC,1);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
sensors.requestTemperatures();
lcd.setCursor(8,0);
lcd.print(sensors.getTempC(redprobe));
lcd.setCursor(8,1);
lcd.print(sensors.getTempC(blackprobe));
delay(1000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Red Probe is: ");
printTemperature(redprobe);
Serial.print("\n\r");
Serial.print("Black Probe is: ");
printTemperature(blackprobe);
Serial.print("\n\r");
}
Any help guidance greatly appreciated.