Skip to content

Commit 2920893

Browse files
authored
Merge pull request #16 from RetiredWizard/main
Update examples to work with settings.toml
2 parents b806b4d + 21c611e commit 2920893

9 files changed

+325
-103
lines changed

examples/dash_display_advancedtest.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import time
55
import ssl
6+
from os import getenv
67
import displayio
78
import board
89
from digitalio import DigitalInOut, Direction, Pull
@@ -30,11 +31,24 @@
3031
back = touchio.TouchIn(board.CAP7)
3132
submit = touchio.TouchIn(board.CAP8)
3233

33-
try:
34-
from secrets import secrets
35-
except ImportError:
36-
print("WiFi secrets are kept in secrets.py, please add them there!")
37-
raise
34+
# Get wifi details and more from a settings.toml file
35+
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
36+
# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY
37+
secrets = {}
38+
for token in ["SSID", "PASSWORD"]:
39+
if getenv("CIRCUITPY_WIFI_" + token):
40+
secrets[token.lower()] = getenv("CIRCUITPY_WIFI_" + token)
41+
for token in ["AIO_USERNAME", "AIO_KEY"]:
42+
if getenv("CIRCUITPY_" + token):
43+
secrets[token.lower()] = getenv("CIRCUITPY_" + token)
44+
45+
if not secrets:
46+
try:
47+
# Fallback on secrets.py until depreciation is over and option is removed
48+
from secrets import secrets
49+
except ImportError:
50+
print("WiFi secrets are kept in settings.toml, please add them there!")
51+
raise
3852

3953
rgb_group = displayio.Group()
4054
R_label = Label(
@@ -171,7 +185,7 @@ def pub_lamp(lamp):
171185

172186
display = board.DISPLAY
173187

174-
# Set your Adafruit IO Username and Key in secrets.py
188+
# Set your Adafruit IO Username and Key in settings.toml
175189
# (visit io.adafruit.com if you need to create an account,
176190
# or if you need your Adafruit IO key.)
177191
aio_username = secrets["aio_username"]

examples/dash_display_client_examples/battery_daughter.py

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

44
import time
5+
from os import getenv
56
import board
67
from adafruit_lc709203f import LC709203F
78
import busio
@@ -22,25 +23,54 @@
2223

2324
### WiFi ###
2425

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-
26+
# Get wifi details and more from a settings.toml file
27+
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
28+
# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY
29+
secrets = {}
30+
for token in ["SSID", "PASSWORD"]:
31+
if getenv("CIRCUITPY_WIFI_" + token):
32+
secrets[token.lower()] = getenv("CIRCUITPY_WIFI_" + token)
33+
for token in ["AIO_USERNAME", "AIO_KEY"]:
34+
if getenv("CIRCUITPY_" + token):
35+
secrets[token.lower()] = getenv("CIRCUITPY_" + token)
36+
37+
if not secrets:
38+
try:
39+
# Fallback on secrets.py until depreciation is over and option is removed
40+
from secrets import secrets
41+
except ImportError:
42+
print("WiFi secrets are kept in settings.toml, please add them there!")
43+
raise
3244

3345
# If you are using a board with pre-defined ESP32 Pins:
34-
esp32_cs = DigitalInOut(board.D13)
35-
esp32_ready = DigitalInOut(board.D11)
36-
esp32_reset = DigitalInOut(board.D12)
37-
38-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
46+
esp32_cs = DigitalInOut(board.ESP_CS)
47+
esp32_ready = DigitalInOut(board.ESP_BUSY)
48+
esp32_reset = DigitalInOut(board.ESP_RESET)
49+
50+
# If you have an externally connected ESP32:
51+
# esp32_cs = DigitalInOut(board.D13)
52+
# esp32_ready = DigitalInOut(board.D11)
53+
# esp32_reset = DigitalInOut(board.D12)
54+
55+
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
56+
if "SCK1" in dir(board):
57+
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
58+
else:
59+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3960
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
61+
4062
"""Use below for Most Boards"""
41-
status_light = neopixel.NeoPixel(
42-
board.NEOPIXEL, 1, brightness=0.2
43-
) # Uncomment for Most Boards
63+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
64+
"""Uncomment below for ItsyBitsy M4"""
65+
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
66+
"""Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)"""
67+
# import adafruit_rgbled
68+
# from adafruit_esp32spi import PWMOut
69+
# RED_LED = PWMOut.PWMOut(esp, 26)
70+
# GREEN_LED = PWMOut.PWMOut(esp, 27)
71+
# BLUE_LED = PWMOut.PWMOut(esp, 25)
72+
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
73+
4474
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
4575

4676

@@ -74,7 +104,6 @@ def message(client, feed_id, payload):
74104
password=secrets["aio_key"],
75105
)
76106

77-
78107
# Initialize an Adafruit IO MQTT Client
79108
io = IO_MQTT(mqtt_client)
80109

@@ -105,7 +134,6 @@ def message(client, feed_id, payload):
105134
alarm_label = label.Label(terminalio.FONT, text="Voltage: ", color=0xFFFFFF, x=4, y=14)
106135
splash.append(alarm_label)
107136

108-
109137
sensor = LC709203F(board.I2C())
110138

111139
start = 0

examples/dash_display_client_examples/door_daughter.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import board
56
import busio
67
from adafruit_esp32spi import adafruit_esp32spi
@@ -14,29 +15,59 @@
1415

1516
### WiFi ###
1617

17-
# Get wifi details and more from a secrets.py file
18-
try:
19-
from secrets import secrets
20-
except ImportError:
21-
print("WiFi secrets are kept in secrets.py, please add them there!")
22-
raise
18+
# Get wifi details and more from a settings.toml file
19+
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
20+
# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY
21+
secrets = {}
22+
for token in ["SSID", "PASSWORD"]:
23+
if getenv("CIRCUITPY_WIFI_" + token):
24+
secrets[token.lower()] = getenv("CIRCUITPY_WIFI_" + token)
25+
for token in ["AIO_USERNAME", "AIO_KEY"]:
26+
if getenv("CIRCUITPY_" + token):
27+
secrets[token.lower()] = getenv("CIRCUITPY_" + token)
28+
29+
if not secrets:
30+
try:
31+
# Fallback on secrets.py until depreciation is over and option is removed
32+
from secrets import secrets
33+
except ImportError:
34+
print("WiFi secrets are kept in settings.toml, please add them there!")
35+
raise
2336

2437
switch_pin = DigitalInOut(board.D10)
2538
switch_pin.direction = Direction.INPUT
2639
switch_pin.pull = Pull.UP
2740
switch = Debouncer(switch_pin)
2841

2942
# If you are using a board with pre-defined ESP32 Pins:
30-
esp32_cs = DigitalInOut(board.D13)
31-
esp32_ready = DigitalInOut(board.D11)
32-
esp32_reset = DigitalInOut(board.D12)
43+
esp32_cs = DigitalInOut(board.ESP_CS)
44+
esp32_ready = DigitalInOut(board.ESP_BUSY)
45+
esp32_reset = DigitalInOut(board.ESP_RESET)
46+
47+
# If you have an externally connected ESP32:
48+
# esp32_cs = DigitalInOut(board.D13)
49+
# esp32_ready = DigitalInOut(board.D11)
50+
# esp32_reset = DigitalInOut(board.D12)
3351

34-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
52+
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
53+
if "SCK1" in dir(board):
54+
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
55+
else:
56+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3557
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
58+
3659
"""Use below for Most Boards"""
37-
status_light = neopixel.NeoPixel(
38-
board.NEOPIXEL, 1, brightness=0.2
39-
) # Uncomment for Most Boards
60+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
61+
"""Uncomment below for ItsyBitsy M4"""
62+
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
63+
"""Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)"""
64+
# import adafruit_rgbled
65+
# from adafruit_esp32spi import PWMOut
66+
# RED_LED = PWMOut.PWMOut(esp, 26)
67+
# GREEN_LED = PWMOut.PWMOut(esp, 27)
68+
# BLUE_LED = PWMOut.PWMOut(esp, 25)
69+
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
70+
4071
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
4172

4273
# Connect to WiFi

examples/dash_display_client_examples/neopixel_daughter.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 Eva Herrada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from os import getenv
45
import board
56
import busio
67
from adafruit_esp32spi import adafruit_esp32spi
@@ -13,26 +14,56 @@
1314

1415
### WiFi ###
1516

16-
# Get wifi details and more from a 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
17+
# Get wifi details and more from a settings.toml file
18+
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
19+
# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY
20+
secrets = {}
21+
for token in ["SSID", "PASSWORD"]:
22+
if getenv("CIRCUITPY_WIFI_" + token):
23+
secrets[token.lower()] = getenv("CIRCUITPY_WIFI_" + token)
24+
for token in ["AIO_USERNAME", "AIO_KEY"]:
25+
if getenv("CIRCUITPY_" + token):
26+
secrets[token.lower()] = getenv("CIRCUITPY_" + token)
27+
28+
if not secrets:
29+
try:
30+
# Fallback on secrets.py until depreciation is over and option is removed
31+
from secrets import secrets
32+
except ImportError:
33+
print("WiFi secrets are kept in settings.toml, please add them there!")
34+
raise
2235

2336
pixels = neopixel.NeoPixel(board.D5, 300)
2437

2538
# If you are using a board with pre-defined ESP32 Pins:
26-
esp32_cs = DigitalInOut(board.D13)
27-
esp32_ready = DigitalInOut(board.D11)
28-
esp32_reset = DigitalInOut(board.D12)
29-
30-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
39+
esp32_cs = DigitalInOut(board.ESP_CS)
40+
esp32_ready = DigitalInOut(board.ESP_BUSY)
41+
esp32_reset = DigitalInOut(board.ESP_RESET)
42+
43+
# If you have an externally connected ESP32:
44+
# esp32_cs = DigitalInOut(board.D13)
45+
# esp32_ready = DigitalInOut(board.D11)
46+
# esp32_reset = DigitalInOut(board.D12)
47+
48+
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
49+
if "SCK1" in dir(board):
50+
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
51+
else:
52+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
3153
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
54+
3255
"""Use below for Most Boards"""
33-
status_light = neopixel.NeoPixel(
34-
board.NEOPIXEL, 1, brightness=0.2
35-
) # Uncomment for Most Boards
56+
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
57+
"""Uncomment below for ItsyBitsy M4"""
58+
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
59+
"""Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)"""
60+
# import adafruit_rgbled
61+
# from adafruit_esp32spi import PWMOut
62+
# RED_LED = PWMOut.PWMOut(esp, 26)
63+
# GREEN_LED = PWMOut.PWMOut(esp, 27)
64+
# BLUE_LED = PWMOut.PWMOut(esp, 25)
65+
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
66+
3667
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
3768

3869

@@ -71,7 +102,6 @@ def on_neopixel(client, topic, message):
71102
password=secrets["aio_key"],
72103
)
73104

74-
75105
# Initialize an Adafruit IO MQTT Client
76106
io = IO_MQTT(mqtt_client)
77107

examples/dash_display_client_examples/neopixel_setter_daughter.py

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import time
55
import math
6+
from os import getenv
67
import board
78
import busio
89
from digitalio import DigitalInOut
@@ -92,23 +93,51 @@
9293
group.append(rect)
9394
print(len(group))
9495

95-
# Get wifi details and more from a secrets.py file
96-
try:
97-
from secrets import secrets
98-
except ImportError:
99-
print("WiFi secrets are kept in secrets.py, please add them there!")
100-
raise
96+
# Get wifi details and more from a settings.toml file
97+
# tokens used by this Demo: CIRCUITPY_WIFI_SSID, CIRCUITPY_WIFI_PASSWORD
98+
# CIRCUITPY_AIO_USERNAME, CIRCUITPY_AIO_KEY
99+
secrets = {}
100+
for token in ["SSID", "PASSWORD"]:
101+
if getenv("CIRCUITPY_WIFI_" + token):
102+
secrets[token.lower()] = getenv("CIRCUITPY_WIFI_" + token)
103+
for token in ["AIO_USERNAME", "AIO_KEY"]:
104+
if getenv("CIRCUITPY_" + token):
105+
secrets[token.lower()] = getenv("CIRCUITPY_" + token)
106+
107+
if not secrets:
108+
try:
109+
# Fallback on secrets.py until depreciation is over and option is removed
110+
from secrets import secrets
111+
except ImportError:
112+
print("WiFi secrets are kept in settings.toml, please add them there!")
113+
raise
101114

102115
# PyPortal ESP32 Setup
103116
esp32_cs = DigitalInOut(board.ESP_CS)
104117
esp32_ready = DigitalInOut(board.ESP_BUSY)
105118
esp32_reset = DigitalInOut(board.ESP_RESET)
106-
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
119+
# Secondary (SCK1) SPI used to connect to WiFi board on Arduino Nano Connect RP2040
120+
if "SCK1" in dir(board):
121+
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
122+
else:
123+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
107124
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
125+
126+
"""Use below for Most Boards"""
108127
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
128+
"""Uncomment below for ItsyBitsy M4"""
129+
# status_light = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
130+
"""Uncomment below for an externally defined RGB LED (including Arduino Nano Connect)"""
131+
# import adafruit_rgbled
132+
# from adafruit_esp32spi import PWMOut
133+
# RED_LED = PWMOut.PWMOut(esp, 26)
134+
# GREEN_LED = PWMOut.PWMOut(esp, 27)
135+
# BLUE_LED = PWMOut.PWMOut(esp, 25)
136+
# status_light = adafruit_rgbled.RGBLED(RED_LED, BLUE_LED, GREEN_LED)
137+
109138
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)
110139

111-
# Set your Adafruit IO Username and Key in secrets.py
140+
# Set your Adafruit IO Username and Key in settings.toml
112141
# (visit io.adafruit.com if you need to create an account,
113142
# or if you need your Adafruit IO key.)
114143
ADAFRUIT_IO_USER = secrets["aio_username"]

0 commit comments

Comments
 (0)