Hi every one. Just started with arduino and Im a bit stuck.
I have used code from the net and changed it about to suit my needs but I have hit a stumbling block.
I can read the temperature on the serial but it will not send to the lcd screen and display, every thing else is fine.
Can some one please point me in the right direction.
Any comments much appreciated.
/*
MultiTempSensor
*/
//Include's
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h> // Library for LCD
#include <Wire.h> // Library for I2C communication
//Constants
#define SENSOR_PIN 5
#define READ_TIMER 10000 //10 seconds
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
//
OneWire oneWire(SENSOR_PIN);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
//Sensor Adresses
DeviceAddress Sensor1 = { 0x28, 0x31, 0xAF, 0x78, 0x32, 0x19, 0x01, 0xBD };
//DeviceAddress Sensor2 = { 0x28, 0xFF, 0xE2, 0x0F, 0x61, 0x16, 0x03, 0x21 };
//DeviceAddress Sensor3 = { 0x28, 0xFF, 0x38, 0xB3, 0x60, 0x16, 0x03, 0xEA };
//DeviceAddress Sensor4 = { 0x28, 0xFF, 0xA4, 0xBE, 0x60, 0x16, 0x03, 0xE1 };
//DeviceAddress Sensor5 = { 0x28, 0xFF, 0xFE, 0x13, 0x61, 0x16, 0x03, 0x56 };
//DeviceAddress Sensor6 = { 0x28, 0xFF, 0x89, 0xBA, 0x60, 0x16, 0x03, 0xFB };
//DeviceAddress Sensor7 = { 0x28, 0xFF, 0xFA, 0xBC, 0x60, 0x16, 0x03, 0xD1 };
//DeviceAddress Sensor8 = { 0x28, 0xFF, 0x57, 0xB1, 0x60, 0x16, 0x03, 0x93 };
int amountOfSensors = 1;
const int oilswitch = 2; // the number of the oilswitch input pin
//variable to check amount of sensors on bus once in a while
int counterCheckBus = 0;
int oilState = 0; // variable for reading the oil switch status
void setup()
{
pinMode(oilswitch, INPUT);
// Initiate the LCD:
lcd.init();
lcd.backlight();
Serial.begin(9600);
sensors.begin();
// Startup screen, will show on power up
lcd.setCursor(0,1);
lcd.print("START UP PLEASE WAIT");
delay(3000);
lcd.setCursor(0,1);
lcd.print(" ");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" SYSTEM SELF TEST ");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" ");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" SYSTEM SELF TEST ");
delay(1000);
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);
// start serial port to show results
Serial.begin(9600);
//display_Running_Sketch();
//printProgramName();
lcd.setCursor(1,0);
lcd.print("Init Temp Cont Lib");
lcd.setCursor(4,2);
lcd.print("V14.06.2020");
delay(3000);
lcd.clear();
delay(1000);
lcd.setCursor(1,1);
lcd.print("Searching for ");
lcd.setCursor(18,1);
lcd.print(amountOfSensors);
lcd.setCursor(2,3);
lcd.println("sensors...");
delay(5000);
lcd.clear();
delay(1000);
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
sensors.setResolution(Sensor1, 10);
//sensors.setResolution(Sensor2, 10);
//sensors.setResolution(Sensor3, 10);
//sensors.setResolution(Sensor4, 10);
//sensors.setResolution(Sensor5, 10);
//sensors.setResolution(Sensor6, 10);
//sensors.setResolution(Sensor7, 10);
//sensors.setResolution(Sensor8, 10);
getSensorsOnBus();
Serial.println("System initialized");
}
void loop()
{
//Oil pressure status, input from pin 2
oilState = digitalRead(oilswitch);
if (oilState == HIGH) {
lcd.setCursor(11, 0);
lcd.print("O/P FAULT");
} else {
lcd.setCursor(11, 0);
lcd.print("O/P OK ");
}
counterCheckBus++;
delay(READ_TIMER);
Serial.println();
if (counterCheckBus == 360)
{
getSensorsOnBus();
counterCheckBus = 0;
}
sensors.requestTemperatures();
Serial.print("Sensor 1: ");
printTemperature(Sensor1);
Serial.println();
// Print 'Input text' on the first line of the LCD:
lcd.setCursor(0, 0); // Set the cursor on the first column and first row.
lcd.print("O/T "); // print the oil temp
lcd.setCursor(5,0);
//lcd.write(Serial.read)(Sensor1);
lcd.setCursor(10, 0); //Set the cursor on the third column and the second row (counting starts at 0!).
lcd.print("c");
//Serial.print("Sensor 2: ");
//printTemperature(Sensor2);
//Serial.println();
//Serial.print("Sensor 3: ");
//printTemperature(Sensor3);
//Serial.println();
//Serial.print("Sensor 4: ");
//printTemperature(Sensor4);
//Serial.println();
//Serial.print("Sensor 5: ");
//printTemperature(Sensor5);
//Serial.println();
//Serial.print("Sensor 6: ");
//printTemperature(Sensor6);
//Serial.println();
//Serial.print("Sensor 7: ");
//printTemperature(Sensor7);
//Serial.println();
//Serial.print("Sensor 8: ");
//printTemperature(Sensor8);
//Serial.println();
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Sensor error!");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
}
}
void printProgramName() {
String path = FILE;
int slash = path.lastIndexOf('\');
String programName = path.substring(slash + 1);
int dot = programName.lastIndexOf('.');
programName = programName.substring(0, dot);
Serial.print("\nProgram version: ");
Serial.println(programName);
}
void getSensorsOnBus() {
Serial.print("Number of sensors found on bus: ");
Serial.println(sensors.getDeviceCount());
}

