Was hoping you guys could help me out here... i'm stuck!
I have a 16x2 LCD hooked up to an arduino (exact to lady ada's picture below with one exception... the 5th pin on the LCD is connected to ardunio digital input #4 [haktronics says pin 5 is used])
http://www.adafruit.com/images/large/LC ... rd_LRG.jpg
I have plugged in a DS18B20 Digital Temperature sensor in. (http://www.sparkfun.com/commerce/produc ... cts_id=245 datasheet link on same page also)
I was going to use an analog temp sensor that I bought from adafruit (i have both analog & digital) but think that since i'm running its 3 wires up and down a 25ft Cat6 cable, digital will be more accurate?
On the DS18B20, I have pin 1 to ground, pin 3 to 5v, and pin 2 to digital input #1 on the arduino.
I have used ladyada.net and http://www.hacktronics.com/Tutorials/ar ... orial.html as resources for this (i converted [hopefully correctly] the pin placements from haktronics diagram -> ladyadas... i've modified the code from haktronics to work with ladyada's LCD wiring below:
Code: Select all
#include <OneWire.h>
#include <LiquidCrystal.h>
// LCD Thermostat
// www.hacktronics.com
LiquidCrystal lcd(7, 4, 8, 9, 10, 11, 12);
int backLight = 13; // pin 13 will control the backlight
OneWire ds(1); // ds18b20 pin #2 (middle pin) to Arduino pin 8
byte i;
byte present = 0;
byte data[7];
byte addr[1];
int HighByte, LowByte, SignBit, Whole, Fract, TReading, Tc_100, FWhole;
void setup(void) {
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0
if ( !ds.search(addr)) {
lcd.clear(); lcd.print("No more addrs");
delay(1000);
ds.reset_search();
return;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
lcd.clear(); lcd.print("CRC not valid!");
delay(1000);
return;
}
}
void getTemp() {
int foo, bar;
ds.reset();
ds.select(addr);
ds.write(0x44,1);
present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for ( i = 0; i < 9; i++) {
data[i] = ds.read();
}
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) {
TReading = -TReading;
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Whole = Tc_100 / 100; // separate off the whole and fractional portions
Fract = Tc_100 % 100;
if (Fract > 49) {
if (SignBit) {
--Whole;
} else {
++Whole;
}
}
if (SignBit) {
bar = -1;
} else {
bar = 1;
}
foo = ((Whole * bar) * 18); // celsius to fahrenheit conversion section
FWhole = (((Whole * bar) * 18) / 10) + 32;
if ((foo % 10) > 4) { // round up if needed
++FWhole;
}
}
void printTemp(void) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp is: ");
lcd.setCursor(0,1);
if (SignBit) {
lcd.print("-");
}
lcd.print(Whole);
lcd.print(" C / ");
lcd.print(FWhole);
lcd.print(" F");
}
void loop(void) {
getTemp();
printTemp();
delay(1000);
}
its as if there is not temperature sensor connected.Temp is:
0*C / 32 F
Any help would be much appreciated!
Thanks.