From 472d14b048f90c54d802ed75a8fc5c410bcad1c3 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 8 Aug 2023 20:36:16 +0200 Subject: [PATCH] add i2c 16x2 display output --- main/main.ino | 60 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/main/main.ino b/main/main.ino index 8999e98..7ada6b7 100644 --- a/main/main.ino +++ b/main/main.ino @@ -5,6 +5,9 @@ #include #include +#include + +LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows // Data wire is conntec to the Arduino digital pin 4 #define ONE_WIRE_BUS 2 @@ -38,7 +41,32 @@ uint8_t addrSensor1[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD1, 0xB1, 0x75 }; uint8_t addrSensor2[8] = { 0x28, 0xFF, 0x64, 0x1F, 0x79, 0xD7, 0xDA, 0x9A }; void setup() { - // put your setup code here, to run once: + lcd.init(); // initialize the lcd + lcd.backlight(); + + lcd.clear(); // clear display + lcd.setCursor(0, 0); // move cursor to (0, 0) + lcd.print("*fridge control*"); // print message at (0, 0) + lcd.setCursor(0, 1); // move cursor to (0, 0) + lcd.print(" by DeltaLima"); + delay(1500); + + // display default values + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("1: H"); + lcd.print(HTemp1); + lcd.print(" L"); + lcd.print(LTemp1); + + lcd.setCursor(0, 1); + lcd.print("2: H"); + lcd.print(HTemp2); + lcd.print(" L"); + lcd.print(LTemp2); + delay(3500); + + // init MOSFET Pins pinMode(MOSFET1, OUTPUT); pinMode(MOSFET2, OUTPUT); @@ -48,9 +76,9 @@ void setup() { } void loop() { - + // get sensor values sensors.requestTemperatures(); - + tempSensor1 = sensors.getTempC(addrSensor1); if(tempSensor1 > HTemp1) { digitalWrite(MOSFET1, HIGH); @@ -69,6 +97,30 @@ void loop() { fetState2 = 0; } + // LCD Display + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("1: "); + lcd.print(tempSensor1); + lcd.print(" "); + lcd.print((char)223); + lcd.print("C"); + lcd.setCursor(14,0); + lcd.print("|"); + lcd.print(fetState1); + + lcd.setCursor(0, 1); + lcd.print("2: "); + lcd.print(tempSensor2); + lcd.print(" "); + lcd.print((char)223); + lcd.print("C"); + lcd.setCursor(14,1); + lcd.print("|"); + lcd.print(fetState2); + + + // JSON StaticJsonDocument<96> jsonOut; //jsonOut["sensor"] = "1"; jsonOut["1"]["temp"] = tempSensor1; @@ -79,6 +131,8 @@ void loop() { jsonOut["2"]["state"] = fetState2; serializeJson(jsonOut, Serial); Serial.println(); + + delay(5000); }