Stap 7: Toevoegen in het LCD-scherm
Zo met onze klok en onze temperatuursensoren werken, let's get sommige output naar de LCD controller.
Het eerste deel van dit is het bepalen wat ik wil zeggen. Ruimte is enigszins beperkt, aangezien ik slechts een totaal van 32 tekens over 2 lijnen, dus de eerste vraag die ik had te beantwoorden is hoe kan ik alles wat die ik nodig om weer te geven binnen deze 32 tekens weergeven.
Hier zijn mijn definitieve LCD uitlezingen:
Zone1: ()
Modus:
Zone2: ()
Oven:
Zone3: ()
Open: < 1,2,3 / geen >
gevallen waarin T1 is temperatuur voor zone 1, TT doel temperatuur, MODE wordt de huidige modus draait (AWAKE, AWAY, HOME, slaap, OVERSCHRIJVEN, of HOLD.
Open verwijst naar die van de zones momenteel open en ontvangende warmte zijn (als de oven wordt uitgevoerd).
Dit was eigenlijk vrij eenvoudig. Ik heb sommige uitzoeken om te doen wat een aangepast symbool is betrokken, maar het is vrij ver naar beneden op mijn prioriteitenlijst.
<tt><tt><tt> /* This is the application that I will be using to control the furnace. The concept is this: I have 3 zones I will be monitoring. Each zone will have at least one zone damper which will be controlled by the arduino application. Each zone will have a single thermometer which will report back to the controller. Depending on the thermometer reading and the thermostat setting, the dampers will open or shut and the central furnace will be turned on. Once an acceptable temperature has been reached in all zones, the furnace will turn off. In addition to general heating cycles, the system will be programmable. At this time, however, the programming cycle will be handled here, not via the thermostat. IMPORTANT TEST CASES: (to be added as I think of them/come across them * Need to ensure that the furnace is always off if all 3 dampers are closed. * dampers should be open unless they specifically need to be closed. */ #include <LiquidCrystal.h> //This is a library needed for the LCD display #include <OneWire.h> //This is a library needed for the thermometer readings #include <DallasTemperature.h> //This is a temperature library #include <Wire.h> #include "RTClib.h" // Connections: // rs (LCD pin 4) to Arduino pin 12 // rw (LCD pin 5) to Arduino pin 11 // enable (LCD pin 6) to Arduino pin 10 // LCD pin 15 to Arduino pin 13 // LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2 LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); byte deg[8] = { B01000, B10100, B01000, B00111, B00100, B00110, B00100, B00100 }; const int backlight = 13; //controls backlight #define THERM_BUS 6 // all temperature readings come in via this single pin. OneWire oneWire(THERM_BUS); DallasTemperature sensors(&oneWire); DeviceAddress zone1Therm = { 0x28, 0x48, 0x39, 0x11, 0x04, 0x00, 0x00, 0x94}; DeviceAddress zone2Therm = { 0x28, 0xF2, 0x1F, 0x11, 0x04, 0x00, 0x00, 0x38}; DeviceAddress zone3Therm = { 0x28, 0xBA, 0xF3, 0x10, 0x04, 0x00, 0x00, 0x98}; RTC_DS1307 RTC; // START PROGRAMMING // Times are 6 AM, 8 AM, 3PM, and 9PM int* PROGRAMMED_VALUES[7]; int SUNDAY_VALUES[4] = { 67, 67, 67, 60}; int MONDAY_VALUES[4] = { 67, 67, 67, 60}; int TUESDAY_VALUES[4] = { 67, 67, 67, 60}; int WEDNESDAY_VALUES[4] = { 67, 67, 67, 60}; int THURSDAY_VALUES[4] = { 67, 67, 67, 60}; int FRIDAY_VALUES[4] = { 67, 67, 90, 75}; int SATURDAY_VALUES[4] = { 67, 67, 67, 60}; //END PROGRAMMING float zone1Temp = 0; float zone2Temp = 0; float zone3Temp = 0; boolean z1Check = 0; boolean z2Check = 0; boolean z3Check = 0; boolean isOverrideHeld = false; boolean isOverridden = false; boolean furnaceState = false; //with furnaceState, false means it's currently off, true means its currently on. int overrideValue = 0; const int furnacePin = 1; int zoneCounter = 0; void setup() { Serial.begin(57600); // This connects the arduino to the computer //TEMPERATURE SENSOR SETUP sensors.begin(); sensors.setResolution(zone1Therm, 10); lcd.createChar(0, deg); // RTC SETUP. Wire.begin(); RTC.begin(); if(!RTC.isrunning()){ log("ERROR", "RTC is NOT running!"); //RTC.adjust(DateTime(__DATE__, __TIME__)); //THIS ONLY NEEDS TO BE UNCOMMENTED IF YOU ARE SETTING UP YOUR RTC FOR THE FIRST TIME! ONCE IT IS SET, THIS MUST BE DISABLED! } //SETUP OUTPUTS pinMode(furnacePin, OUTPUT); pinMode(backlight, OUTPUT); digitalWrite(backlight, HIGH); //SETTING UP THE WEEKLY PROGRAM PROGRAMMED_VALUES[0] = SUNDAY_VALUES; PROGRAMMED_VALUES[1] = MONDAY_VALUES; PROGRAMMED_VALUES[2] = TUESDAY_VALUES; PROGRAMMED_VALUES[3] = WEDNESDAY_VALUES; PROGRAMMED_VALUES[4] = THURSDAY_VALUES; PROGRAMMED_VALUES[5] = FRIDAY_VALUES; PROGRAMMED_VALUES[6] = SATURDAY_VALUES; } // this runs the continual loop void loop() { delay(3000); //DELAY CURRENTLY SET TO 10 SECONDS. WILL ADJUST AS NEEDED //DATE/TIME LOGIC log("TIME", "Loop initiated at " + getDateAndTime()); //TEMPERATURE LOGIC sensors.requestTemperatures(); zone1Temp = getTemperature(zone1Therm); zone2Temp = getTemperature(zone2Therm); zone3Temp = getTemperature(zone3Therm); logTemperatureData(); getScreenOutput(); z1Check = checkZoneTemp(zone1Temp); z2Check = checkZoneTemp(zone2Temp); z3Check = checkZoneTemp(zone3Temp); if(z1Check || z2Check || z3Check){ startFurnace(); } else { stopFurnace(); } if(z1Check && furnaceState) { closeDamper(1); } else { openDamper(1); } if(z2Check && furnaceState) { closeDamper(2); } else { openDamper(2); } if(z3Check && furnaceState) { closeDamper(3); } else { openDamper(3); } } boolean checkZoneTemp(int temperature) { int temp = getTargetTemperature(); if(temperature > temp){ return false; } return true; } void logTemperatureData() { log("Zone1Temp", (String)(int)zone1Temp); log("Zone2Temp", (String)(int)zone2Temp); log("Zone3Temp", (String)(int)zone3Temp); } void getScreenOutput() { zoneCounter++; if(zoneCounter == 1){ String val = "Zone1: " + (String)(int)zone1Temp; val += " (" + (String)getTargetTemperature(); val += (String)")"; toScreen(val, "Mode: " + getModeString()); } else if (zoneCounter == 2){ String val = "Zone2: " + (String)(int)zone2Temp; val += " (" + (String)getTargetTemperature(); val += (String)")"; toScreen(val, "Furnace: " + getFurnaceState()); } else { zoneCounter = 0; String val = "Zone3: " + (String)(int)zone3Temp; val += " (" + (String)getTargetTemperature(); val += (String)")"; toScreen(val, "Open: " + getActiveZonesForScreen()); } } int getTargetTemperature(){ int mode = getMode(); DateTime now = RTC.now(); int date = now.dayOfWeek(); int* values = { 0 }; log("info", (String)date); values = PROGRAMMED_VALUES[date]; log("info", "getting target temp: " + (String)values[mode]); return values[mode]; } String getActiveZonesForScreen(){ String retVal = ""; if(z1Check && !furnaceState){ retVal += "1,"; } if(z2Check && !furnaceState) { retVal += "2,"; } if(z3Check && !furnaceState){ retVal += "3"; } if(retVal.length() == 0) { retVal += "None"; } return retVal; } String getFurnaceState(){ if(furnaceState){ return "On"; } else { return "Off"; } } String getModeString() { int mode = getMode(); switch (mode) { case 0: return "Wake"; case 1: return "Away"; case 2: return "Home"; case 3: return "Sleep"; default: return "N/A"; } } int getMode() { DateTime now = RTC.now(); int hour = now.hour(); if(hour < 6 || hour >= 21) { return 3; } if(hour >= 6 && hour < 8){ return 0; } if(hour >=8 && hour < 15){ return 1; } if(hour >= 15 && hour < 21){ return 2; } } float getTemperature(DeviceAddress deviceAddress) { float tempC = sensors.getTempC(deviceAddress); //Serial.println(tempC); if(tempC == -127){ Serial.println("ERROR getting temperature."); } return DallasTemperature::toFahrenheit(tempC); } //convenience function. Handles all the boilerplate for writing to the LCDScreen void toScreen(String line1Value, String line2Value) { lcd.begin(16,2); lcd.clear(); lcd.setCursor(0,0); lcd.print(line1Value); lcd.setCursor(0,1); lcd.print(line2Value); } String getDateAndTime() { DateTime now = RTC.now(); return String(now.year()) + "/" + String(now.month()) + "/" + String(now.day()) + " " + String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second()); } void openDamper(int damper) { // if(damper == damper1Pin || damper == damper2Pin || damper == damper3Pin) { // digitalWrite(damper, HIGH); // } else { // log("Problem opening damper. Damper not found. Was expecting 1, 2, or 3. Got " + damper); // } } void closeDamper(int damper) { // if(damper == damper1Pin || damper == damper2Pin || damper == damper3Pin) { // digitalWrite(damper, LOW); // } else { // log("Problem closing damper. Damper not found. Was expecting 1, 2, or 3. Got " + damper); // } } //function for logging messages to the console. //Eventually plan to write to logfile on RPi void log(String code, String message) { Serial.println(code + ": " + message); } void recordData(String type, String object, String value) { // TODO - output to RPi database } void startFurnace(){ //Send appropriate signal to the furnace to start up if(!furnaceState) { furnaceState = !furnaceState; log("INFO", "STARTING FURNACE"); digitalWrite(furnacePin, HIGH); } } void stopFurnace(){ //Send appropriate signal to the furnace to stop if(furnaceState){ furnaceState = !furnaceState; log("INFO", "STOPPING FURNACE"); digitalWrite(furnacePin, LOW); } } </tt></tt></tt>