Skip to content

Instantly share code, notes, and snippets.

@aleksmk
Created May 2, 2012 22:23
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aleksmk/2580992 to your computer and use it in GitHub Desktop.
Save aleksmk/2580992 to your computer and use it in GitHub Desktop.
Simple arduino reader for the DS1621 I2C temperature sensor
#include <Wire.h>
#define DEV_ID 0x90 >> 1 // shift required by wire.h
void setup()
{
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(DEV_ID); // connect to DS1621 (#0)
Wire.send(0xAC); // Access Config
Wire.send(0x02); // set for continuous conversion
Wire.beginTransmission(DEV_ID); // restart
Wire.send(0xEE); // start conversions
Wire.endTransmission();
}
void loop()
{
int8_t firstByte;
int8_t secondByte;
float temp = 0;
delay(1000); // give time for measurement
Wire.beginTransmission(DEV_ID);
Wire.send(0xAA); // read temperature command
Wire.endTransmission();
Wire.requestFrom(DEV_ID, 2); // request two bytes from DS1621 (0.5 deg. resolution)
firstByte = Wire.receive(); // get first byte
secondByte = Wire.receive(); // get second byte
temp = firstByte;
if (secondByte) // if there is a 0.5 deg difference
temp += 0.5;
Serial.println(temp);
}
@AndKe
Copy link

AndKe commented Dec 10, 2013

thanks, all I get is
.....
sketch_dec10b:12: error: ‘class TwoWire’ has no member named ‘send’
.....
sketch_dec10b:34: error: ‘class TwoWire’ has no member named ‘receive’

@ecadmaster
Copy link

change "send" by "write", and "receive" by "read"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment