Okay I am totally clueless about this arduino code I just started about 3 weeks ago. I have never do any programming. I found this code because I basically have 4 ds18s20's that I want their temperature to show up on an lcd screen. And I also want it to save to the data to a 1 gb microsd card.
I found this code and it was setup for a serial display. i added a fourbit library because I didn't know the codes to do scrolling with the standard lcd library. If anyone knows those I will be happy to change that immediately. Below is my code if anyone wants to take a peek.
//-----DS18S20 Temperature Setup-------
// Sketch to run two DS18s20's on an arduino, outputing to
// a serial enabled 20x4 LCD in Fahrenheit
//
//
// Resources
// http://www.arduino.cc/playground/Code/PrintFloats
// http://www.arduino.cc/playground/Learning/OneWire
// http://216.38.50.214/cgi-bin/yabb2/YaBB.pl?num=1218768628/2
// http://forums.fungizmos.com/viewtopic.php?f=6&t=2&st=0&sk=t&sd=a&sid=4b4e4942df2d3402308d2bf58902cd75
// Datasheets
// DS18s20 - http://pdfserv.maxim-ic.com/en/ds/DS18S20.pdf
// SerLCDv2.5 - http://www.sparkfun.com/datasheets/LCD/SerLCD_V2_5.pdf
//-------------------------------------
#include <OneWire.h> //1-wire library
#undef int
#include <stdio.h>
#include <LCD4Bit.h>
LCD4Bit lcd = LCD4Bit(2);
OneWire ds(5); // on ardunio pin 5
#define BADTEMP -999
// Define unique sensor ID
// DS18S20 inside the house
byte alpha1[8] = {0x10, 0xD6, 0xC4, 0x71, 0x01, 0x08, 0x00, 0x4A};
byte alpha2[8] = {0x10, 0xFE, 0xA2, 0x71, 0x01, 0x08, 0x00, 0xD0};
byte alpha3[8] = {0x10, 0x4A, 0xB3, 0x71, 0x01, 0x08, 0x00, 0xBA};
byte alpha4[8] = {0x10, 0xB5, 0xD7, 0x71, 0x01, 0x08, 0x00, 0xE2};
//----------Initialize------------------
// start serial port
void setup(void) {
Serial.begin(9600);
pinMode(13,OUTPUT);
lcd.init();
lcd.clear();
lcd.cursorTo(1,2);
lcd.printIn("Green Dot Tech");
lcd.cursorTo(2,3);
lcd.printIn("Sensor V.1");
delay(1000);
lcd.leftScroll(20,60);
delay (3000);
lcd.clear();
lcd.cursorTo(1,2);
lcd.printIn("Warming Up");
lcd.cursorTo(2,2);
lcd.printIn("Please Wait");
delay (2000);
lcd.leftScroll(20,60);
lcd.clear();
lcd.cursorTo(1,8);
lcd.printIn("A");
lcd.cursorTo(2,7);
lcd.printIn("B");
}
//---------Search_devices---------------
// Search for 1-wire devices
void search_devices() {
byte addr[8];
int i=0;
if ( !ds.search(addr)) {
Serial.print("No more addresses.\n");
ds.reset_search();
return;
}
Serial.print("R=");
for( i = 0; i < 8; i++) {
Serial.print(addr[i], HEX);
Serial.print(" ");
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.print("CRC is not valid!\n");
return;
}
if ( addr[0] != 0x10) {
Serial.print("Device is not a DS18S20 family device.\n");
return;
}
}
//-----------GetTemp-------------------
float get_temp(byte* addr) {
byte i;
byte present = 0;
byte data[12];
int temp;
float ftemp;
ds.reset();
ds.select(addr);
ds.write(0x44,1); // Start conversion, with parasite power on at the end
delay(1000);
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // We need 9 bytes
data[i] = ds.read();
}
// Get temp in something besides hex, and take the two bytes from
// the response relating to temperature
temp = (data[1]<<8)+data[0];
// Get hi-rez data - see datasheet
int cpc;
int cr = data[6];
cpc = data[7];
if (cpc == 0)
return BADTEMP;
temp = temp >> 1; // Truncate by dropping bit zero for hi-rez forumua
// Fahrenheit conversion
temp = ((temp * 9) / 5.0) + 32; // Comment this line out to get celcius
ftemp = temp - (float)0.25 + (cpc - cr)/(float)cpc; // Per datasheet
return ftemp;
}
//------------PrintFloat---------------
void printFloat(float value, int places) {
// this is used to cast digits
int digit;
float tens = 0.1;
int tenscount = 0;
int i;
float tempfloat = value;
// if value is negative, set tempfloat to the abs value
// make sure we round properly. this could use pow from
//<math.h>, but doesn't seem worth the import
// if this rounding step isn't here, the value 54.321 prints as
//54.3209
// calculate rounding term d: 0.5/pow(10,places)
float d = 0.5;
if (value < 0)
d *= -1.0;
// divide by ten for each decimal place
for (i = 0; i < places; i++)
d/= 10.0;
// this small addition, combined with truncation will round our
// values properly
tempfloat += d;
// first get value tens to be the large power of ten less than value
// tenscount isn't necessary but it would be useful if you wanted
// to know after this how many chars the number will take
if (value < 0)
tempfloat *= -1.0;
while ((tens * 10.0) <= tempfloat) {
tens *= 10.0;
tenscount += 1;
}
// write out the negative if needed
if (value < 0)
Serial.print('-');
if (tenscount == 0)
Serial.print(0, DEC);
for (i=0; i< tenscount; i++) {
digit = (int) (tempfloat/tens);
Serial.print(digit, DEC);
tempfloat = tempfloat - ((float)digit * tens);
tens /= 10.0;
}
// if no places after decimal, stop now and return
if (places <= 0)
return;
// otherwise, write the point and continue on
Serial.print('.');
// now write out each decimal place by shifting digits one by one
// into the ones place and writing the truncated value
for (i = 0; i < places; i++) {
tempfloat *= 10.0;
digit = (int) tempfloat;
Serial.print(digit,DEC);
// once written, subtract off that digit
tempfloat = tempfloat - (float) digit;
}
}
//-------------Loop--------------------
void loop(void) {
//search_devices(); //Gets sensor device id. Comment out to disable
float temp1;
temp1 = get_temp(alpha1);
float temp2;
temp2 = get_temp(alpha2);
float temp3;
temp3= get_temp(alpha3);
float temp4;
temp4= get_temp(alpha4);
char buffer[2];
char baffer[3];
char beffer[4];
char biffer[5];
int temp1a = (((temp1)*100))/100;
int temp2a = ((temp2) - (int)temp2a)*1;
int temp3a = ((temp3) - (int)temp3a)*1;
int temp4a = ((temp4) - (int)temp4a)*1;
/*Serial.print(0xFE, BYTE); // Command flag
Serial.print(130, BYTE); // Position
Serial.print("Ambient Temp (F)");*/
Serial.print(0xFE, BYTE);
Serial.print(192, BYTE);
Serial.print("alpha1 = ");
//printFloat(temp,1);
lcd.cursorTo(1,0);
sprintf(buffer,"%d.%d",temp1a);
lcd.printIn(buffer);
Serial.print(0xFE, BYTE);
Serial.print(148, BYTE);
Serial.print("alpha2 = ");
printFloat(temp2,1);
lcd.cursorTo(2,0);
sprintf(baffer,"%d.%d",temp2a);
lcd.printIn(baffer);
Serial.print(0xFE, BYTE);
Serial.print(148, BYTE);
Serial.print("alpha3 = ");
printFloat(temp2,1);
lcd.cursorTo(2,9);
sprintf(beffer,"%d.%d",temp3a);
lcd.printIn(beffer);
Serial.print(0xFE, BYTE);
Serial.print(148, BYTE);
Serial.print("alpha4 = ");
printFloat(temp2,1);
lcd.cursorTo(1,9);
sprintf(biffer,"%d.%d",temp3a);
lcd.printIn(biffer);
Serial.print(0xFE, BYTE); // Heartbeat to insure the it's working
Serial.print(231, BYTE);
//Serial.print("-");
delay(1000*1); //1 sec loop
Serial.print(0xFE, BYTE);
Serial.print(231, BYTE);
Serial.print("+");
}