Hi guys! Not sure if his is the correct subforum..
I am developing standalone special-purpose thermostat unit with ATMega328p-pu, programmed by pulling the chip out from socket into arduino, so I can't really use serial debugging etc...
I am using standard I2C adapter into 16x2 LCD display. I had to sniff the address (by modifying the SPI_CHECK, i was able to identify the DEC adress by reading number of LED blinks...), it was 0x3F instead of standard 0x20/0x27. So, the LCD is responding, backlight works and 1st row is full, just as it is supposed to do with no data. Yes, I played with the contrast pot..
But I got stuck somewhere in the initialisation, i found out that the micro freezes at the lcd.begin(16, 2), because the led blinks no more...
I will gladly provide any additional information, just to fix this, because I am running out of time a bit
Here is the code - not completed, but working:
/*
* Thermostat build 1
* Calibrated: null
* Maroš Macko 2016
*/
//Pin lookup
#define rLed 9
#define gLed 10
#define button1 5
#define button2 6
#define button3 7
#define button4 8
#define buttonPress 3 // interrupt
#define ThermistorPIN1 A0
#define ThermistorPIN2 A1 //Read temperature
#define relay A2 //A2
#include <math.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //A5 - SCL
float vcc = 5; // only used for display purposes, if used set to the measured Vcc.
float pad = 9850; // balance/pad resistor value, set this to the measured resistance of your pad resistor
float thermr = 10000; // thermistor nominal resistance
float inT;
float ouT;
bool relayState = 0;
volatile byte manual = LOW;
void setup()
{
delay(1000);
//display
gblink();
lcd.begin(16, 2);
rblink();
lcd.backlight();
gblink();
lcd.setCursor(0, 0);
rblink();
lcd.print(" Thermostat v1");
gblink();
lcd.setCursor(0, 1);
lcd.print(" by Maros Macko");
delay(3000);
//Pin setup
pinMode(rLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(buttonPress, INPUT);
pinMode(ThermistorPIN1, INPUT);
pinMode(ThermistorPIN2, INPUT);
pinMode(relay, OUTPUT);
//Test flashes
digitalWrite(rLed, HIGH);
delay(500);
digitalWrite(rLed, LOW);
digitalWrite(gLed, HIGH);
delay(500);
digitalWrite(gLed, LOW);
delay(500);
//attachInterrupt(digitalPinToInterrupt(3), intmanual, FALLING);
}
void rblink()
{
digitalWrite(rLed, HIGH);
delay(200);
digitalWrite(rLed, LOW);
}
void gblink()
{
digitalWrite(gLed, HIGH);
delay(200);
digitalWrite(gLed, LOW);
}
void loop()
{
Sensors();
if(manual = HIGH)
{
relayState == 1;
digitalWrite(relay, HIGH);
}
else if(relayState == 0)
{
if((inT > 5) && (inT - ouT > 1.5))
{
relayState = 1;
digitalWrite(relay, HIGH);
}
}
else
{
if(inT < 3)
{
relayState = 0;
digitalWrite(relay, LOW);
}
else if ((inT > 5) && (ouT - inT > 1.5))
{
relayState = 0;
digitalWrite(relay, LOW);
}
}
displayInfo();
delay(5000); //(5s)
}
void Sensors() {
inT = Thermistor(analogRead(ThermistorPIN1));
ouT = Thermistor(analogRead(ThermistorPIN2));
}
void displayInfo()
{
gblink();
lcd.clear();
//lcd.print("inT=".inT."°C ouT=".ouT."°C");
lcd.setCursor(0,1);
if(manual == HIGH) lcd.print("Vent: ON manual");
else if(relayState == 0) lcd.print("Vent: OFF");
else if(relayState == 1) lcd.print("Vent: ON");
}
float Thermistor(int RawADC) {
long Resistance;
float Temp;
Resistance=pad*((1024.0 / RawADC) - 1);
Temp = log(Resistance);
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; //K to C
return Temp;
}
Thanks!