 |
|
02-22-2009, 10:26 PM
|
#1
|
|
Feedback Score: 0 reviews
Join Date: Jul 2008
Location: Guelph, ON, CANADA
Posts: 75
|
Arduino with 2wire/SMBUS digital thermometer
|
|
Hello Everyone,
I finally managed to get my Arduino talking to a DS1624 Digital Thermometer and Memory IC that I had lying around for a while and thought it might be useful to use for homebrewing. Two wire devices typically only have 4 wires going to them (power, ground and 2 communications lines) and can be installed on a bus and individually addressed. All of the a/d conversion is done on the chip and then the information is transmitted digitally back to the Arduino. Think of it as a mini network connected to the Arduino. The benefits of reading temperatures this way are that you don't need to use any analog ports and you can hook up more than one to the "network" (in the case of the DS1624, there can be a maximum of 8 per "network"). Also there is no chance of any further errors being introduced by wiring lengths or and A-D errors that you might encounter using devices such as the LM34 or LM35.
The DS1624 can measure from -55 C to 125 C in increments of 0.03125 C and has a typical error of less than 0.2 C from 0-80C which makes it pretty good for measuring mash temperatures.
The only trick is getting the the SMBUS communications working correctly on the Arduino using the wire library. I have included some sample code below that will read temperatures from the DS1624.
Note: the DS1624 also has 256 bytes of eeprom onboard as well that can be used to store anything you want (such as 128 temperature readings) although I am not using this feature.
The only downside to these devices is the price. On Digikey they are listed for around $5.90 each (CAD) and thats almost double the cost for an LM35.
Note: attached code uses the printfloat library to be able to print floats to the serial port for monitoring. Once downloaded monitor the serial port to get the temperature output. Also the address is defined by a combination of the device address and the address lines. For my example, the first 4 bits are hard coded in the chip and the last 3 are selectable by address lines. I have tied A0-A1-A2 all to Vdd to give a total address of 1001111
Code:
#include <Wire.h>
#define DS1624_ADDRESS 0x4F
int tempmsb = 0;
int templsb = 0;
int temp2 = 0;
float temperature = 0;
void setup()
{
Serial.begin(9600);
Wire.begin();
delay(100);
ds1624_config();
delay(100);
ds1624_startconvert();
delay(1000);
}
void ds1624_config()
{
// START CONDITION + ADDRESS + MODE
Wire.beginTransmission(DS1624_ADDRESS);
// SEND ACCESS CONFIG PROTOCOL
Wire.send(0xAC);
// SEND CONTINUOUS CONVERSION COMMAND
Wire.send(0x00);
// STOP CONDITION
Wire.endTransmission();
}
void ds1624_startconvert()
{
// START CONDITION + ADDRESS + MODE
Wire.beginTransmission(DS1624_ADDRESS);
// SEND CONTINUOUS CONVERSION COMMAND
Wire.send(0xEE);
// STOP CONDITION
Wire.endTransmission();
}
void ds1624_readtemp()
{
// START CONDITION + ADDRESS + MODE
Wire.beginTransmission(DS1624_ADDRESS);
// SEND READ TEMP COMMAND
Wire.send(0xAA);
// GET THE TEMP MSB AND LSB
Wire.requestFrom(DS1624_ADDRESS, 2);
if (Wire.available()) {
tempmsb = Wire.receive();
}
if (Wire.available()) {
templsb = Wire.receive();
}
temp2 = templsb >> 3;
temperature = (float(tempmsb) + (float(temp2) * 0.03125));
// STOP CONDITION
Wire.endTransmission();
}
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;
// 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;
}
}
void loop()
{
ds1624_readtemp();
Serial.print(" Temperature (deg C): ");
printFloat(temperature , 3);
Serial.println();
delay(1000);
}
|
|
|
02-22-2009, 10:47 PM
|
#2
|
|
Vendor
Feedback Score: 0 reviews
Join Date: Dec 2008
Location: Orange County, CA
Posts: 449
Liked 3 Times on 3 Posts
|
Pretty cool. What package is the chip in? The nice thing about LM34s or DS18B20s is they are in a T092 case and easily fit in a .25 X.028 wall tube.
|
|
|
02-22-2009, 11:06 PM
|
#3
|
|
Feedback Score: 0 reviews
Join Date: Jul 2008
Location: Guelph, ON, CANADA
Posts: 75
|
Hi Derrin,
The DS1624 comes in an 8-pin SOIC (208mil) and 8-pin DIP 9300mil) your choice!
I also have a DS1629 that is also 8pin SOIC that is similar to the DS1624 except it is a real time clock and digital thermometer. I will try to get this one talking on my SMBUS as well tonight. I was planning on putting these inside some tubing sections to make submersible temperature probes, similar to what people have done with the LM34/LM35s.
I am also working on a program for my arduino to control two electric heating elements (4500W), one for BK and one for HLT using the PWM capabilities of the arduino. If my research is correct, the SSRs can be driven directly off the output pins as they can drive up to 40ma. The SSRs I have will accept 3-32vdc input as a trigger!
|
|
|
02-22-2009, 11:15 PM
|
#4
|
|
Feedback Score: 0 reviews
Join Date: Jan 2009
Location: Lincoln Park, MI
Posts: 300
|
Yea, I've been playing around with the DS18B20 for a few weeks now, and they are really amazing. You can get them for about 3-4bux shipped (US), so it's not too bad, at least compared to a dedicated thermometer.
Also networking multiple sensors is awesome!
Edit: If you haven't already, you may want to check out this link: http://groups.homebrewtalk.com/Open_Source_Mash_Computer.
|
|
|
02-23-2009, 01:50 AM
|
#5
|
|
Vendor
Feedback Score: 0 reviews
Join Date: Dec 2008
Location: Orange County, CA
Posts: 449
Liked 3 Times on 3 Posts
|
Quote:
Originally Posted by HomebrewJeff
Yea, I've been playing around with the DS18B20 for a few weeks now, and they are really amazing. You can get them for about 3-4bux shipped (US), so it's not too bad, at least compared to a dedicated thermometer.
Also networking multiple sensors is awesome!
Edit: If you haven't already, you may want to check out this link: HomeBrewTalk Groups - Open Source Mash Computer.
|
I thought that was the one in the SOIC package. Check out the brewtroller group here, they also started a website: BrewTroller
|
|
|
02-23-2009, 02:22 AM
|
#6
|
|
Feedback Score: 0 reviews
Join Date: Jul 2008
Location: Guelph, ON, CANADA
Posts: 75
|
Ok, just finished playing around with the DS1629. The schematics call for a 32khz oscillator but I have found this is only required if you are going to be using the clock functions. The temperature functionality works fine without anything attached to the IC. The only problem with the DS1629 is that it can only output the temperature in 0.5 degrees celsius steps which might not be accurate enough for some people. I think the DS1624 is a better option as it has a higher resolution (0.03125 degrees C).
|
|
|
02-23-2009, 01:49 PM
|
#7
|
|
Why that human mask?
Feedback Score: 0 reviews
Join Date: Jan 2009
Location: Taylorsville, Ut
Posts: 895
Liked 34 Times on 27 Posts Likes Given: 1
|
yeah I've been interested in the group mentioned, I'm going to buy the sanguino, its the same codebase as the arduino but more powerful. The only problem now is they're all out of them at both places that sell them :P At any rate, I'm still getting all my other parts together anyway, so I'll not have all the hardware. I just built my brew stand, its super half assed  I'm not a welder, but I tried and partly succeeded. I'm going to post some pics today sometime. I think real welders and building types will get a good laugh. The important part, though, is that it works 
__________________
~Phil
Fermenting: nada
Kegged: Aramis Pale Ale
Bottled: Nada
Drinking: All of the above :)
|
|
|
12-11-2009, 10:02 AM
|
#8
|
|
Feedback Score: 0 reviews
Join Date: Dec 2009
Location: Mexico
Posts: 1
|
uhhh help anyone?
... got 4 wires going into the ds1624... connected the sda and scl of the ds1624 to the sda and scl of the arduino.. tried spines code and am only reading "0.00"'s on the serial port monitor in arduino environment.
SPINE, where you at dude?
Last edited by wlewis; 12-12-2009 at 08:39 PM.
Reason: correction
|
|
|
12-11-2009, 02:16 PM
|
#9
|
|
Feedback Score: 0 reviews
Join Date: Nov 2009
Location: Missouri
Posts: 73
|
Quote:
Originally Posted by Spine
The only problem with the DS1629 is that it can only output the temperature in 0.5 degrees celsius steps which might not be accurate enough for some people. I think the DS1624 is a better option as it has a higher resolution (0.03125 degrees C).
|
My feeble mind is a bit puzzled. What does resolution mean in relationship to accuracy, and why is it important if the accuracy is the same?
|
|
|
12-12-2009, 02:33 AM
|
#10
|
|
Feedback Score: 0 reviews
Join Date: Mar 2009
Location: Manorville, New York
Posts: 2,730
Liked 20 Times on 18 Posts
|
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
|
|
|