Skip to content

Commit 94ea0f0

Browse files
author
brentru
committed
Adding dht22 example, updating header to include MIT license info
switch pins
1 parent 2969865 commit 94ea0f0

File tree

4 files changed

+122
-18
lines changed

4 files changed

+122
-18
lines changed

examples/basics/analog_output.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
"""
22
`analog_output.py`
3-
-------------------
4-
PWM a LED from
5-
Adafruit IO!
3+
===============================================================================
4+
PWM a LED from Adafruit IO!
65
7-
Requires:
8-
- Adafruit-Blinka
9-
- Adafruit-CircuitPython-PCA9685
6+
Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-analog-output
7+
8+
Adafruit invests time and resources providing this open source code.
9+
Please support Adafruit and open source hardware by purchasing
10+
products from Adafruit!
11+
12+
Author(s): Brent Rubell for Adafruit Industries
13+
Copyright (c) 2018 Adafruit Industries
14+
Licensed under the MIT license.
15+
All text above must be included in any redistribution.
16+
17+
Dependencies:
18+
- Adafruit_Blinka
19+
(https://github.com/adafruit/Adafruit_Blinka)
20+
- Adafruit_CircuitPython_PCA9685
21+
(https://github.com/adafruit/Adafruit_CircuitPython_PCA9685)
1022
"""
23+
1124
# import system libraries
1225
import time
1326

examples/basics/rgb_led.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
"""
22
`rgb_led.py`
3-
------------------------
3+
=======================================================================
44
Control a RGB LED using
55
Adafruit IO and Python
66
7-
Requires:
8-
- Adafruit-Blinka
9-
- Adafruit-CircuitPython-PCA9685
7+
Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-color
8+
9+
Adafruit invests time and resources providing this open source code.
10+
Please support Adafruit and open source hardware by purchasing
11+
products from Adafruit!
12+
13+
Author(s): Brent Rubell for Adafruit Industries
14+
Copyright (c) 2018 Adafruit Industries
15+
Licensed under the MIT license.
16+
All text above must be included in any redistribution.
17+
18+
Dependencies:
19+
- Adafruit_Blinka
20+
(https://github.com/adafruit/Adafruit_Blinka)
21+
- Adafruit_CircuitPython_PCA9685
22+
(https://github.com/adafruit/Adafruit_CircuitPython_PCA9685)
1023
"""
1124
# import system libraries
1225
import time

examples/basics/servo.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
"""
22
`servo.py`
3-
------------------
4-
Control a servo
5-
with Adafruit IO
6-
7-
Requires:
8-
- Adafruit-Blinka
9-
- Adafruit-CircuitPython-PCA9685
10-
- Adafruit-CircuitPython-Motor
3+
========================================================================
4+
5+
Control a servo with Adafruit IO
6+
Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-servo
7+
8+
Adafruit invests time and resources providing this open source code.
9+
Please support Adafruit and open source hardware by purchasing
10+
products from Adafruit!
11+
12+
Author(s): Brent Rubell for Adafruit Industries
13+
Copyright (c) 2018 Adafruit Industries
14+
Licensed under the MIT license.
15+
All text above must be included in any redistribution.
16+
17+
Dependencies:
18+
- Adafruit_Blinka
19+
(https://github.com/adafruit/Adafruit_Blinka)
20+
- Adafruit_CircuitPython_PCA9685
21+
(https://github.com/adafruit/Adafruit_CircuitPython_PCA9685)
22+
- Adafruit_CircuitPython_Motor
23+
(https://github.com/adafruit/Adafruit_CircuitPython_Motor)
1124
"""
25+
1226
# import system libraries
1327
import time
1428

examples/basics/temp_humidity.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
'temp_humidity.py'
3+
==================================
4+
Example of sending analog sensor
5+
values to an Adafruit IO feed.
6+
7+
Author(s): Brent Rubell
8+
9+
Tutorial Link: Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-temperature-and-humidity
10+
11+
Dependencies:
12+
- Adafruit IO Python Client
13+
(https://github.com/adafruit/io-client-python)
14+
- Adafruit_Python_DHT
15+
(https://github.com/adafruit/Adafruit_Python_DHT)
16+
"""
17+
18+
# import standard python modules.
19+
import time
20+
21+
# import adafruit dht library.
22+
import Adafruit_DHT
23+
24+
# import Adafruit IO REST client.
25+
from Adafruit_IO import Client, Feed
26+
27+
# Delay in-between sensor readings, in seconds.
28+
DHT_READ_TIMEOUT = 5
29+
30+
# Pin connected to DHT22 data pin
31+
DHT_DATA_PIN = 26
32+
33+
# Set to your Adafruit IO key.
34+
# Remember, your key is a secret,
35+
# so make sure not to publish it when you publish this code!
36+
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
37+
38+
# Set to your Adafruit IO username.
39+
# (go to https://accounts.adafruit.com to find your username).
40+
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
41+
42+
# Create an instance of the REST client.
43+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
44+
45+
# Set up Adafruit IO Feeds.
46+
temperature_feed = aio.feeds('temperature')
47+
humidity_feed = aio.feeds('humidity')
48+
49+
# Set up DHT22 Sensor.
50+
dht22_sensor = Adafruit_DHT.DHT22
51+
52+
while True:
53+
humidity, temperature = Adafruit_DHT.read_retry(dht22_sensor, DHT_DATA_PIN)
54+
if humidity is not None and temperature is not None:
55+
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
56+
# Send humidity and temperature feeds to Adafruit IO
57+
temperature = '%.2f'%(temperature)
58+
humidity = '%.2f'%(humidity)
59+
aio.send(temperature_feed.key, str(temperature))
60+
aio.send(humidity_feed.key, str(humidity))
61+
else:
62+
print('Failed to get DHT22 Reading, trying again in ', DHT_READ_TIMEOUT, 'seconds')
63+
# Timeout to avoid flooding Adafruit IO
64+
time.sleep(DHT_READ_TIMEOUT)

0 commit comments

Comments
 (0)