Hi Folks,
Strange one this, I have a project that was working before I made some changes, i.e. changed a 16x2 for a 20x4 lcd.
now I cant remember if they stopped working when I changed lcd's or after maybe I tweeked some code without registering.
heres my code see if you guru's can spot anything I am missing?
any help / advise greatly appreciated
#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 redprobe_RED_LED 9
#define redprobe_GRN_LED 10
#define blackprobe_RED_LED 11
#define blackprobe_GRN_LED 12
#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 (20, 4);
pinMode(redprobe_RED_LED, OUTPUT);
pinMode(redprobe_GRN_LED, OUTPUT);
pinMode(blackprobe_RED_LED, OUTPUT);
pinMode(blackprobe_GRN_LED, OUTPUT);
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
lcd.setCursor(1, 1);
lcd.print("Environment Agency");
lcd.setCursor(3, 2);
lcd.print("Fish Husbandry");
delay(4000);
lcd.clear();
lcd.setCursor(6, 1);
lcd.print("Fetching");
lcd.setCursor(4, 2);
lcd.print("Temperatures");
delay(2000);
// 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(redprobe);
Serial.print(tempC);
if (tempC < 20.0) {
digitalWrite(redprobe_RED_LED, LOW);
digitalWrite(redprobe_GRN_LED, HIGH);
}
else {
digitalWrite(redprobe_RED_LED, HIGH);
digitalWrite(redprobe_GRN_LED, LOW);
delay(500);
digitalWrite(redprobe_RED_LED, LOW);
digitalWrite(redprobe_GRN_LED, LOW);
delay(500);
}
{
float tempC = sensors.getTempC(blackprobe);
Serial.print(tempC);
if (tempC < 20.0) {
digitalWrite(blackprobe_RED_LED, LOW);
digitalWrite(blackprobe_GRN_LED, HIGH);
}
else {
digitalWrite(blackprobe_RED_LED, HIGH);
digitalWrite(blackprobe_GRN_LED, LOW);
delay(500);
digitalWrite(blackprobe_RED_LED, LOW);
digitalWrite(blackprobe_GRN_LED, LOW);
delay(500);
}
}
{
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.clear();
lcd.setCursor(0, 0);
lcd.print("Red Air Line:");
lcd.setCursor(18, 0);
lcd.print((char)223);
lcd.setCursor(19, 0);
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Blk Air Line:");
lcd.setCursor(18, 3);
lcd.print((char)223);
lcd.setCursor(19, 3);
lcd.print("C");
lcd.setCursor(14, 0);
lcd.print(sensors.getTempC(redprobe), 1);
lcd.setCursor(14, 3);
lcd.print(sensors.getTempC(blackprobe), 1);
delay(500);
}
// Serial.print("Getting temperatures...\n\r");
// sensors.requestTemperatures();
//
// Serial.print("Red Probe is: ");
// printTemperature(redprobe);
// Serial.print("\n\r");
// Serial.print("Blk Probe is: ");
// printTemperature(blackprobe);
// Serial.print("\n\r");