Skip to content

Commit d9cb958

Browse files
Include simple example programme demonstrating basic periodic data acquisition usage.
1 parent e08e521 commit d9cb958

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

README.rst

+11-6
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@ And then you can start measuring the temperature and humidity:
6363
print(sensor.temperature)
6464
print(sensor.relative_humidity)
6565
66-
You can instruct the sensor to start periodically measuring the temperature
67-
and humidity at a set interval and retrieve the stored measurements:
66+
You can instruct the sensor to periodically measure the temperature and
67+
humidity, storing the result in its internal cache:
6868

6969
.. code:: python
7070
7171
sensor.mode = 'Periodic'
72-
print(sensor.temperature)
73-
print(sensor.relative_humidity)
7472
7573
You can adjust the frequency at which the sensor periodically gathers data to:
7674
0.5, 1, 2, 4 or 10 Hz. The following adjusts the frequency to 2 Hz:
@@ -79,9 +77,16 @@ You can adjust the frequency at which the sensor periodically gathers data to:
7977
8078
sensor.frequency = 2
8179
82-
8380
The sensor is capable of storing eight results. The sensor stores these
84-
results in an internal FILO cache.
81+
results in an internal FILO cache. Retrieving these results is simlilar to
82+
taking a measurement. The sensor clears its cache once the stored data is read.
83+
The sensor always returns eight data points. The list of results is backfilled
84+
with the maximum output values of 130.0 ºC and 100.01831417975366 % RH:
85+
86+
.. code:: python
87+
88+
print(sensor.temperature)
89+
print(sensor.relative_humidity)
8590
8691
The sensor will continue to collect data at the set interval until it is
8792
returned to single shot data acquisition mode:

examples/sht31d_periodictest.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/python3
2+
import time
3+
import board
4+
import busio
5+
import adafruit_sht31d
6+
7+
# Create library object using our Bus I2C port
8+
i2c = busio.I2C(board.SCL, board.SDA)
9+
sensor = adafruit_sht31d.SHT31D(i2c)
10+
11+
print('\033[1mSensor\033[0m = SHT31-D')
12+
print('\033[1mSerial Number\033[0m = ', sensor.serial_number, '\n')
13+
sensor.frequency = 1
14+
sensor.mode = 'Periodic'
15+
for i in range(3):
16+
if i == 2:
17+
sensor.heater = True
18+
if i == 1:
19+
time.sleep(4)
20+
print('\033[91mCache half full.\033[0m')
21+
else:
22+
time.sleep(8)
23+
if sensor.heater:
24+
print('\033[1mHeater:\033[0m On')
25+
sensor.heater = False
26+
print('\033[1mTemperature:\033[0m ', sensor.temperature)
27+
if not sensor.heater:
28+
print('\033[1mHeater:\033[0m Off')
29+
print('\033[1mHumidity:\033[0m ', sensor.relative_humidity, '\n')
30+
sensor.mode = 'Single'

0 commit comments

Comments
 (0)