adafruit / Adafruit_CircuitPython_SCD30

Helper library for the SCD30 e-CO2 sensor
MIT License
15 stars 10 forks source link

Make sure we turn ambient pressure to an int. #7

Closed rpavlik closed 3 years ago

rpavlik commented 3 years ago

I noticed that there was this feature to set the pressure for better results, and since I was using a CLUE, I figured I'd set it on startup. Of course, the BMP280 returns a float, not an int, so I got an error about trying to shift a float. This fixes the error, by turning whatever we're given in the setter of ambient_pressure into an int, so you can just:

# Tell it our ambient pressure on startup for best data
scd.ambient_pressure = clue.pressure
tannewt commented 3 years ago

ping @caternuson

caternuson commented 3 years ago

@tannewt yep. on it. just got one yesterday :)

caternuson commented 3 years ago

@rpavlik What about doing this in user code instead?

scd.ambient_pressure = int(clue.pressure)

This would help reinforce the fact that the setting really is only integer resolution: image

It would also make things more symetric in terms of getting the same value back when you read scd.ambient_pressure.

caternuson commented 3 years ago

Actually, I'm going to be like a politician and flip-flip on this. I'm cool with it. I think the trade off of allowing simpler user code vs. the potential issues of the automagic behavior is minimal.

@rpavlik Want to do something similar for altitude while you're at it?

rpavlik commented 3 years ago

Ah, I hadn't thought of altitude since my thought process was literally "hey, I can have it compensate for pressure, this clue has a bmp280, I shall take the value from bmp280 and apply to scd30". Sure, I can get to that tonight probably.

rpavlik commented 3 years ago

There you go!

rpavlik commented 3 years ago

BTW, we probably want to bump major version soon on this because of the eCO2 -> CO2 rename?

caternuson commented 3 years ago

Looks good. Tested real quick on a MatrixPortal. The parameter is still eCO2 since this PR is based on branch forked without that merged in.

Adafruit CircuitPython 6.1.0 on 2021-01-21; Adafruit Matrix Portal M4 with samd51j19
>>> import board
>>> import adafruit_scd30
>>> scd30 = adafruit_scd30.SCD30(board.I2C())
>>> scd30.eCO2
755.951
>>> scd30.ambient_pressure
0
>>> scd30.ambient_pressure = 1010.5
>>> scd30.ambient_pressure
1010
>>> scd30.altitude
0
>>> scd30.altitude = 300.5
>>> scd30.altitude
300
>>> scd30.eCO2
779.802
>>> 
caternuson commented 3 years ago

BTW, we probably want to bump major version soon on this because of the eCO2 -> CO2 rename?

Yep. Looks like that was done a couple of days ago with the 2.0.0 release: https://github.com/adafruit/Adafruit_CircuitPython_SCD30/releases/tag/2.0.0

rpavlik commented 3 years ago

awesome thanks!