-
Notifications
You must be signed in to change notification settings - Fork 201
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
Add support for HTS221 capacitive digital sensor for relative humidity and temperature #295
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good to me, just a few comments.
hts221/hts221.go
Outdated
// For Nano 33 BLE Sense, use machine.P0_15 (SCL1) and machine.P0_14 (SDA1), | ||
// and set onNano33BLE as hts221.ON_NANO_33_BLE. | ||
func New(bus drivers.I2C, deviceType uint8) Device { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use the nano_33_ble
build tag for this. I think that's a lot simpler to use.
hts221/hts221.go
Outdated
if d.OnNano33BLE { | ||
ENV := machine.Pin(22) | ||
ENV.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
ENV.High() | ||
R := machine.Pin(32) | ||
R.Configure(machine.PinConfig{Mode: machine.PinOutput}) | ||
R.High() | ||
time.Sleep(time.Millisecond * 10) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in the configuration step. A user is not required to call .Connected()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trouble is that without pull high these pins first, the I2C bus simply hangs.
Would it be ok if I put it in New()
(and I create two versions of them using build tags)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, just updated (including other drivers for Nano 33 BLE).
|
||
// ReadPressure returns the relative humidity in percent * 1000. | ||
// Returns an error if the device is not turned on. | ||
func (d *Device) ReadHumidity() (humidity int32, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BME280 driver has the same interface but returns humidity in percent * 100. I think it would be better to match that API.
Also, the comment says ReadPressure
, it should be ReadHumidity
.
h0rH_v := float32(h0rH[0]) / 2.0 | ||
h1rH_v := float32(h1rH[0]) / 2.0 | ||
t0degC_v := float32(readUint(t1t0msb[0]&0x03, t0degC[0])) / 8.0 | ||
t1degC_v := float32(readUint(t1t0msb[0]&0x0C>>2, t1degC[0])) / 8.0 | ||
h0t0Out_v := float32(readInt(h0t0Out[1], h0t0Out[0])) | ||
h1t0Out_v := float32(readInt(h1t0Out[1], h1t0Out[0])) | ||
t0Out_v := float32(readInt(t0Out[1], t0Out[0])) | ||
t1Out_v := float32(readInt(t1Out[1], t1Out[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is usually better to only use integers, because floating point can be slow. However, in this case it doesn't matter much I think.
Hello @alankrantas thanks for working on this. Seems like it could be merged if the commits were squashed and the merge conflict in the Do you want to do this yourself or would you like me to do this? Thank you! |
For #276.