Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit e985d5b

Browse files
author
Adrian McEwen
committed
Spot when pressure sensor has stalled and reset it.
1 parent a1b8b9d commit e985d5b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pysense/lib/MPL3115A2.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ def __init__(self, pysense = None, sda = 'P22', scl = 'P21', mode = PRESSURE):
6969
raise MPL3115A2exception("Error with MPL3115A2")
7070

7171
def _read_status(self):
72-
while True:
72+
read_attempts = 0
73+
while read_attempts < 500:
7374
self.i2c.readfrom_mem_into(MPL3115_I2CADDR, MPL3115_STATUS, self.STA_reg)
75+
read_attempts += 1
7476

7577
if(self.STA_reg[0] == 0):
7678
time.sleep(0.01)
@@ -80,6 +82,11 @@ def _read_status(self):
8082
else:
8183
return False
8284

85+
# If we get here the sensor isn't responding. Reset it so next time in it should work
86+
self.i2c.writeto_mem(MPL3115_I2CADDR, MPL3115_CTRL_REG1, bytes([0x00])) # put into standby
87+
self.i2c.writeto_mem(MPL3115_I2CADDR, MPL3115_CTRL_REG1, bytes([0x04])) # reset
88+
return False
89+
8390
def pressure(self):
8491
if self.mode == ALTITUDE:
8592
raise MPL3115A2exception("Incorrect Measurement Mode MPL3115A2")

0 commit comments

Comments
 (0)