-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTU21D humidity measurements are sometimes incorrect #1278
Comments
I can make a PR for fixing this if it's seen as a bug. |
@fivdi Thanks for making a thorough issue. It makes sense to change the humidity to an unsigned integer since the value should never be negative. I don't believe that is an issue for temperature values, according to Adafruit's HTU21D description:
So there is the possibility for negative values from that component.
Since it appears that is an issue with the |
I'm very curious why that first bit is changing in the i2cRead. Doesn't that imply there is a bug somewhere in the firmata/firmata.js chain? |
The conversion of the raw 16 bit value to a Celsius is performed with this code: return toFixed((175.72 * raw / 65536) - 46.85, 2); If
The first bit isn't being changed by i2cRead or firmata/firmata.js. The test was performed on a C.H.I.P. using the C.H.I.P IO plugin where firmata/firmata.js doesn't play a role. The error is occuring because two unsigned bytes that were read using i2cRead are being incorrectly converted to a signed 16 bit integer here. They should be converted to an unsigned 16 bit integer. |
Sorry I have firmata on the brain, specifically various number types in the protocol. Makes sense now. |
A similar test with temperature shows that there's a similar problem. Here's the test program: var five = require("johnny-five");
var chipio = require('chip-io');
var board = new five.Board({io: new chipio()});
board.on("ready", function() {
var thermometer = new five.Thermometer({
controller: "HTU21D",
bus: 1
});
thermometer.on("change", function() {
console.log(this.celsius + "°C", this.fahrenheit + "°F");
});
}); And here's the output when the temperature constantly increases:
Changing this line of code from: computed.temperature = int16(data[0], data[1]); to: computed.temperature = uint16(data[0], data[1]); fixes it. |
Thanks for confirming @fivdi. Can you create a PR with those fixes and updated tests? |
Same bug with SHT31D and SI7021 (#1282) |
#1296 is a PR for fixing this issue. |
If humidity is measured using a HTU21D connected to a C.H.I.P. and humidity increases above approximately 56% Johnny-Five starts to report negative humidity values.
For example, let's say that humidity values are displayed with the following program:
Here's some typical output of this program when the humidity increases:
This appears to be an issue with signed/unsigned values. This line of code converts the raw humidity data from the sensor to a signed 16 bit value:
Modifying this code to convert the raw humidity data to an unsigned 16 bit value fixes the issue:
It looks like the same issue also exists for temperature values.
The text was updated successfully, but these errors were encountered: