i2c thermometer on arduino
I have hooked up my c-control i2c thermometer-module (link in german) to my arduino and wrote some code to read the current temperature in Celcius.
The module uses the maxim DS1631 chip.
The temperature is send as a 2 byte value using a 12 bit resolution. in the MSB the first bit is used as a sign bit, the other seven bits are represent the part before the comma, in the LSB the first 4 bits are used as the fractional part.
the code below doesn't handle negative values yet. i want to use it in my livingroom - i never ever want it to deal with negative values!
include "Wire.h"
#define address 0x4F
#define baudrate 9600
void setup() {
Wire.begin();
Serial.begin(baudrate);
}
void loop(){
Wire.beginTransmission(address);
// send configuration
Wire.send(0xAC);
Wire.send(B00001111); // 12 bit resolution, pol, oneshot
Wire.endTransmission();
delay(10);
// begin convert
Wire.beginTransmission(address);
Wire.send(0x51);
Wire.endTransmission();
delay(10);
// wait until converting is done
byte conf = 0;
while ( conf & B1000000 != B10000000 ) {
delay( 100 );
Wire.beginTransmission(address);
Wire.send(0xAC);
Wire.endTransmission();
conf = Wire.receive();
}
// ask for the temerature
Wire.beginTransmission(address);
Wire.send(0xAA);
Wire.endTransmission();
// request 2 bytes
Wire.requestFrom(address, 2);
// read first byte
int temp = Wire.receive();
// read second byte
int frac = Wire.receive();
Serial.print(temp);
Serial.print( "." );
frac = 100 * (frac & 0xF0 )/ 256;
if ( frac < 10 ) {
Serial.print("0");
}
Serial.println( frac );
delay(1000);
}
See also:
RadioPI hardware part 1
Day 24 of 30DaysOfCreativity - a breadboard arduino
Day 23 of 30DaysOfCreativity - Buttons for the raspbery car radio
processing ical-flowers-2.0
Hi , I used anDS1631Z sensor and Arduino uno V3.0 .After the code loaded ,the temperature showed in terminal was " -1.93"constantly ! I puted the finger on sensor but nothing hepend ! ? Can you help me ? Thank you .
Check the Wireing from SDA and SDC the SDA must connect to the SDA pin on your arduino board and the SDC to the SDC pin