Skip to content

Commit 4c2e7cf

Browse files
Merge branch 'master' into collin_cunningham_changes
2 parents 26a1d7e + bc3ffd2 commit 4c2e7cf

Some content is hidden

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

45 files changed

+1213
-6157
lines changed

FeatherCAN_CircuitPython/listener-ack.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
boost_enable = digitalio.DigitalInOut(board.BOOST_ENABLE)
1515
boost_enable.switch_to_output(True)
1616

17+
# Use this line if your board has dedicated CAN pins. (Feather M4 CAN and Feather STM32F405)
1718
can = canio.CAN(rx=board.CAN_RX, tx=board.CAN_TX, baudrate=250_000, auto_restart=True)
19+
# On ESP32S2 most pins can be used for CAN. Uncomment the following line to use IO5 and IO6
20+
#can = canio.CAN(rx=board.IO6, tx=board.IO5, baudrate=250_000, auto_restart=True)
1821
listener = can.listen(matches=[canio.Match(0x408)], timeout=.9)
1922

2023
old_bus_state = None

FeatherCAN_CircuitPython/listener.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
boost_enable = digitalio.DigitalInOut(board.BOOST_ENABLE)
1515
boost_enable.switch_to_output(True)
1616

17+
# Use this line if your board has dedicated CAN pins. (Feather M4 CAN and Feather STM32F405)
1718
can = canio.CAN(rx=board.CAN_RX, tx=board.CAN_TX, baudrate=250_000, auto_restart=True)
19+
# On ESP32S2 most pins can be used for CAN. Uncomment the following line to use IO5 and IO6
20+
#can = canio.CAN(rx=board.IO6, tx=board.IO5, baudrate=250_000, auto_restart=True)
1821
listener = can.listen(matches=[canio.Match(0x408)], timeout=.9)
1922

2023
old_bus_state = None

FeatherCAN_CircuitPython/sender-ack.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
boost_enable = digitalio.DigitalInOut(board.BOOST_ENABLE)
1616
boost_enable.switch_to_output(True)
1717

18+
# Use this line if your board has dedicated CAN pins. (Feather M4 CAN and Feather STM32F405)
1819
can = canio.CAN(rx=board.CAN_RX, tx=board.CAN_TX, baudrate=250_000, auto_restart=True)
20+
# On ESP32S2 most pins can be used for CAN. Uncomment the following line to use IO5 and IO6
21+
#can = canio.CAN(rx=board.IO6, tx=board.IO5, baudrate=250_000, auto_restart=True)
1922
listener = can.listen(matches=[canio.Match(0x409)], timeout=.1)
2023

2124
old_bus_state = None

FeatherCAN_CircuitPython/sender.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
boost_enable = digitalio.DigitalInOut(board.BOOST_ENABLE)
1616
boost_enable.switch_to_output(True)
1717

18+
# Use this line if your board has dedicated CAN pins. (Feather M4 CAN and Feather STM32F405)
1819
can = canio.CAN(rx=board.CAN_RX, tx=board.CAN_TX, baudrate=250_000, auto_restart=True)
20+
# On ESP32S2 most pins can be used for CAN. Uncomment the following line to use IO5 and IO6
21+
#can = canio.CAN(rx=board.IO6, tx=board.IO5, baudrate=250_000, auto_restart=True)
1922

2023
old_bus_state = None
2124
count = 0

IoT_NeoPixel_Sign/code.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import ssl
2+
import board
3+
import neopixel
4+
import adafruit_requests
5+
import socketpool
6+
import wifi
7+
from adafruit_io.adafruit_io import IO_HTTP
8+
from adafruit_pixel_framebuf import PixelFramebuffer
9+
# adafruit_circuitpython_adafruitio usage with native wifi networking
10+
11+
# Neopixel matrix configuration
12+
PIXEL_PIN = board.IO6
13+
PIXEL_WIDTH = 12
14+
PIXEL_HEIGHT = 12
15+
16+
# secrets.py has SSID/password and adafruit.io
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
22+
AIO_USERNAME = secrets["aio_username"]
23+
AIO_KEY = secrets["aio_key"]
24+
25+
# LED matrix creation
26+
PIXELS = neopixel.NeoPixel(
27+
PIXEL_PIN, PIXEL_WIDTH * PIXEL_HEIGHT, brightness=0.5, auto_write=False,
28+
)
29+
30+
PIXEL_FRAMEBUF = PixelFramebuffer(
31+
PIXELS,
32+
PIXEL_WIDTH,
33+
PIXEL_HEIGHT,
34+
alternating=True,
35+
rotation=1,
36+
reverse_x=True
37+
)
38+
39+
# Adafruit.io feeds setup
40+
QUOTE_FEED = "sign-quotes.signtext"
41+
COLOR_FEED = "sign-quotes.signcolor"
42+
CURRENT_TEXT = "Merry Christmas!"
43+
CURRENT_COLOR = 0xFFFFFF
44+
45+
# Helper function to get updated data from Adafruit.io
46+
def update_data():
47+
global CURRENT_TEXT, CURRENT_COLOR
48+
print("Updating data from Adafruit IO")
49+
try:
50+
quote_feed = IO.get_feed(QUOTE_FEED)
51+
quotes_data = IO.receive_data(quote_feed["key"])
52+
CURRENT_TEXT = quotes_data["value"]
53+
color_feed = IO.get_feed(COLOR_FEED)
54+
color_data = IO.receive_data(color_feed["key"])
55+
CURRENT_COLOR = int(color_data["value"][1:], 16)
56+
# pylint: disable=broad-except
57+
except Exception as error:
58+
print(error)
59+
60+
61+
# Connect to WiFi
62+
print("Connecting to %s" % secrets["ssid"])
63+
wifi.radio.connect(secrets["ssid"], secrets["password"])
64+
print("Connected to %s!" % secrets["ssid"])
65+
66+
# Setup Adafruit IO connection
67+
POOL = socketpool.SocketPool(wifi.radio)
68+
REQUESTS = adafruit_requests.Session(POOL, ssl.create_default_context())
69+
# Initialize an Adafruit IO HTTP API object
70+
IO = IO_HTTP(AIO_USERNAME, AIO_KEY, REQUESTS)
71+
72+
73+
while True:
74+
update_data()
75+
print("Displaying", CURRENT_TEXT, "in", hex(CURRENT_COLOR))
76+
77+
for i in range(12 * len(CURRENT_TEXT) + PIXEL_WIDTH):
78+
PIXEL_FRAMEBUF.fill(0x000000)
79+
PIXEL_FRAMEBUF.pixel(0, 0, 0x000000)
80+
PIXEL_FRAMEBUF.text(CURRENT_TEXT, PIXEL_WIDTH - i, 3, CURRENT_COLOR)
81+
PIXEL_FRAMEBUF.display()

MagTag_Christmas_Countdown/code.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
from adafruit_display_shapes.circle import Circle
55

66
# create MagTag and connect to network
7-
magtag = MagTag()
8-
magtag.network.connect()
7+
try:
8+
magtag = MagTag()
9+
magtag.network.connect()
10+
except (ConnectionError, ValueError, RuntimeError) as e:
11+
print("*** MagTag(), Some error occured, retrying! -", e)
12+
# Exit program and restart in 1 seconds.
13+
magtag.exit_and_deep_sleep(1)
14+
15+
916

1017
# displayio groups
1118
group = displayio.Group(max_size=30)
@@ -53,11 +60,15 @@
5360

5461
# circles to cover-up bitmap's number ornaments
5562

63+
ball_color = [0x555555, 0xaaaaaa, 0xFFFFFF] # All colors except black (0x000000)
64+
ball_index = 0
65+
5666
# creating the circles & pulling in positions from spots
5767
for spot in spots:
58-
circle = Circle(x0=spot[0], y0=spot[1],
59-
r=11,
60-
fill=0xFF00FF)
68+
circle = Circle(x0=spot[0], y0=spot[1], r=11, fill=ball_color[ball_index]) # Each ball has a color
69+
ball_index += 1
70+
ball_index %= len(ball_color)
71+
6172
# adding circles to their display group
6273
circle_group.append(circle)
6374

@@ -70,7 +81,10 @@
7081
now = time.localtime()
7182
month = now[1]
7283
day = now[2]
73-
print("day is", day)
84+
(hour, minutes, seconds) = now[3:6]
85+
seconds_since_midnight = 60 * (hour*60 + minutes)+seconds
86+
print( f"day is {day}, ({seconds_since_midnight} seconds since midnight)")
87+
7488

7589
# sets colors of circles to transparent to reveal dates that have passed & current date
7690
for i in range(day):
@@ -82,9 +96,11 @@
8296
magtag.display.refresh()
8397
time.sleep(5)
8498

85-
# goes into deep sleep for 12 hours
99+
# goes into deep sleep till a 'stroke' past midnight
86100
print("entering deep sleep")
87-
magtag.exit_and_deep_sleep(43200)
101+
seconds_to_sleep = 24*60*60 - seconds_since_midnight + 10
102+
print( f"sleeping for {seconds_to_sleep} seconds")
103+
magtag.exit_and_deep_sleep(seconds_to_sleep)
88104

89105
# entire code will run again after deep sleep cycle
90106
# similar to hitting the reset button

0 commit comments

Comments
 (0)