Skip to content

Commit

Permalink
Include simple example programme demonstrating basic periodic data ac…
Browse files Browse the repository at this point in the history
…quisition usage.
  • Loading branch information
WoefulDerelict committed Aug 2, 2019
1 parent e08e521 commit d9cb958
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,12 @@ And then you can start measuring the temperature and humidity:
print(sensor.temperature)
print(sensor.relative_humidity)
You can instruct the sensor to start periodically measuring the temperature
and humidity at a set interval and retrieve the stored measurements:
You can instruct the sensor to periodically measure the temperature and
humidity, storing the result in its internal cache:

.. code:: python
sensor.mode = 'Periodic'
print(sensor.temperature)
print(sensor.relative_humidity)
You can adjust the frequency at which the sensor periodically gathers data to:
0.5, 1, 2, 4 or 10 Hz. The following adjusts the frequency to 2 Hz:
Expand All @@ -79,9 +77,16 @@ You can adjust the frequency at which the sensor periodically gathers data to:
sensor.frequency = 2
The sensor is capable of storing eight results. The sensor stores these
results in an internal FILO cache.
results in an internal FILO cache. Retrieving these results is simlilar to
taking a measurement. The sensor clears its cache once the stored data is read.
The sensor always returns eight data points. The list of results is backfilled
with the maximum output values of 130.0 ºC and 100.01831417975366 % RH:

.. code:: python
print(sensor.temperature)
print(sensor.relative_humidity)
The sensor will continue to collect data at the set interval until it is
returned to single shot data acquisition mode:
Expand Down
30 changes: 30 additions & 0 deletions examples/sht31d_periodictest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python3
import time
import board
import busio
import adafruit_sht31d

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_sht31d.SHT31D(i2c)

print('\033[1mSensor\033[0m = SHT31-D')
print('\033[1mSerial Number\033[0m = ', sensor.serial_number, '\n')
sensor.frequency = 1
sensor.mode = 'Periodic'
for i in range(3):
if i == 2:
sensor.heater = True
if i == 1:
time.sleep(4)
print('\033[91mCache half full.\033[0m')
else:
time.sleep(8)
if sensor.heater:
print('\033[1mHeater:\033[0m On')
sensor.heater = False
print('\033[1mTemperature:\033[0m ', sensor.temperature)
if not sensor.heater:
print('\033[1mHeater:\033[0m Off')
print('\033[1mHumidity:\033[0m ', sensor.relative_humidity, '\n')
sensor.mode = 'Single'

0 comments on commit d9cb958

Please sign in to comment.