Skip to content

Commit ebd17be

Browse files
authored
Merge branch 'master' into master
2 parents f378202 + ea5f5f5 commit ebd17be

File tree

17 files changed

+616
-14
lines changed

17 files changed

+616
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Hue_Controller/secrets.h
44
*.DS_Store
55
CircuitPython_Logger/secrets\.py
66
.python-version
7+
__pycache__

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ confidence=
5252
# no Warning level messages displayed, use"--disable=all --enable=classes
5353
# --disable=W"
5454
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
55-
disable=too-many-instance-attributes,len-as-condition,too-few-public-methods,anomalous-backslash-in-string,no-else-return,simplifiable-if-statement,too-many-arguments,duplicate-code,no-name-in-module,no-member,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,missing-docstring,invalid-name,bad-whitespace,consider-using-enumerate
55+
disable=too-many-instance-attributes,len-as-condition,too-few-public-methods,anomalous-backslash-in-string,no-else-return,simplifiable-if-statement,too-many-arguments,duplicate-code,no-name-in-module,no-member,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,missing-docstring,invalid-name,bad-whitespace,consider-using-enumerate,unexpected-keyword-arg
5656

5757
# Enable the message, report, category or checker with the given id(s). You can
5858
# either give multiple identifier separated by comma (,) or put this option

PaperCraft_Gems/code.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
Crystal Gem Light Strand Project By Erin St Blaine for Adafruit Industries
3+
https://learn.adafruit.com/no-solder-papercraft-crystal-light-strand
4+
5+
Circuit Playground Bluetooth with LED strand attached runs 4 different variable animation modes.
6+
7+
Code by Roy Hooper using Adafruit's LED Animation Library:
8+
https://learn.adafruit.com/circuitpython-led-animations/overview
9+
"""
10+
# pylint: disable=attribute-defined-outside-init
11+
12+
#Import libraries
13+
import board
14+
import neopixel
15+
from adafruit_circuitplayground import cp
16+
from adafruit_led_animation.animation.solid import Solid
17+
from adafruit_led_animation.animation import Animation
18+
from adafruit_led_animation.animation.rainbow import Rainbow
19+
from adafruit_led_animation.animation.sparkle import Sparkle
20+
from adafruit_led_animation.sequence import AnimationSequence
21+
from adafruit_led_animation.color import WHITE, colorwheel
22+
23+
speeds = (0.25, 0.125, 0.1, 0.08, 0.05, 0.02, 0.01) # Customize speed levels here
24+
# periods = (7, 6, 5, 4, 3, 2, 1)
25+
26+
class RainbowFade(Animation):
27+
28+
_color_index = 0
29+
def __init__(self, pixel_object, speed, name):
30+
super().__init__(pixel_object, speed=speed, color=WHITE, name=name)
31+
32+
def draw(self):
33+
self.color = colorwheel(self._color_index)
34+
self._color_index = (self._color_index + 1) % 256
35+
self.fill(self.color)
36+
37+
38+
current_speed = 4
39+
40+
# Set your number of pixels here
41+
pixel_num = 20
42+
43+
pixel_pin = board.A1
44+
pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=1, auto_write=False)
45+
46+
# Animation Setup
47+
48+
rainbow = Rainbow(pixels, speed=speeds[current_speed], period=2, name="rainbow", step=3)
49+
sparkle = Sparkle(pixels, speed=speeds[current_speed], color=WHITE, name="sparkle")
50+
rainbowfade = RainbowFade(pixels, speed=speeds[current_speed], name="rainbowfade")
51+
solid = Solid(pixels, color=colorwheel(0), name="solid")
52+
53+
# Animation Sequence Playlist -- rearrange to change the order of animations
54+
55+
animations = AnimationSequence(
56+
rainbow,
57+
rainbowfade,
58+
solid,
59+
sparkle,
60+
auto_clear=True,
61+
auto_reset=True,
62+
)
63+
64+
solid.speed = 0.01
65+
solid_color = 0
66+
67+
while True:
68+
if cp.switch: # if slide switch is in the "on" position, run animations
69+
animations.animate() #play animation sequence
70+
if cp.button_a:
71+
animations.next()
72+
while cp.button_a:
73+
continue
74+
75+
if cp.button_b:
76+
if animations.current_animation.name == "solid":
77+
solid_color = (solid_color + 8) % 256
78+
animations.current_animation.color = colorwheel(solid_color)
79+
else:
80+
current_speed += 1
81+
if current_speed >= len(speeds):
82+
current_speed = 0
83+
rainbow.speed = speeds[current_speed]
84+
sparkle.speed = speeds[current_speed]
85+
rainbowfade.speed = speeds[current_speed]
86+
print(speeds[current_speed])
87+
while cp.button_b:
88+
continue
89+
else: # If slide switch is in the "off" position, set pixels to black
90+
pixels.fill(0)
91+
pixels.show()

PyPortal_Azure_Plant_Monitor/azure_gfx_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
data_font = cwd+"/fonts/Collegiate-50.bdf"
1414

1515
class Azure_GFX(displayio.Group):
16-
def __init__(self, is_celsius=True):
16+
def __init__(self, is_celsius):
1717
"""Creates an Azure_GFX object.
1818
:param bool is_celsius: Temperature displayed in Celsius.
1919
"""
@@ -76,9 +76,9 @@ def __init__(self, is_celsius=True):
7676
self.azure_status_text.y = 225
7777
self._text_group.append(self.azure_status_text)
7878

79+
def show_text(self):
7980
board.DISPLAY.show(self._text_group)
8081

81-
8282
def display_azure_status(self, status_text):
8383
"""Displays the system status on the PyPortal
8484
:param str status_text: Description of Azure IoT status

PyPortal_Azure_Plant_Monitor/code.py

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
"""
22
PyPortal Azure IoT Plant Monitor
33
====================================================
4-
Log plant vitals to Microsoft Azure IoT with
4+
Log plant vitals to Microsoft Azure IoT Central with
55
your PyPortal
66
7-
Author: Brent Rubell for Adafruit Industries, 2019
7+
Authors: Brent Rubell for Adafruit Industries, 2019
8+
: Jim Bennett for Microsoft, 2020
89
"""
910
import time
11+
import json
1012
import board
1113
import busio
1214
from digitalio import DigitalInOut
1315
from adafruit_esp32spi import adafruit_esp32spi, adafruit_esp32spi_wifimanager
16+
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
1417
import neopixel
15-
from adafruit_azureiot import IOT_Hub
18+
from adafruit_ntp import NTP
19+
from adafruit_azureiot import IoTCentralDevice
1620
from adafruit_seesaw.seesaw import Seesaw
1721

1822
# gfx helper
1923
import azure_gfx_helper
2024

25+
# init. graphics helper
26+
gfx = azure_gfx_helper.Azure_GFX(is_celsius=True)
27+
2128
# Get wifi details and more from a secrets.py file
2229
try:
2330
from secrets import secrets
@@ -31,18 +38,39 @@
3138
esp32_reset = DigitalInOut(board.ESP_RESET)
3239
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3340
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
41+
42+
# Set up the WiFi manager with a status light to show the WiFi connection status
3443
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
3544
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
45+
print("WiFi connecting...")
46+
wifi.connect()
47+
print("WiFi connected!")
48+
49+
# Time setup, needed to authenticate with Azure IoT Central
50+
ntp = NTP(esp)
51+
while not ntp.valid_time:
52+
print("Failed to obtain time, retrying in 5 seconds...")
53+
time.sleep(5)
54+
ntp.set_time()
3655

3756
# Soil Sensor Setup
3857
i2c_bus = busio.I2C(board.SCL, board.SDA)
3958
ss = Seesaw(i2c_bus, addr=0x36)
4059

41-
# Create an instance of the Azure IoT Hub
42-
hub = IOT_Hub(wifi, secrets['azure_iot_hub'], secrets['azure_iot_sas'], secrets['azure_device_id'])
60+
# Create an instance of the Azure IoT Central device
61+
device = IoTCentralDevice(
62+
socket,
63+
esp,
64+
secrets["id_scope"],
65+
secrets["device_id"],
66+
secrets["key"]
67+
)
4368

44-
# init. graphics helper
45-
gfx = azure_gfx_helper.Azure_GFX(False)
69+
# Connect to Azure IoT Central
70+
device.connect()
71+
72+
# Hide the splash screen and show the telemetry values
73+
gfx.show_text()
4674

4775
while True:
4876
try:
@@ -52,15 +80,27 @@
5280
temperature = ss.get_temp()
5381
# display soil sensor values on pyportal
5482
gfx.display_moisture(moisture_level)
55-
temperature = gfx.display_temp(temperature)
83+
gfx.display_temp(temperature)
84+
5685
print('Sending data to Azure')
5786
gfx.display_azure_status('Sending data...')
58-
hub.send_device_message(temperature)
59-
hub.send_device_message(moisture_level)
87+
88+
# send the temperature and moisture level to Azure
89+
message = {
90+
"Temperature": temperature,
91+
"MoistureLevel": moisture_level
92+
}
93+
device.send_telemetry(json.dumps(message))
94+
device.loop()
95+
6096
gfx.display_azure_status('Data sent!')
6197
print('Data sent!')
6298
except (ValueError, RuntimeError) as e:
6399
print("Failed to get data, retrying\n", e)
64100
wifi.reset()
101+
wifi.connect()
102+
device.reconnect()
65103
continue
66-
time.sleep(60)
104+
105+
# Sleep for 10 minutes before getting the next value
106+
time.sleep(600)

PyPortal_Azure_Plant_Monitor/images/azure_splash.bmp

100755100644
-149 KB
Binary file not shown.
2.7 MB
Binary file not shown.
529 KB
Binary file not shown.
6.05 KB
Binary file not shown.
6.05 KB
Binary file not shown.

0 commit comments

Comments
 (0)