Skip to content

Commit b1feebe

Browse files
committed
reading raw humidity data
1 parent b768adc commit b1feebe

File tree

5 files changed

+136
-22
lines changed

5 files changed

+136
-22
lines changed

README.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ This is easily achieved by downloading
3232

3333
Installing from PyPI
3434
=====================
35-
.. note:: This library is not available on PyPI yet. Install documentation is included
36-
as a standard element. Stay tuned for PyPI availability!
37-
38-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
39-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
4035

4136
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4237
PyPI <https://pypi.org/project/adafruit-circuitpython-ms8607/>`_. To install for current user:
@@ -63,7 +58,23 @@ To install in a virtual environment in your current project:
6358
Usage Example
6459
=============
6560

66-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
61+
.. code-block:: python3
62+
63+
import time
64+
import busio
65+
import board
66+
import adafruit_shtc3
67+
68+
i2c = busio.I2C(board.SCL, board.SDA)
69+
sht = adafruit_shtc3.SHTC3(i2c)
70+
71+
while True:
72+
temperature, relative_humidity = sht.measurements
73+
print("Temperature: %0.1f C" % temperature)
74+
print("Humidity: %0.1f %%" % relative_humidity)
75+
print("")
76+
time.sleep(1)
77+
6778
6879
Contributing
6980
============

adafruit_ms8607.py

Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,117 @@
1616
1717
**Hardware:**
1818
19-
.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
20-
inline format: "* `Link Text <url>`_"
19+
* `Adafruit AS7341 Breakout <https://www.adafruit.com/products/45XX>`_
2120
2221
**Software and Dependencies:**
2322
2423
* Adafruit CircuitPython firmware for the supported boards:
2524
https://github.com/adafruit/circuitpython/releases
2625
27-
.. todo:: Uncomment or remove the Bus Device and/or the Register library dependencies based on the library's use of either.
26+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27+
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
2828
29-
# * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
30-
# * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
3129
"""
3230

3331
# imports
3432

3533
__version__ = "0.0.0-auto.0"
3634
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MS8607.git"
35+
36+
37+
from struct import unpack_from
38+
from time import sleep
39+
from micropython import const
40+
import adafruit_bus_device.i2c_device as i2c_device
41+
42+
# // HSENSOR device commands
43+
_MS8607_RESET_COMMAND = const(0xFE) #
44+
_MS8607_READ_HUMIDITY_W_HOLD_COMMAND = const(0xE5) #
45+
_MS8607_READ_HUMIDITY_WO_HOLD_COMMAND = const(0xF5) #
46+
_MS8607_READ_SERIAL_FIRST_8BYTES_COMMAND = const(0xFA0F) #
47+
_MS8607_READ_SERIAL_LAST_6BYTES_COMMAND = const(0xFCC9) #
48+
_MS8607_WRITE_USER_REG_COMMAND = const(0xE6) #
49+
_MS8607_READ_USER_REG_COMMAND = const(0xE7) #
50+
51+
_MS8607_HSENSOR_ADDR = const(0x40) #
52+
53+
# enum MS8607_humidity_resolution
54+
# {
55+
# MS8607_humidity_resolution_12b = 0,
56+
# MS8607_humidity_resolution_8b,
57+
# MS8607_humidity_resolution_10b,
58+
# MS8607_humidity_resolution_11b
59+
# };]
60+
61+
62+
class MS8607Humidity:
63+
"""Library for the MS8607 Humidity Sensor
64+
65+
66+
:param ~busio.I2C i2c_bus: The I2C bus the MS8607 is connected to.
67+
68+
"""
69+
70+
def __init__(self, i2c_bus):
71+
72+
self.i2c_device = i2c_device.I2CDevice(i2c_bus, _MS8607_HSENSOR_ADDR)
73+
74+
# self.reset()
75+
# self.initialize()
76+
self._buffer = bytearray(3)
77+
78+
@property
79+
def relative_humidity(self):
80+
"""The current relative humidity in % rH"""
81+
82+
# self._buffer.clear()
83+
self._buffer[0] = _MS8607_READ_HUMIDITY_WO_HOLD_COMMAND
84+
with self.i2c_device as i2c:
85+
i2c.write(self._buffer, end=1)
86+
sleep(0.1) # _i2cPort->requestFrom((uint8_t)MS8607_HSENSOR_ADDR, 3U);
87+
88+
with self.i2c_device as i2c:
89+
i2c.readinto(self._buffer, end=3)
90+
91+
# _adc = (buffer[0] << 8) | buffer[1];
92+
# crc = buffer[2];
93+
raw_humidity = unpack_from(">H", self._buffer)
94+
95+
# *humidity =
96+
# adc * HUMIDITY_COEFF_MUL / (1UL << 16) + HUMIDITY_COEFF_ADD;
97+
return raw_humidity
98+
# // compute CRC
99+
# uint8_t crc;
100+
# status = hsensor_crc_check(_adc, crc);
101+
# if (status != MS8607_status_ok)
102+
# return status;
103+
104+
# *adc = _adc;
105+
106+
# return status;
107+
108+
109+
# read_temperature_pressure_humidity(float *t, float *p,
110+
111+
# set_humidity_resolution(enum MS8607_humidity_resolution res);
112+
# void set_humidity_i2c_master_mode(enum MS8607_humidity_i2c_master_mode mode);
113+
114+
# get_compensated_humidity(float temperature, float relative_humidity, float *compensated_humidity);
115+
116+
# /*
117+
# private:
118+
# bool hsensor_is_connected(void);
119+
# hsensor_reset(void);
120+
# hsensor_crc_check(uint16_t value, uint8_t crc);
121+
# hsensor_read_user_register(uint8_t *value);
122+
# hsensor_write_user_register(uint8_t value);
123+
# enum MS8607_humidity_i2c_master_mode hsensor_i2c_master_mode;
124+
# hsensor_humidity_conversion_and_read_adc(uint16_t *adc);
125+
# hsensor_read_relative_humidity(float *humidity);
126+
# int err = set_humidity_resolution(MS8607_humidity_resolution_12b); // 12 bits
127+
# hsensor_conversion_time = HSENSOR_CONVERSION_TIME_12b;
128+
# hsensor_i2c_master_mode = MS8607_i2c_no_hold;
129+
# float humidity = getHumidity();
130+
# float temperature = getTemperature();
131+
# float compensated_RH= get_compensated_humidity(temperature, humidity, &compensated_RH);
132+
# float dew_point = get_dew_point(temperature, humidity, &dew_point);

docs/index.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
2826

2927
.. toctree::
3028
:caption: Related Products
3129

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
30+
* `Adafruit MS8607 Breakout <https://www.adafruit.com/products/45XX>`_
3431

3532
.. toctree::
3633
:caption: Other Links

examples/ms8607_simpletest.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
2-
#
3-
# SPDX-License-Identifier: Unlicense
1+
# SPDX-FileCopyrightText: 2020 Bryan Siepert, written for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
from time import sleep
4+
import board
5+
import busio
6+
from adafruit_ms8607 import MS8607Humidity
7+
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
sensor = MS8607Humidity(i2c)
10+
11+
while True:
12+
13+
print("%.2f %% rH" % sensor.relative_humidity)
14+
print("\n------------------------------------------------")
15+
sleep(1)

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
# Author details
3535
author="Adafruit Industries",
3636
author_email="[email protected]",
37-
install_requires=[
38-
"Adafruit-Blinka",
39-
],
37+
install_requires=["Adafruit-Blinka",],
4038
# Choose your license
4139
license="MIT",
4240
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
@@ -52,7 +50,7 @@
5250
],
5351
# What does your project relate to?
5452
keywords="adafruit blinka circuitpython micropython ms8607 pressure humidity temperature "
55-
"sensor",
53+
"sensor",
5654
# You can just specify the packages manually here if your project is
5755
# simple. Or you can use find_packages().
5856
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,

0 commit comments

Comments
 (0)