Just in case you’re here, here is Dave Eaton’s code from the product comments page.
See CalculusAE’s thread at http://www.arduino.cc/cgi-bin/yabb2/YaB … 1214872633 for a link to a i2cmaster library
I am using a Duemilanove, so I changed the twimaster.c to reflect the 16MHz clock, and changed the bus frequency to 50Khz:
#ifndef F_CPU
#define F_CPU 16000000UL
#endif
/* I2C clock in Hz */
#define SCL_CLOCK 50000L
You make a folder in /{arduino root}/hardware/libraries and copy the
i2cmaster.h and twimaster.c, renaming the .c file to .cpp
Then the Arduio code in subsequent posts works for me:
#include
void setup()
{
Serial.begin(9600);
Serial.println(“Hello!”);
i2c_init(); //Initialise the i2c bus
Serial.println(“Return from i2c_init”);
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop()
{
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);
i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();
//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB
double tempData = 0x0000;
int frac;
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
tempData = tempData - 273.15;
Serial.print((int)tempData); //Print temp in degrees C to serial
Serial.print(“.”);
tempData=tempData-(int)tempData;
frac=tempData*100;
Serial.println(frac);
delay(100);
}
The above is CalculusAE’s code, with a line added to enable the pullups in the Arduino. It spits out a temperature
to the nearest C degree every second. It was a bit of a tooth-pull to get this device to talk, and this code is not
taking advantage of the capabilities of the device, but it does work, which I wanted to prove to myself before
goofing with getting more accuracy. I stripped most of the comments out to get it to post. You really should look
at the code with comments. I think there is a type conversion error that limits the output to integers. I’ll let
y’all know if I figure it out.