Skip to content
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

Merged
merged 20 commits into from
Nov 6, 2021

Conversation

alankrantas
Copy link
Contributor

@alankrantas alankrantas commented Aug 26, 2021

For #276.

Copy link
Member

@aykevl aykevl left a 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
Comment on lines 32 to 34
// 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 {
Copy link
Member

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
Comment on lines 45 to 53
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)
}
Copy link
Member

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().

Copy link
Contributor Author

@alankrantas alankrantas Sep 5, 2021

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)?

Copy link
Contributor Author

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) {
Copy link
Member

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.

Comment on lines +153 to +160
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]))
Copy link
Member

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.

@deadprogram
Copy link
Member

Hello @alankrantas thanks for working on this. Seems like it could be merged if the commits were squashed and the merge conflict in the Makefile is resolved.

Do you want to do this yourself or would you like me to do this?

Thank you!

@deadprogram deadprogram merged commit cd2694e into tinygo-org:dev Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants