-
Notifications
You must be signed in to change notification settings - Fork 2
/
adafruit.py
64 lines (58 loc) · 1.93 KB
/
adafruit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#M5Atom matrix scroll text example using matrix.py library
#Reads data from adafruit.io using REST API.
#Feed from adafruit.io who you want to read without APIKEY
#must be set as PUBLIC in feed settings.
#That mean that anyone can read it, but cannot write to it.
import urequests
import matrix
import time
import json
import urandom
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
#REPLACE YOUR ACCES POINT CREDENTIALS BELOW
sta_if.connect("YOUR_ACCES_POINT_NAME", "AP_PASSWORD")
def read(delay=100):
#creating aliasses
r = urandom.randint
m = matrix.matrix
#init matrix
m.init()
m.clear_all()
#setting adafruit.io access data
USER_NAME = 'robalstona'
FEED_NAME = 'feed02'
#access to adafruit.io feed via REST API
#read humidity value from feed
response = urequests.get('https://io.adafruit.com/api/v2/' + USER_NAME + '/feeds/' + FEED_NAME)
#decode json response from adafruit.io
output = json.loads((response.text))
#reads a needed field from response
feed_value = output['last_value']
#set random color of text
m.pixel_color( r(0,360) )
text = 'humidity = ' + feed_value + ' %rh'
#print value
print(text)
#scroll values on matrix
m.text_scroll(text, delay)
#setting adafruit.io access data
USER_NAME = 'robalstona'
FEED_NAME = 'feed01'
#access to adafruit.io feed via REST API
#read temperature value from feed
response = urequests.get('https://io.adafruit.com/api/v2/' + USER_NAME + '/feeds/' + FEED_NAME)
#decode json response from adafruit.io
output = json.loads((response.text))
#reads a needed field from response
feed_value = output['last_value']
#set random color of text
m.pixel_color( r(0,360) )
#create celsius symbol character
celsius = chr(176)
text = 'temperature = ' + feed_value + ' ' + celsius + 'C'
#print value
print(text)
#scroll values on matrix
m.text_scroll(text, delay)