Closed GuySawyer closed 10 years ago
The readBytes command requires a command. For your case, i'd just use the ReadByte and read in two bytes. Then, it looks like you just need to do some bit shifting as per the LM75A spec.
var temp = bytes[0] << 8;
newTemp |= bytes[1];
newTemp = newTemp >> 5;
temp = newTemp * 0.125;
Thanks for your quick response.
I started using the readByte function. It worked some of the time, but eventually it ends up pulling the SDA line low, and then failing to read the value anymore.
Any idea what might be causing this?
It's really hard to diagnose hardware issues, but you may want to try a pull-up resistors on the line.
i've digged through the same problem and ended up with:
wire.readBytes(0x00, 2, function(err, data){
console.log(err);
console.log(data);
var tempA = data[0];
var tempB = data[1];
var temp = (tempA << 8) | tempB;
temp = temp >> 5
var signBit = temp >> 10;
var result;
if(signBit > 0){
result = (temp * 0.125) - 256;
} else {
result = temp * 0.125;
}
console.log(result);
});
and it works just fine, shows both positive and negative temps and does readBytes without command - registry with temp according to the LM75A spec, and I read just two bytes. Then some shifting here and there to get thre real value and voila :)
Good day all
I am using the readBytes() function to read two bytes of an LM75A temperature sensor. My code is as follows:
The address is correct, I am sure of that. My problem is with the Command variable. I can't find out from the source code what that variable means, and to my knowledge, the LM75A doesn't require a command variable for reading.
The results I am getting from this code are all over the place. Varying between 2 deg, and 115 deg.
Any advice? Thanks