Raymond Genovese
- Joined Mar 5, 2016
- 1,653
Don't have one but I was looking at the data sheet. There are a couple of issues that I can see...try this snippet and if it works, you can clean it up - figure out what mode you want to use, calculate a checksum, mess with the status, add pull up resistors and that kind of thing.
#include <Wire.h>
int address1 = 0x4A; // hex address of sensor 1 with ADDR to GND
void setup() {
Serial.begin(9600);
Wire.begin(); // create a wire object
Wire.beginTransmission(address1); //start the communication with IC with the address xx
Serial.println("begin");
// set up for single shot mode / clock stretching /.5/sec max frequency
Wire.write(byte(0x2C));
Wire.write(byte(0x06));
Wire.endTransmission();
Serial.println("mode set");
//end transmission
}
void loop() {
Serial.println(" wait..");
delay(1000);
// request the 3 bytes of measurement data 16 bit temp value plus checksum
Wire.requestFrom(address1, 3);
byte byte1=Wire.read(); // msb of temp
byte byte2=Wire.read(); // lsb of temp
byte byte3=Wire.read(); // chksum
unsigned short tC= (byte1<<8) + byte2;
float temperatureC= -45 + 175 * (tC/65536-1);
Serial.print("Temperature (C) = ");
Serial.println(temperatureC);
}
edit: 8 not 16 duh?
#include <Wire.h>
int address1 = 0x4A; // hex address of sensor 1 with ADDR to GND
void setup() {
Serial.begin(9600);
Wire.begin(); // create a wire object
Wire.beginTransmission(address1); //start the communication with IC with the address xx
Serial.println("begin");
// set up for single shot mode / clock stretching /.5/sec max frequency
Wire.write(byte(0x2C));
Wire.write(byte(0x06));
Wire.endTransmission();
Serial.println("mode set");
//end transmission
}
void loop() {
Serial.println(" wait..");
delay(1000);
// request the 3 bytes of measurement data 16 bit temp value plus checksum
Wire.requestFrom(address1, 3);
byte byte1=Wire.read(); // msb of temp
byte byte2=Wire.read(); // lsb of temp
byte byte3=Wire.read(); // chksum
unsigned short tC= (byte1<<8) + byte2;
float temperatureC= -45 + 175 * (tC/65536-1);
Serial.print("Temperature (C) = ");
Serial.println(temperatureC);
}
edit: 8 not 16 duh?
Last edited: