Guttemann:
I am trying to get the readings from a DS18B20 graphed by Processing, but I can only find examples that use analogue sensors. For the Arduino, I am using this code: http://bildr.org/2011/07/ds18b20-arduino/
I remember that stuff and was singularly unimpressed but I note that you specifically say "a DS18B20" so, if you have it working, with a result on the monitor, it will suffice for now. If not, you might find the code below useful. It is derived from Hacktronics q.v.
Basically, this is what I would like to do:
http://community.cosm.com/arduino/usb/processing#pachube-input
I believe this is all out of date and should be studiously avoided. Assuming you are using a W5100 Ethernet shield, check the cosm site and make sure you get the latest libraries cosm.h and HttpClient.h. If you don't have an ethernet shield yet, make sure you get a W5100. If you have an enc28 ethernet, it is possible to use it on cosm but you will have a harder time with it. There is recent discussion around on that.
but I will settle for a simple graph for the moment
You might find PLX-DAQ useful. It is an Excel macro that gives a local real time graph. It isn't made with Arduino in mind but it is easily adapted, being merely a matter of formatting. This is shown in the code.
/*
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
// code uses Arduino LCD stuff, for shield on Freetronics EtherTen.
// Serial print commands are for PLX-DAQ
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <LiquidCrystal.h>
#include <SD.h>
// These three are required to create the filename
#include <string.h>
#include "RTClib.h"
RTC_DS1307 RTC;
File myFile;
char filename[] = "00000000.CSV";
#include "Wire.h"
#define DS1307_ADDRESS 0x68
LiquidCrystal lcd(8,9,16,5,6,7);
byte InThermo[8] = {
0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
byte DrainThermo[8] = {
0x28, 0x09, 0xA9, 0xC0, 0x03, 0x00, 0x00, 0x95};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int second, minute, hour, weekDay, monthDay, month, year;
int k=0;
float InTemp, OutTemp, DrainTemp; // used for SD write only
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";
char calcId1[] = "diff";
void setup() {
lcd.begin(16, 2);
Wire.begin();
Serial.begin(9600);
Serial.print(" filename ");
delay(300);//Wait for newly restarted system to stabilize
lcd.setCursor (0,0);
lcd.print("Initializing SD");
delay(2000);
lcd.setCursor (0,1);
pinMode(10, OUTPUT);
if (!SD.begin(4)) {
Serial.println("init. failed!");
return;
}
lcd.print("init. OK");
delay(2000);
getFileName();
Serial.println(filename);
lcd.clear();
Serial.println("LABEL,Time,InTemp,OutTemp,diff,DrainTemp");
sensors.setResolution(InThermo, 12);
sensors.setResolution(OutThermo, 12);
sensors.setResolution(DrainThermo, 12);
}
void loop() {
GetClock();
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
if (hour == 0 && minute == 0 && second <2)
{
getFileName();
}
Serial.print("DATA,TIME, ");
Serial.print(monthDay);
Serial.print("/");
Serial.print(month);
Serial.print("/");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
if ((second) < 10)
{
Serial.print("0");
};
Serial.print(second);
Serial.print(" ");
int ret=0;
//get the values from the DS8B20's
sensors.requestTemperatures();
float InTemp = (sensorValue(InThermo));
float OutTemp = (sensorValue(OutThermo));
float DrainTemp = (sensorValue(DrainThermo));
float diff = OutTemp - InTemp;
Serial.print(InTemp);
Serial.print(" , ");
Serial.print(OutTemp);
Serial.print(" , ");
Serial.print(DrainTemp);
Serial.println(" , ");
lcd.setCursor (0,0);
lcd.print(InTemp);
lcd.setCursor (11,0);
lcd.print (OutTemp);
lcd.setCursor(0,1);
lcd.print(diff);
lcd.print(" ");
lcd.setCursor(11,1);
lcd.print(DrainTemp);
k=k+1;
if (k>9 )
{
myFile.print(monthDay);
myFile.print("/");
myFile.print(month);
myFile.print("/");
myFile.print(year);
myFile.print(", ");
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.print(second);
myFile.print(", ");
myFile.print(InTemp);
myFile.print(", ");
myFile.print(OutTemp);
myFile.print(", ");
myFile.print(DrainTemp);
myFile.print(", ");
k=0;
}
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
delay(850);
} // loop ends here
//sensorValue function
float sensorValue (byte deviceAddress[])
{
float tempC = sensors.getTempC (deviceAddress);
return tempC;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal numbers
return ( (val/16*10) + (val%16) );
}
void GetClock(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void getFileName(){
DateTime now = RTC.now();
filename[0] = (now.year()/1000)%10 + '0'; //To get 1st digit from year()
filename[1] = (now.year()/100)%10 + '0'; //To get 2nd digit from year()
filename[2] = (now.year()/10)%10 + '0'; //To get 3rd digit from year()
filename[3] = now.year()%10 + '0'; //To get 4th digit from year()
filename[4] = now.month()/10 + '0'; //To get 1st digit from month()
filename[5] = now.month()%10 + '0'; //To get 2nd digit from month()
filename[6] = now.day()/10 + '0'; //To get 1st digit from day()
filename[7] = now.day()%10 + '0'; //To get 2nd digit from day()
myFile = SD.open(filename, FILE_WRITE);
myFile.close();
}