Skip to content

Commit 72b8e97

Browse files
committed
Merge remote-tracking branch 'origin/main' into runcpm-metro-rp2350
2 parents 6b9d4d8 + f327f68 commit 72b8e97

File tree

855 files changed

+27384
-5846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

855 files changed

+27384
-5846
lines changed

Adafruit_Feather_ESP32-S2/BME280_LC709203_Adafruit_IO/code.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
CircuitPython Adafruit IO Example for BME280 and LC709203 Sensors
55
"""
6+
7+
from os import getenv
68
import time
79
import ssl
810
import alarm
@@ -14,11 +16,21 @@
1416
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
1517
from adafruit_lc709203f import LC709203F, PackSize
1618
from adafruit_bme280 import basic as adafruit_bme280
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("WiFi and Adafruit IO credentials are kept in secrets.py, please add them there!")
21-
raise
19+
20+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
21+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
22+
ssid = getenv("CIRCUITPY_WIFI_SSID")
23+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
24+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
25+
aio_key = getenv("ADAFRUIT_AIO_KEY")
26+
27+
if None in [ssid, password, aio_username, aio_key]:
28+
raise RuntimeError(
29+
"WiFi and Adafruit IO settings are kept in settings.toml, "
30+
"please add them there. The settings file must contain "
31+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
32+
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
33+
)
2234

2335
# Duration of sleep in seconds. Default is 600 seconds (10 minutes).
2436
# Feather will sleep for this duration between sensor readings / sending data to AdafruitIO
@@ -78,9 +90,9 @@ def send_io_data(feed, value):
7890
# Wi-Fi connections can have issues! This ensures the code will continue to run.
7991
try:
8092
# Connect to Wi-Fi
81-
wifi.radio.connect(secrets["ssid"], secrets["password"])
82-
print("Connected to {}!".format(secrets["ssid"]))
83-
print("IP:", wifi.radio.ipv4_address)
93+
wifi.radio.connect(ssid, password)
94+
print(f"Connected to {ssid}!")
95+
print(f"IP: {wifi.radio.ipv4_address}")
8496

8597
pool = socketpool.SocketPool(wifi.radio)
8698
requests = adafruit_requests.Session(pool, ssl.create_default_context())
@@ -90,12 +102,6 @@ def send_io_data(feed, value):
90102
print(e)
91103
go_to_sleep(60)
92104

93-
# Set your Adafruit IO Username and Key in secrets.py
94-
# (visit io.adafruit.com if you need to create an account,
95-
# or if you need your Adafruit IO key.)
96-
aio_username = secrets["aio_username"]
97-
aio_key = secrets["aio_key"]
98-
99105
# Initialize an Adafruit IO HTTP API object
100106
io = IO_HTTP(aio_username, aio_key, requests)
101107

Adafruit_Feather_ESP32-S2/BME280_LC709203_Simple_Data/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66
import time
77
import board
8-
from adafruit_bme280 import basic as adafruit_bme280
98
from adafruit_lc709203f import LC709203F, PackSize
9+
from adafruit_bme280 import basic as adafruit_bme280
1010

1111
# Create sensor objects, using the board's default I2C bus.
1212
i2c = board.I2C() # uses board.SCL and board.SDA

Adafruit_Feather_TFT_ESP32-S2/LC709203_Adafruit_IO/code.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
CircuitPython Adafruit IO Example for LC709203 Sensor
55
"""
6+
7+
from os import getenv
68
import time
79
import ssl
810
import alarm
@@ -13,11 +15,21 @@
1315
import adafruit_requests
1416
from adafruit_io.adafruit_io import IO_HTTP
1517
from adafruit_lc709203f import LC709203F, PackSize
16-
try:
17-
from secrets import secrets
18-
except ImportError:
19-
print("WiFi and Adafruit IO credentials are kept in secrets.py, please add them there!")
20-
raise
18+
19+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
20+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
21+
ssid = getenv("CIRCUITPY_WIFI_SSID")
22+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
23+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
24+
aio_key = getenv("ADAFRUIT_AIO_KEY")
25+
26+
if None in [ssid, password, aio_username, aio_key]:
27+
raise RuntimeError(
28+
"WiFi and Adafruit IO settings are kept in settings.toml, "
29+
"please add them there. The settings file must contain "
30+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
31+
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
32+
)
2133

2234
# Duration of sleep in seconds. Default is 600 seconds (10 minutes).
2335
# Feather will sleep for this duration between sensor readings / sending data to AdafruitIO
@@ -58,9 +70,9 @@ def send_io_data(feed, value):
5870
# Wi-Fi connections can have issues! This ensures the code will continue to run.
5971
try:
6072
# Connect to Wi-Fi
61-
wifi.radio.connect(secrets["ssid"], secrets["password"])
62-
print("Connected to {}!".format(secrets["ssid"]))
63-
print("IP:", wifi.radio.ipv4_address)
73+
wifi.radio.connect(ssid, password)
74+
print(f"Connected to {ssid}!")
75+
print(f"IP: {wifi.radio.ipv4_address}")
6476

6577
pool = socketpool.SocketPool(wifi.radio)
6678
requests = adafruit_requests.Session(pool, ssl.create_default_context())
@@ -70,12 +82,6 @@ def send_io_data(feed, value):
7082
print(e)
7183
go_to_sleep(60)
7284

73-
# Set your Adafruit IO Username and Key in secrets.py
74-
# (visit io.adafruit.com if you need to create an account,
75-
# or if you need your Adafruit IO key.)
76-
aio_username = secrets["aio_username"]
77-
aio_key = secrets["aio_key"]
78-
7985
# Initialize an Adafruit IO HTTP API object
8086
io = IO_HTTP(aio_username, aio_key, requests)
8187

Adafruit_Feather_TFT_ESP32-S2/TFT_GitHub_Stars/code.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
CircuitPython GitHub Stars viewer
55
"""
6+
7+
from os import getenv
68
import time
79
import ssl
810
import wifi
@@ -13,12 +15,17 @@
1315
from adafruit_bitmap_font import bitmap_font
1416
import adafruit_requests
1517

16-
# Get WiFi details secrets.py file
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("WiFi secrets are kept in secrets.py, please add them there!")
21-
raise
18+
# Get WiFi details, ensure these are setup in settings.toml
19+
ssid = getenv("CIRCUITPY_WIFI_SSID")
20+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
21+
22+
if None in [ssid, password]:
23+
raise RuntimeError(
24+
"WiFi settings are kept in settings.toml, "
25+
"please add them there. The settings file must contain "
26+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
27+
"at a minimum."
28+
)
2229

2330
display = board.DISPLAY
2431

@@ -38,10 +45,10 @@
3845
display.root_group = group
3946

4047
# Connect to WiFi
41-
print("Connecting to %s"%secrets["ssid"])
42-
wifi.radio.connect(secrets["ssid"], secrets["password"])
43-
print("Connected to %s!"%secrets["ssid"])
44-
print("My IP address is", wifi.radio.ipv4_address)
48+
print(f"Connecting to {ssid}")
49+
wifi.radio.connect(ssid, password)
50+
print(f"Connected to {ssid}!")
51+
print(f"My IP address is {wifi.radio.ipv4_address}")
4552

4653
pool = socketpool.SocketPool(wifi.radio)
4754
requests = adafruit_requests.Session(pool, ssl.create_default_context())

Adafruit_IO_Air_Quality/code.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from os import getenv
56
import time
67
import board
78
import busio
@@ -22,14 +23,22 @@
2223
# Interval the sensor publishes to Adafruit IO, in minutes
2324
PUBLISH_INTERVAL = 10
2425

25-
### WiFi ###
26+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
27+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
28+
ssid = getenv("CIRCUITPY_WIFI_SSID")
29+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
30+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
31+
aio_key = getenv("ADAFRUIT_AIO_KEY")
32+
33+
if None in [ssid, password, aio_username, aio_key]:
34+
raise RuntimeError(
35+
"WiFi and Adafruit IO settings are kept in settings.toml, "
36+
"please add them there. The settings file must contain "
37+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
38+
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
39+
)
2640

27-
# Get wifi details and more from a secrets.py file
28-
try:
29-
from secrets import secrets
30-
except ImportError:
31-
print("WiFi secrets are kept in secrets.py, please add them there!")
32-
raise
41+
### WiFi ###
3342

3443
# AirLift FeatherWing
3544
esp32_cs = DigitalInOut(board.D13)
@@ -38,8 +47,8 @@
3847

3948
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
4049
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
41-
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
42-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
50+
status_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
51+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
4352

4453
# Connect to a PM2.5 sensor over UART
4554
reset_pin = None
@@ -142,19 +151,19 @@ def read_bme(is_celsius=False):
142151

143152

144153
# Create an instance of the Adafruit IO HTTP client
145-
io = IO_HTTP(secrets["aio_user"], secrets["aio_key"], wifi)
154+
io = IO_HTTP(aio_username, aio_key, wifi)
146155

147156
# Describes feeds used to hold Adafruit IO data
148157
feed_aqi = io.get_feed("air-quality-sensor.aqi")
149158
feed_aqi_category = io.get_feed("air-quality-sensor.category")
150159
feed_humidity = io.get_feed("air-quality-sensor.humidity")
151160
feed_temperature = io.get_feed("air-quality-sensor.temperature")
152161

153-
# Set up location metadata from secrets.py file
162+
# Set up location metadata from settings.toml file
154163
location_metadata = {
155-
"lat": secrets["latitude"],
156-
"lon": secrets["longitude"],
157-
"ele": secrets["elevation"],
164+
"lat": getenv("latitude"),
165+
"lon": getenv("longitude"),
166+
"ele": getenv("elevation"),
158167
}
159168

160169
elapsed_minutes = 0

Adafruit_IO_Power_Relay/code.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414

1515
import adafruit_minimqtt.adafruit_minimqtt as MQTT
1616

17-
### WiFi ###
17+
# Get WiFi details, ensure these are setup in settings.toml
18+
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
19+
password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
20+
21+
if None in [ssid, password]:
22+
raise RuntimeError(
23+
"WiFi settings are kept in settings.toml, "
24+
"please add them there. The settings file must contain "
25+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
26+
"at a minimum."
27+
)
1828

19-
secrets = {
20-
"ssid" : os.getenv("CIRCUITPY_WIFI_SSID"),
21-
"password" : os.getenv("CIRCUITPY_WIFI_PASSWORD"),
22-
}
29+
### WiFi ###
2330

2431
# If you are using a board with pre-defined ESP32 Pins:
2532
esp32_cs = DigitalInOut(board.ESP_CS)
@@ -34,19 +41,19 @@
3441
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3542
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
3643
"""Use below for Most Boards"""
37-
status_light = neopixel.NeoPixel(
44+
status_pixel = neopixel.NeoPixel(
3845
board.NEOPIXEL, 1, brightness=0.2
3946
) # Uncomment for Most Boards
4047
"""Uncomment below for ItsyBitsy M4"""
41-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
48+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
4249
# Uncomment below for an externally defined RGB LED
4350
# import adafruit_rgbled
4451
# from adafruit_esp32spi import PWMOut
4552
# RED_LED = PWMOut.PWMOut(esp, 26)
4653
# GREEN_LED = PWMOut.PWMOut(esp, 27)
4754
# BLUE_LED = PWMOut.PWMOut(esp, 25)
48-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
49-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
55+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
56+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
5057

5158
# Set up a pin for controlling the relay
5259
power_pin = DigitalInOut(board.D3)

Adafruit_IO_Power_Relay/code_light_sensor/code.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
from os import getenv
56
import time
67
import board
78
import busio
@@ -14,6 +15,21 @@
1415

1516
import adafruit_minimqtt.adafruit_minimqtt as MQTT
1617

18+
# Get WiFi details and Adafruit IO keys, ensure these are setup in settings.toml
19+
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
20+
ssid = getenv("CIRCUITPY_WIFI_SSID")
21+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
22+
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
23+
aio_key = getenv("ADAFRUIT_AIO_KEY")
24+
25+
if None in [ssid, password, aio_username, aio_key]:
26+
raise RuntimeError(
27+
"WiFi and Adafruit IO settings are kept in settings.toml, "
28+
"please add them there. The settings file must contain "
29+
"'CIRCUITPY_WIFI_SSID', 'CIRCUITPY_WIFI_PASSWORD', "
30+
"'ADAFRUIT_AIO_USERNAME' and 'ADAFRUIT_AIO_KEY' at a minimum."
31+
)
32+
1733
### Sensor Calibration ###
1834
# Appliance power LED's light level, in Lux
1935
APPLIANCE_ON_LUX = 30.0
@@ -22,13 +38,6 @@
2238

2339
### WiFi ###
2440

25-
# Get wifi details and more from a secrets.py file
26-
try:
27-
from secrets import secrets
28-
except ImportError:
29-
print("WiFi secrets are kept in secrets.py, please add them there!")
30-
raise
31-
3241
# If you are using a board with pre-defined ESP32 Pins:
3342
esp32_cs = DigitalInOut(board.ESP_CS)
3443
esp32_ready = DigitalInOut(board.ESP_BUSY)
@@ -42,19 +51,19 @@
4251
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
4352
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
4453
"""Use below for Most Boards"""
45-
status_light = neopixel.NeoPixel(
54+
status_pixel = neopixel.NeoPixel(
4655
board.NEOPIXEL, 1, brightness=0.2
4756
) # Uncomment for Most Boards
4857
"""Uncomment below for ItsyBitsy M4"""
49-
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
58+
# status_pixel = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
5059
# Uncomment below for an externally defined RGB LED
5160
# import adafruit_rgbled
5261
# from adafruit_esp32spi import PWMOut
5362
# RED_LED = PWMOut.PWMOut(esp, 26)
5463
# GREEN_LED = PWMOut.PWMOut(esp, 27)
5564
# BLUE_LED = PWMOut.PWMOut(esp, 25)
56-
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
57-
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
65+
# status_pixel = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
66+
wifi = adafruit_esp32spi_wifimanager.WiFiManager(esp, ssid, password, status_pixel=status_pixel)
5867

5968
# Set up a pin for controlling the relay
6069
power_pin = DigitalInOut(board.D3)
@@ -67,10 +76,10 @@
6776

6877
### Feeds ###
6978
# Set up a feed named Relay for subscribing to the relay feed on Adafruit IO
70-
feed_relay = secrets["aio_username"] + "/feeds/relay"
79+
feed_relay = f"{aio_username}/feeds/relay"
7180

7281
# Set up a feed named status for subscribing to the status feed on Adafruit IO
73-
feed_status = secrets["aio_username"] + "/feeds/status"
82+
feed_status = f"{aio_username}/feeds/status"
7483

7584
### Code ###
7685

@@ -122,8 +131,8 @@ def on_relay_msg(client, topic, value):
122131
# Set up a MiniMQTT Client
123132
client = MQTT.MQTT(
124133
broker="io.adafruit.com",
125-
username=secrets["aio_username"],
126-
password=secrets["aio_key"],
134+
username=aio_username,
135+
password=aio_key,
127136
socket_pool=pool,
128137
ssl_context=ssl_context,
129138
)

0 commit comments

Comments
 (0)