loading

Why doesn't my Arduino 'secret thermometer' print to LCD?

[Solved]

I've had my Arduino a few days now and have found this code:

code.google.com/p/tinkerit/wiki/SecretThermometer.

I have tried modifying it with a few basic LCD commands, which I have had working with a 16x2 LCD.

I want it to print the temperature from "readTemp()", divide by 10000 (to get it in degrees C) and print to the LCD (with the "C" character after it).

This is what I have so far:

#include LiquidCrystal

lcd(7, 6, 5, 4, 3, 2);

long readTemp() {
long result;
ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = (result - 125) * 1075;
return result;
}

int temp = (readTemp()/10000, DEC);


void setup(){

lcd.clear();
lcd.begin(16, 2);
lcd.print("Thermuino");
delay(2000);
lcd.clear();
}

void loop(){

lcd.setCursor(3, 0);
lcd.print("C");
lcd.setCursor(0, 0);
lcd.print(temp); // is this where the problem is?
delay(1000);
}



But it does not work, I have checked all I/O lines,  different code etc. and they all work fine. So It must be a mistake in my programming.

All I get is row 0 of the LCD full black all characters along it.

I hope I have provided enough information for you to help :-D



[EDIT]

After removing the "int temp = (readTemp()/10000, DEC);" section and changing "lcd.print(temp);" to "lcd.print(readTemp()/10000);"  it now works! :-D

It prints a correct temperature to the LCD and refreshes it.




Picture of Why doesn't my Arduino 'secret thermometer' print to LCD?
sort by: active | newest | oldest
Grathio7 years ago
Does it successfully print "Thermuino" at the start of the application?  If not then there's something wrong with your LCD setup.

Also you'll probably want to move the "int temp=readTemp()...." line into loop() so it updates with the current temperature.  
Yes, unless Arduinos automagically send the 4 initialisation  bytes to the display, you won't see anything. And the unused dataline should be tied low AFAIR.
Is your wiring spec correct ? It certainly doesn't LOOK wired 7, 6, 5, 4, 3, 2

Steve
Not sure that the LCD.clear is necessary or correct before the LCD.begin line ?

Steve
mathews7 years ago
I have been using a LCD screen for the first time recently, and found that the setup can be a pain. If you are using pre-built libraries ( I assume LiquidCrystal), have you got the LCD connected to the pins it is expecting? Have you instructed the LCD what format to display the data in? I had both these problems.

Also is this C? You may need to open with:
#include <LiquidCrystal.h>

Do you also need an additional library for the ADC.

Have you tried working up in steps? 1) Display something. 2) Display numbers. 3) Read ADC and display raw. 4) Make calculation.