Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jposada202020 committed Jun 30, 2023
1 parent 2f8a764 commit c0838fe
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class-rgx=[A-Z_][a-zA-Z0-9_]+$
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
docstring-min-length=-1
function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_,cs
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_,cs,c1,c2,c3,c4,c5,c6,D1,D2,TEMP,dT,T2,OFF2,SENS2,OFF,P,SENS
include-naming-hint=no
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
Expand Down
2 changes: 1 addition & 1 deletion examples/ms5611_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
print(f"Temperature: {temp:.2f}C")
print(f"Pressure: {press:.2f}KPa")
print()
time.sleep(2)
time.sleep(2)
5 changes: 4 additions & 1 deletion examples/ms5611_temperature_oversample_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

while True:
for temperature_oversample_rate in ms5611.temperature_oversample_rate_values:
print("Current Temperature oversample rate setting: ", ms.temperature_oversample_rate)
print(
"Current Temperature oversample rate setting: ",
ms.temperature_oversample_rate,
)
for _ in range(5):
temp, press = ms.measurements
print(f"Temperature: {temp:.2f}C")
Expand Down
65 changes: 54 additions & 11 deletions micropython_ms5611/ms5611.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
from micropython import const
from micropython_ms5611.i2c_helpers import CBits, RegisterStruct

try:
from typing import Tuple
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/jposada202020/MicroPython_MS5611.git"
Expand All @@ -39,16 +43,41 @@
TEMP_OSR_1024 = const(2)
TEMP_OSR_2048 = const(3)
TEMP_OSR_4096 = const(4)
temperature_oversample_rate_values = (TEMP_OSR_256, TEMP_OSR_512, TEMP_OSR_1024, TEMP_OSR_2048, TEMP_OSR_4096)
temp_command_values = {TEMP_OSR_256: 0x50, TEMP_OSR_512: 0x52, TEMP_OSR_1024: 0x54, TEMP_OSR_2048: 0x56, TEMP_OSR_4096: 0x58}
temperature_oversample_rate_values = (
TEMP_OSR_256,
TEMP_OSR_512,
TEMP_OSR_1024,
TEMP_OSR_2048,
TEMP_OSR_4096,
)
temp_command_values = {
TEMP_OSR_256: 0x50,
TEMP_OSR_512: 0x52,
TEMP_OSR_1024: 0x54,
TEMP_OSR_2048: 0x56,
TEMP_OSR_4096: 0x58,
}

PRESS_OSR_256 = const(0)
PRESS_OSR_512 = const(1)
PRESS_OSR_1024 = const(2)
PRESS_OSR_2048 = const(3)
PRESS_OSR_4096 = const(4)
pressure_oversample_rate_values = (PRESS_OSR_256, PRESS_OSR_512, PRESS_OSR_1024, PRESS_OSR_2048, PRESS_OSR_4096)
pressure_command_values = {PRESS_OSR_256: 0x40, PRESS_OSR_512: 0x42, PRESS_OSR_1024: 0x44, PRESS_OSR_2048: 0x46, PRESS_OSR_4096: 0x48}
pressure_oversample_rate_values = (
PRESS_OSR_256,
PRESS_OSR_512,
PRESS_OSR_1024,
PRESS_OSR_2048,
PRESS_OSR_4096,
)
pressure_command_values = {
PRESS_OSR_256: 0x40,
PRESS_OSR_512: 0x42,
PRESS_OSR_1024: 0x44,
PRESS_OSR_2048: 0x46,
PRESS_OSR_4096: 0x48,
}


class MS5611:
"""Driver for the MS5611 Sensor connected over I2C.
Expand Down Expand Up @@ -128,18 +157,18 @@ def measurements(self) -> Tuple[float, float]:

if TEMP < 2000:
T2 = dT * dT / 2**31.0
OFF2 = 5 * (TEMP - 2000)**2.0 / 2
OFF2 = 5 * (TEMP - 2000) ** 2.0 / 2
SENS2 = 5 * (TEMP - 2000) / 4
if TEMP < -1500:
OFF2 = OFF2 + 7 * (TEMP + 1500)**2.0
OFF2 = OFF2 + 7 * (TEMP + 1500) ** 2.0
SENS2 = SENS2 + 11 * (TEMP + 1500) / 2
TEMP = TEMP - T2
OFF = OFF - OFF2
SENS = SENS - SENS2

P = (SENS * D1 / 2**21.0 - OFF) / 2**15.0

return TEMP/100, P/1000
return TEMP / 100, P / 1000

@property
def temperature_oversample_rate(self) -> str:
Expand All @@ -160,13 +189,21 @@ def temperature_oversample_rate(self) -> str:
| :py:const:`ms5611.TEMP_OSR_4096` | :py:const:`4` |
+----------------------------------+---------------+
"""
values = ("TEMP_OSR_256", "TEMP_OSR_512", "TEMP_OSR_1024", "TEMP_OSR_2048", "TEMP_OSR_4096")
values = (
"TEMP_OSR_256",
"TEMP_OSR_512",
"TEMP_OSR_1024",
"TEMP_OSR_2048",
"TEMP_OSR_4096",
)
return values[self._temperature_oversample_rate]

@temperature_oversample_rate.setter
def temperature_oversample_rate(self, value: int) -> None:
if value not in temperature_oversample_rate_values:
raise ValueError("Value must be a valid temperature_oversample_rate setting")
raise ValueError(
"Value must be a valid temperature_oversample_rate setting"
)
self._temperature_oversample_rate = value
self._temp_command = temp_command_values[value]

Expand All @@ -189,12 +226,18 @@ def pressure_oversample_rate(self) -> str:
| :py:const:`ms5611.PRESS_OSR_4096` | :py:const:`4` |
+-----------------------------------+---------------+
"""
values = ("PRESS_OSR_256", "PRESS_OSR_512", "PRESS_OSR_1024", "PRESS_OSR_2048", "PRESS_OSR_4096")
values = (
"PRESS_OSR_256",
"PRESS_OSR_512",
"PRESS_OSR_1024",
"PRESS_OSR_2048",
"PRESS_OSR_4096",
)
return values[self._pressure_oversample_rate]

@pressure_oversample_rate.setter
def pressure_oversample_rate(self, value: int) -> None:
if value not in pressure_oversample_rate_values:
raise ValueError("Value must be a valid pressure_oversample_rate setting")
self._pressure_oversample_rate = value
self._pressure_command = pressure_command_values[value]
self._pressure_command = pressure_command_values[value]

0 comments on commit c0838fe

Please sign in to comment.