Skip to content

Commit 19caee9

Browse files
conejoninjadeadprogram
authored andcommitted
fixed link to datasheet
fixed temp/humidity values
1 parent c235509 commit 19caee9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

scd4x/scd4x.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Package scd4x provides a driver for the scd4x I2C envrironment sensor.
22
//
3-
// Datasheet: https://sensirion.com/media/documents/C4B87CE6/61652F80/Sensirion_CO2_Sensors_SCD4x_Datasheet.pdf
3+
// Datasheet: https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf
44
//
55
// This driver is heavily influenced by the scd4x code from Adafruit for CircuitPython:
66
// https://github.com/adafruit/Adafruit_CircuitPython_SCD4X
@@ -115,7 +115,8 @@ func (d *Device) ReadTemperature() (temperature int32, err error) {
115115
if ok {
116116
err = d.ReadData()
117117
}
118-
return (-1 * 45) + 175*(int32(d.temperature)/0x100000)*1000, err
118+
// temp = -45 + 175 * value / 2¹⁶
119+
return (-1 * 45000) + (21875 * (int32(d.temperature)) / 8192), err
119120
}
120121

121122
// ReadTempC returns the value in the temperature value in Celsius.
@@ -138,7 +139,8 @@ func (d *Device) ReadHumidity() (humidity int32, err error) {
138139
if ok {
139140
err = d.ReadData()
140141
}
141-
return (100 * int32(d.humidity) / 0x100000), err
142+
// humidity = 100 * value / 2¹⁶
143+
return (25 * int32(d.humidity)) / 16384, err
142144
}
143145

144146
func (d *Device) sendCommand(command uint16) error {

0 commit comments

Comments
 (0)