View Single Post
  #56  
Old 20-10-2016, 11:36 PM
Shand359 (Shand)
Registered User

Shand359 is offline
 
Join Date: Sep 2016
Posts: 6
LCD Upgrade..... working

Ok, thanks to ChrisV for his help with this.... (would never have been done otherwise...)

I ordered the wrong screen from ebay (2004A) when I first went to build this controller. Re-ordered with the correct OLED one.
The LCD eventually arrived from China and its a HUGE screen compared to the OLED one.

Due to the size of the box I used (to get use of the 4 channels on the MOSFET eventually) I think the larger LCD screen just looks better....

http://vid182.photobucket.com/albums...ps9sa9x8ob.mp4

This is the CODE used for the LCD in case anyone else fancies doing the same.....
Quote:
/*
Dew Heater Controller v4.1_LCD, 18 Oct 2016
Uses Arduino Nano with extension board
Display
20 x 4 LCD, using I2C.
Ambient temperature & humidity
- 1x sensor = DHT22 on digital pin 2
4x temperature sensors for feedback control of heaters on telescope glass
- temperature sensors = DS18B20 on digital pins 10, 11, 12, 8
- heater outputs = digital 3, 5, 6, 9 (PWM). To MOSFET heater drivers
*/
// global constants
const int numHeaters = 4; // max number of heaters
const float tempCutOff = 30; // heater cut-off if too hot
const float dewPointThreshold = 5; // threshold above dew point to start heater
// the display = LCD 20x4 I2C
#include <Wire.h>
// #include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
// setup DHT22 for ambient temperature & humidity sensing.
// on pin 2
#include <DHT.h>
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define DHTPIN 2 // the DHT22 pin
DHT dht(DHTPIN, DHTTYPE);
float dewPointAmbient;
float temperatureAmbient;
float humidityAmbient;
boolean errorDHT22;
// Setup glass temp sensor & heater outputs (MOSFET Driver modules)
// temp sensors on pins 10, 11, 12, 8. DS18B20s using Onewire library
// heater outputs on PWM pins 3, 5, 6, 9
int heaterDutyCycle[] = {0, 0, 0, 0}; // drive to heater
int heaterPin[] = {3, 5, 6, 9}; // heater pins
// Have separate pin for each DS18B20. Easier to wire up and less confusing
#include <OneWire.h>
#include <DallasTemperature.h>
int DS18B20Pin[] = {10, 11, 12, 8};
OneWire oneWire1(DS18B20Pin[0]);
OneWire oneWire2(DS18B20Pin[1]);
OneWire oneWire3(DS18B20Pin[2]);
OneWire oneWire4(DS18B20Pin[3]);
DallasTemperature sensor1(&oneWire1);
DallasTemperature sensor2(&oneWire2);
DallasTemperature sensor3(&oneWire3);
DallasTemperature sensor4(&oneWire4);
boolean errorDS18B20[numHeaters];
float tempHeater[numHeaters];
// general - delay for sensor and "i" for counting
int theDelay = 1000; // need ~1sec delay after DS18B20 read in parasitic mode
int i;
void setup() {
// activate LCD module
lcd.begin (20,4); // for 20 x 4 LCD module
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
// Display intro and heating parameters
lcd.clear(); // clear &set cursor to 0,0
lcd.print("DewHeater 16x4 LCD");
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("Threshold = ");
lcd.print(dewPointThreshold,0);
lcd.print(char(223));
lcd.print("C");
lcd.setCursor (0,2); // go to start of 3rd line
lcd.print("Cutoff = ");
lcd.print(tempCutOff,0);
lcd.print(char(223));
lcd.print("C");
delay(theDelay*4);
// setup heater output pins, and set to zero
for (i = 0; i < numHeaters; i++) {
pinMode(heaterPin[i], OUTPUT); // sets the pin as output
heaterDutyCycle[i] = 0;
analogWrite(heaterPin[i] , heaterDutyCycle[i]);
}
}
void loop() {
// Read ambient temperature & humidity from DHT22
// If no read error, calculate dew point
errorDHT22 = getDHT22data();
// display ambient temp/humidity
displayAmbientData();
// Read temperatures from DS18B20s and set duty cycle.
for (i = 0; i < numHeaters; i++) {
// read the heater, return if an error and value to global variable tempHeater
errorDS18B20[i] = getDS18B20data(i);
// send duty cycle to heater output, set to 0 if any read errors
heaterDutyCycle[i] = setDutyCycle(i);
analogWrite(heaterPin[i] , heaterDutyCycle[i]);
if ( !errorDS18B20[i] ) {
// display heater data if its connected (no errors)
displayHeaterData(i);
}
}
}
boolean getDHT22data() {
float logEx,dewPoint;
boolean anError;
// read the DHT22
humidityAmbient = dht.readHumidity();
// Read temperature as Celsius (the default)
temperatureAmbient = dht.readTemperature();
// Reading temperature or humidity takes about 250 milliseconds. So put in a delay
delay(theDelay);
if (isnan(temperatureAmbient) || isnan(humidityAmbient)) {
// if error reading DHT22 set all to 0
temperatureAmbient = 0;
humidityAmbient = 0;
dewPointAmbient = 0 ;
anError = true;
}
else {
// if no error reading DHT22 calc dew point
// Using the more complex dew point calculation
logEx=0.66077 + 7.5*temperatureAmbient/(237.3+temperatureAmbient) + (log10(humidityAmbient) - 2);
dewPointAmbient = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
// This is the simpler calc
// dewPointAmbient = temperatureAmbient - ((100 - humidityAmbient)/5.0);
anError = false;
}
return anError;
}
boolean getDS18B20data(int theHeater) {
boolean anError = false;
// if sensor/heater connected, start the sensor,
// read temperatures & save to global array tempHeater
// I used to have a 1sec delay after each read, but not needed ?
if (theHeater == 0) {
sensor1.begin();
sensor1.requestTemperatures();
tempHeater[theHeater] = sensor1.getTempCByIndex(0);
}
if (theHeater == 1) {
sensor2.begin();
sensor2.requestTemperatures();
tempHeater[theHeater] = sensor2.getTempCByIndex(0);
}
if (theHeater == 2) {
sensor3.begin();
sensor3.requestTemperatures();
tempHeater[theHeater] = sensor3.getTempCByIndex(0);
}
if (theHeater == 3) {
sensor4.begin();
sensor4.requestTemperatures();
tempHeater[theHeater] = sensor4.getTempCByIndex(0);
}
if (tempHeater[theHeater] == -127) {
anError = true;
}
return anError;
}
int setDutyCycle(int theHeater) {
// set output duty cycle for each heater, using temp diff between heater and ambient dew point
float aboveDewPoint;
float theDutyCycle = 0;
if (errorDHT22 || errorDS18B20[ theHeater ]) {
// Heater OFF if error reading DHT22 or DS18B20 (for this heater)
theDutyCycle = 0;
}
else {
if ( tempHeater[ theHeater ] > tempCutOff ) {
// Heater OFF if above cut-off
theDutyCycle = 0;
}
else {
// Heater ON if Temp < Threshold(C) above dew point(C)
aboveDewPoint = tempHeater[ theHeater ] - dewPointAmbient;
// restrict between 0 & threshold
aboveDewPoint = constrain( aboveDewPoint , 0.0 , dewPointThreshold );
// PWM 0 - 100% duty cycle EQUIV TO analog 0 - 255
theDutyCycle = 255 * (( dewPointThreshold - aboveDewPoint ) / dewPointThreshold );
}
}
return theDutyCycle;
}
void displayAmbientData() {
lcd.clear(); // clear & set cursor to 0,0
lcd.setCursor (0,0); // go to start of 2nd line
if (errorDHT22) {
// error reading DHT22
lcd.print("Temp Humidty DewPt");
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("-error DHT22-");
}
else {
// if ambient read okay display DHT22 data
lcd.print("Ambient");
lcd.setCursor (0,1);
lcd.print("Temp = ");
lcd.print(temperatureAmbient, 0);
lcd.print(char(223));
lcd.print("C ");
lcd.setCursor (0,2);
lcd.print("Humidity = ");
lcd.print(humidityAmbient, 0);
lcd.print("% ");
lcd.setCursor (0,3);
lcd.print("DewPoint = ");
lcd.print(dewPointAmbient, 0);
lcd.print(char(223));
lcd.print("C ");
}
delay(theDelay*2 );
}
void displayHeaterData( int theHeater ) {
float thePerCentDutyCycle;
thePerCentDutyCycle = 100 * heaterDutyCycle[ theHeater ] / 255;
lcd.clear(); // clear & set cursor to 0,0
lcd.print("Heater ");
lcd.print(theHeater+1);
lcd.print(": ");
lcd.print(tempHeater[ theHeater] , 0);
lcd.print(char(223));
lcd.print("C ");
if (tempHeater[ theHeater] > tempCutOff) {
// if above cut-off
lcd.print("CutOFF");
}
else {
if ((tempHeater[ theHeater] - dewPointAmbient) > 0) {
lcd.print("(+");
}
else {
lcd.print("(");
}
lcd.print(tempHeater[ theHeater] - dewPointAmbient , 0);
lcd.print(")");
}
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("Power: ");
lcd.print(thePerCentDutyCycle , 0);
lcd.print("%");
delay(theDelay*2);
}

Last edited by Shand359; 20-10-2016 at 11:39 PM. Reason: adding text
Reply With Quote