-
Notifications
You must be signed in to change notification settings - Fork 1
IndexError, fixed(?), but now temperature sensor is wrong (< 0) #1
Description
Hi @jposada202020,
First, thanks for making the micropython driver for a DPS310 sensor.
I'm using your driver for a Lolin HP303B sensor (shield), which seems compatibly with the DPS310. I'm a software engineer, so apologies if that is a wrong assumption.
I'm using your simple test example, and got an IndexError in method mode() of class DPS310. After some research on github.com/wemos, I found an Arduino sample with Mode-values. It seems that two values are missing from your "mode_values"(index 3 and 4 in table must be present, although they are invalid).
My changes in module dps310.py:
line 85: added INVAL_OP_CMD_BOTH and INVAL_OP_CONT_NONE
# Source: https://github.com/wemos/LOLIN_HP303B_Library/blob/master/src/LOLIN_HP303B.h -> enum Mode...
IDLE = const(0b000)
ONE_PRESSURE = const(0b001)
ONE_TEMPERATURE = const(0b010)
INVAL_OP_CMD_BOTH = const(0b011) # invalid
INVAL_OP_CONT_NONE = const(0b100) # invalid
CONT_PRESSURE = const(0b101)
CONT_TEMP = const(0b110)
CONT_PRESTEMP = const(0b111)
mode_values = (
IDLE, #0
ONE_PRESSURE, #1
ONE_TEMPERATURE, #2
INVAL_OP_CMD_BOTH, #3 - invalid
INVAL_OP_CONT_NONE, #4 - invalid
CONT_PRESSURE, #5
CONT_TEMP, #6
CONT_PRESTEMP, #7
)
and in method mode() (around line 438):
#DEBUG: print(f"sensor_mode: {self._sensor_mode}") # PP: 7 = 0b111 = CONT_PRESTEMP
values = (
"IDLE",
"ONE_PRESSURE",
"ONE_TEMPERATURE",
"INVAL_OP_CMD_BOTH", # invalid
"INVAL_OP_CONT_NONE", # invalid
"CONT_PRESSURE",
"CONT_TEMP",
"CONT_PRESTEMP",
)
return values[self._sensor_mode]
The IndexError is gone! However, I'll get from the sensor temperature values below zero, while it definitely is above 20 degrees Celsius. The pressure value from the sensor seems correct.
Output sensor (simple test):
Temperature -1.872383°C, Pressure: 990.9458HPa
Room temperature: 22°C.
Could you have a look at it what is the problem and make a fix? I do not know what to do next. I'm willing to test it (with Lolin HP303B sensor).
Kind regards,
Peter