Go Down

Topic: Values does not update itself on the LCD but does on the serial comm (Read 434 times) previous topic - next topic

quickfire

Hi guys, I have a problem with my 16 pin LCD currently. I'm making a thermostat which displays the current temperature and selected temperature(temperature is chosen using a potentiometer).
On the LCD it should display values for "Set to:" and "Currently:". Now here is the weird part, the "Currently" values seems to update itself however the "Set to" does not respond to changes made to the potentiometer. Funny thing is that it both values update itself on the serial comm and is working perfectly. Any ideas what is happening? Also, there are unnecessary lines being displayed as well. How do i get rid of those? I've added a picture!

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal.h>

int tmp102Address = 0x48;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potPin = A0; //analog 0
int relayPin = 1;// digital 2

int lowTemp = 25; //lowest temp in C you can set it to
int highTemp = 35; //highest temp in C you can set it to


void setup(){
  Serial.begin(9600);
  Wire.begin();
  lcd.begin(16,2);
  pinMode (relayPin,OUTPUT);
}

void loop(){

  float temperatureSetAt = getThreshold();
 
  float currentCelsius = getTemperature();
 
  if(temperatureSetAt < currentCelsius){
   digitalWrite(relayPin, HIGH); //turn it on
  }else{
    digitalWrite(relayPin, LOW); //turn it off
  }
 
  lcd.print("Set to:");
  lcd.println(temperatureSetAt);
  lcd.setCursor(0, 2);
  lcd.print("Currently:");
  lcd.println(currentCelsius);
  Serial.print("Set Celsius:");
  Serial.println(temperatureSetAt);
 
  Serial.print("Current Celsius: ");
  Serial.println(currentCelsius);


  delay(2000); //just here to slow down the output. You can remove this
}

float getThreshold(){
int potVaule = analogRead(potPin);
potVaule = map(potVaule, 0, 1023, lowTemp, highTemp);

float floatValue = (float)potVaule;
return floatValue;
}

float getTemperature(){
  Wire.requestFrom(tmp102Address,2);

  byte MSB = Wire.read();
  byte LSB = Wire.read();

  //it's a 12bit int, using two's compliment for negative
  int TemperatureSum = ((MSB << 8) | LSB) >> 4;

  float celsius = TemperatureSum*0.0625;
  return celsius;
}


Riva

A couple of things I can see...
Code: [Select]
lcd.print("Set to:");
  lcd.println(temperatureSetAt);
  lcd.setCursor(0, 2);
  lcd.print("Currently:");
  lcd.println(currentCelsius);

Your not doing a setCursor before the initial lcd.print of Set to: so it may not be printing where you expect it to. The other is your using .println instead of .print to send temperatureSetAt & currentCelsius so your getting a couple of strange characters on the lcd.
http://forum.arduino.cc/index.php?action=unread;boards=5,67,10,11,66,12,15,17,21,22,23,24,25,29;ALL

liudr

You should also do (0, 1) instead of (0, 2). The rows are zero-based, row 0 is the first row, row 1 is the second row.

lcd.setCursor(0, 1);

Go Up