Skip to content

Commit 78e14cc

Browse files
committed
Integrated Temp/Humidity/Pressure in peripherals
1 parent 44908f3 commit 78e14cc

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

adafruit_funhouse/network.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def init_mqtt(
104104
# pylint: enable=too-many-arguments
105105

106106
def _get_mqtt_client(self):
107-
print(self._mqtt_client)
108107
if self._mqtt_client is not None:
109108
return self._mqtt_client
110109
raise RuntimeError("Please initialize MQTT before using")

adafruit_funhouse/peripherals.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
from analogio import AnalogIn
3333
import touchio
3434
import simpleio
35+
import adafruit_dps310
36+
import adafruit_ahtx0
3537
import adafruit_dotstar
3638

3739
__version__ = "0.0.0-auto.0"
@@ -74,6 +76,10 @@ def __init__(self):
7476
cap = touchio.TouchIn(pin)
7577
self._ctp.append(cap)
7678

79+
self.i2c = board.I2C()
80+
self._dps310 = adafruit_dps310.DPS310(self.i2c)
81+
self._aht20 = adafruit_ahtx0.AHTx0(self.i2c)
82+
7783
# LED
7884
self._led = DigitalInOut(board.LED)
7985
self._led.direction = Direction.OUTPUT
@@ -203,6 +209,27 @@ def light(self):
203209
"""
204210
return self._light.value
205211

212+
@property
213+
def temperature(self):
214+
"""
215+
Return the temperature
216+
"""
217+
return self._aht20.temperature
218+
219+
@property
220+
def relative_humidity(self):
221+
"""
222+
Return the relative humidity
223+
"""
224+
return self._aht20.relative_humidity
225+
226+
@property
227+
def pressure(self):
228+
"""
229+
Return the temperature
230+
"""
231+
return self._dps310.pressure
232+
206233
@property
207234
def led(self):
208235
"""

examples/funhouse_adafruit_io_mqtt.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@
33
#
44
# SPDX-License-Identifier: MIT
55
import time
6-
import board
7-
import adafruit_dps310
8-
import adafruit_ahtx0
96
from adafruit_funhouse import FunHouse
107

11-
i2c = board.I2C()
12-
dps310 = adafruit_dps310.DPS310(i2c)
13-
aht20 = adafruit_ahtx0.AHTx0(i2c)
14-
158
funhouse = FunHouse(default_bg=None)
169
funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080)
1710

@@ -58,16 +51,18 @@ def message(client, feed_id, payload):
5851
while True:
5952
funhouse.network.mqtt_loop()
6053

61-
print("Temp %0.1F" % dps310.temperature)
62-
print("Pres %d" % dps310.pressure)
54+
print("Temp %0.1F" % funhouse.peripherals.temperature)
55+
print("Pres %d" % funhouse.peripherals.pressure)
6356

6457
# every 10 seconds, write temp/hum/press
6558
if (time.monotonic() - sensorwrite_timestamp) > 10:
6659
funhouse.peripherals.led = True
6760
print("Sending data to adafruit IO!")
68-
funhouse.network.mqtt_publish("temperature", dps310.temperature)
69-
funhouse.network.mqtt_publish("humidity", int(aht20.relative_humidity))
70-
funhouse.network.mqtt_publish("pressure", int(dps310.pressure))
61+
funhouse.network.mqtt_publish("temperature", funhouse.peripherals.temperature)
62+
funhouse.network.mqtt_publish(
63+
"humidity", int(funhouse.peripherals.relative_humidity)
64+
)
65+
funhouse.network.mqtt_publish("pressure", int(funhouse.peripherals.pressure))
7166
sensorwrite_timestamp = time.monotonic()
7267
# Send PIR only if changed!
7368
if last_pir is None or last_pir != funhouse.peripherals.pir_sensor:

examples/funhouse_simpletest.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
# SPDX-License-Identifier: Unlicense
55
import board
66
from digitalio import DigitalInOut, Direction, Pull
7-
import adafruit_dps310
8-
import adafruit_ahtx0
97
from adafruit_funhouse import FunHouse
108

119
funhouse = FunHouse(
1210
default_bg=0x0F0F00,
1311
scale=2,
1412
)
1513

16-
i2c = board.I2C()
17-
dps310 = adafruit_dps310.DPS310(i2c)
18-
aht20 = adafruit_ahtx0.AHTx0(i2c)
19-
2014
funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080)
2115

2216
# sensor setup
@@ -71,10 +65,10 @@ def set_label_color(conditional, index, on_color):
7165
funhouse.display.show(funhouse.splash)
7266

7367
while True:
74-
funhouse.set_text("Temp %0.1F" % dps310.temperature, temp_label)
75-
funhouse.set_text("Pres %d" % dps310.pressure, pres_label)
68+
funhouse.set_text("Temp %0.1F" % funhouse.peripherals.temperature, temp_label)
69+
funhouse.set_text("Pres %d" % funhouse.peripherals.pressure, pres_label)
7670

77-
print(aht20.temperature, aht20.relative_humidity)
71+
print(funhouse.peripherals.temperature, funhouse.peripherals.relative_humidity)
7872
set_label_color(funhouse.peripherals.captouch6, onoff_label, 0x00FF00)
7973
set_label_color(funhouse.peripherals.captouch7, capleft_label, 0x00FF00)
8074
set_label_color(funhouse.peripherals.captouch8, capright_label, 0x00FF00)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ adafruit-circuitpython-dotstar
1010
adafruit-circuitpython-requests
1111
adafruit-circuitpython-simpleio
1212
adafruit-circuitpython-minimqtt
13+
adafruit-circuitpython-dps310
14+
adafruit-circuitpython-ahtx0

0 commit comments

Comments
 (0)