Skip to content

Commit 5b275b1

Browse files
authored
Merge branch 'adafruit:main' into master
2 parents 1759da7 + 50f62d2 commit 5b275b1

82 files changed

Lines changed: 16695 additions & 8 deletions

File tree

Some content is hidden

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

.github/workflows/githubci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
arduino-platform: ["uno", "nrf52832", "cpx_ada", "pyportal", "protrinket_3v", "protrinket_5v", "metro_m0", "esp8266", "esp32", "trinket_3v", "trinket_5v", "gemma", "flora", "feather32u4", "feather_m0_express", "gemma_m0", "trinket_m0", "hallowing_m0", "monster_m4sk", "hallowing_m4", "neotrellis_m4", "pybadge", "cpb", "cpc", "funhouse", "magtag"]
10+
arduino-platform: ["uno", "nrf52832", "cpx_ada", "pyportal", "protrinket_3v", "protrinket_5v", "metro_m0", "esp8266", "esp32", "trinket_3v", "trinket_5v", "gemma", "flora", "feather32u4", "feather_m0_express", "gemma_m0", "trinket_m0", "hallowing_m0", "monster_m4sk", "hallowing_m4", "hallowing_m4_tinyusb", "neotrellis_m4", "pybadge", "cpb", "cpc", "funhouse", "magtag"]
1111

1212
runs-on: ubuntu-18.04
1313

.github/workflows/images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- cron: '0 10 * * *'
66
workflow_dispatch:
77
push:
8-
branches: [master]
8+
branches: [main]
99

1010
concurrency:
1111
group: folder-images
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import time
2+
import board
3+
from digitalio import DigitalInOut, Direction
4+
5+
# LED setup for onboard LED
6+
led = DigitalInOut(board.LED)
7+
led.direction = Direction.OUTPUT
8+
9+
while True:
10+
11+
led.value = True
12+
print("led on")
13+
time.sleep(1)
14+
15+
led.value = False
16+
print("led off")
17+
time.sleep(1)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import time
2+
import board
3+
from digitalio import DigitalInOut, Direction, Pull
4+
5+
# LED setup for onboard LED
6+
led = DigitalInOut(board.LED)
7+
led.direction = Direction.OUTPUT
8+
9+
# button setup
10+
switch = DigitalInOut(board.D4)
11+
switch.direction = Direction.INPUT
12+
switch.pull = Pull.UP
13+
14+
# variable for number count
15+
n = 0
16+
17+
while True:
18+
19+
# when switch is NOT pressed...
20+
if switch.value:
21+
# LED is off
22+
led.value = False
23+
# when switch is pressed...
24+
else:
25+
# LED is on
26+
led.value = True
27+
# value of n increases by 1
28+
n += 1
29+
# n is printed to the REPL
30+
print("led ON %i" % n)
31+
# delay
32+
time.sleep(0.01)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'''Adapted from the example code DM_Mic_Sound_Level_Plot.py
2+
https://github.com/adafruit/Adafruit_Learning_System_Guides/
3+
blob/master/PDM_Microphone/PDM_Mic_Sound_Level_Plot.py '''
4+
5+
import time
6+
import array
7+
import math
8+
import board
9+
import audiobusio
10+
import pwmio
11+
import simpleio
12+
13+
# LED setup
14+
led = pwmio.PWMOut(board.A1, frequency=5000, duty_cycle=0)
15+
16+
# Remove DC bias before computing RMS.
17+
def mean(values):
18+
return sum(values) / len(values)
19+
20+
def normalized_rms(values):
21+
minbuf = int(mean(values))
22+
samples_sum = sum(
23+
float(sample - minbuf) * (sample - minbuf)
24+
for sample in values
25+
)
26+
27+
return math.sqrt(samples_sum / len(values))
28+
29+
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK,
30+
board.MICROPHONE_DATA, sample_rate=16000, bit_depth=16)
31+
samples = array.array('H', [0] * 160)
32+
33+
while True:
34+
35+
mic.record(samples, len(samples))
36+
magnitude = normalized_rms(samples)
37+
print((magnitude,))
38+
39+
# mapping mic's level to LED PWM range
40+
mapped_value = simpleio.map_range(magnitude, 75 , 300, 0, 65535)
41+
42+
# sending mapped value to LED for PWM
43+
led.duty_cycle = int(mapped_value)
44+
# optional logging for mapped_value
45+
# print((mapped_value,))
46+
time.sleep(0.01)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
'''Adapted from the Adafruit_CircuitPython_ESP32SPI
2+
library example esp32spi_simpletest.py:
3+
https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/
4+
blob/master/examples/esp32spi_simpletest.py '''
5+
6+
import board
7+
import busio
8+
from digitalio import DigitalInOut
9+
import adafruit_requests as requests
10+
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
11+
from adafruit_esp32spi import adafruit_esp32spi
12+
13+
# Get wifi details and more from a secrets.py file
14+
try:
15+
from secrets import secrets
16+
except ImportError:
17+
print("WiFi secrets are kept in secrets.py, please add them there!")
18+
raise
19+
20+
print("Arduino Nano RP2040 Connect webclient test")
21+
22+
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
23+
24+
# ESP32 pins
25+
esp32_cs = DigitalInOut(board.CS1)
26+
esp32_ready = DigitalInOut(board.ESP_BUSY)
27+
esp32_reset = DigitalInOut(board.ESP_RESET)
28+
29+
# uses the secondary SPI connected through the ESP32
30+
spi = busio.SPI(board.SCK1, board.MOSI1, board.MISO1)
31+
32+
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
33+
34+
requests.set_socket(socket, esp)
35+
36+
if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
37+
print("ESP32 found and in idle mode")
38+
print("Firmware vers.", esp.firmware_version)
39+
print("MAC addr:", [hex(i) for i in esp.MAC_address])
40+
41+
for ap in esp.scan_networks():
42+
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
43+
44+
print("Connecting to AP...")
45+
while not esp.is_connected:
46+
try:
47+
esp.connect_AP(secrets["ssid"], secrets["password"])
48+
except RuntimeError as e:
49+
print("could not connect to AP, retrying: ", e)
50+
continue
51+
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
52+
print("My IP address is", esp.pretty_ip(esp.ip_address))
53+
54+
print(
55+
"IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
56+
)
57+
58+
print("Fetching text from", TEXT_URL)
59+
r = requests.get(TEXT_URL)
60+
print("-" * 40)
61+
print(r.text)
62+
print("-" * 40)
63+
r.close()
64+
65+
print("Done!")

Astrophotography_Tracker/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
microsteps = 64 # Microstepping resolution
1111
total_steps = steps * microsteps # Total microsteps per revolution
1212

13-
wait = 1/ ((gear_ratio * total_steps) / 86400)
13+
wait = 1/ ((gear_ratio * total_steps) / 86164.1)
1414

1515
step = digitalio.DigitalInOut(board.D6)
1616
direct = digitalio.DigitalInOut(board.D5)
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# SPDX-FileCopyrightText: 2021 Dylan Herrada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
# General imports
5+
import time
6+
import random
7+
import board
8+
import digitalio
9+
import neopixel
10+
11+
# HID imports
12+
from adafruit_hid.keyboard import Keyboard
13+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
14+
15+
# BLE imports
16+
import adafruit_ble
17+
from adafruit_ble.advertising import Advertisement
18+
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
19+
from adafruit_ble.services.standard.hid import HIDService
20+
from adafruit_ble.services.standard.device_info import DeviceInfoService
21+
22+
try:
23+
from audiocore import WaveFile
24+
except ImportError:
25+
from audioio import WaveFile
26+
27+
try:
28+
from audioio import AudioOut
29+
except ImportError:
30+
try:
31+
from audiopwmio import PWMAudioOut as AudioOut
32+
except ImportError:
33+
pass # not always supported by every board!
34+
35+
# Enable the speaker
36+
spkrenable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
37+
spkrenable.direction = digitalio.Direction.OUTPUT
38+
spkrenable.value = True
39+
40+
41+
# Make the input buttons
42+
btn1 = digitalio.DigitalInOut(board.D10) # Marked A3
43+
btn1.direction = digitalio.Direction.INPUT
44+
btn1.pull = digitalio.Pull.UP
45+
46+
btn2 = digitalio.DigitalInOut(board.D9) # Marked A2
47+
btn2.direction = digitalio.Direction.INPUT
48+
btn2.pull = digitalio.Pull.UP
49+
50+
btn3 = digitalio.DigitalInOut(board.D3) # Marked SCL A4
51+
btn3.direction = digitalio.Direction.INPUT
52+
btn3.pull = digitalio.Pull.UP
53+
54+
central = digitalio.DigitalInOut(board.D0) # Marked RX A6
55+
central.direction = digitalio.Direction.INPUT
56+
central.pull = digitalio.Pull.UP
57+
58+
led = digitalio.DigitalInOut(board.D2) # Marked SDA A5
59+
led.switch_to_output()
60+
led.value = False
61+
62+
buttons = [btn1, btn2, btn3]
63+
upper = len(buttons) - 1
64+
65+
ble_enabled = digitalio.DigitalInOut(board.SLIDE_SWITCH)
66+
ble_enabled.direction = digitalio.Direction.INPUT
67+
ble_enabled.pull = digitalio.Pull.UP
68+
69+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.5)
70+
# Use default HID descriptor
71+
hid = HIDService()
72+
device_info = DeviceInfoService(
73+
software_revision=adafruit_ble.__version__, manufacturer="Adafruit Industries"
74+
)
75+
advertisement = ProvideServicesAdvertisement(hid)
76+
advertisement.appearance = 961
77+
scan_response = Advertisement()
78+
79+
ble = adafruit_ble.BLERadio()
80+
if ble.connected:
81+
for c in ble.connections:
82+
c.disconnect()
83+
84+
if ble_enabled.value:
85+
print("advertising")
86+
ble.start_advertising(advertisement, scan_response)
87+
88+
k = Keyboard(hid.devices)
89+
kl = KeyboardLayoutUS(k)
90+
91+
wave_file = open("jeopardy.wav", "rb")
92+
wave = WaveFile(wave_file)
93+
audio = AudioOut(board.SPEAKER)
94+
95+
while True:
96+
if ble_enabled.value:
97+
while not ble.connected:
98+
pass
99+
if ble.connected:
100+
print("Connected")
101+
led.value = True
102+
time.sleep(0.1)
103+
led.value = False
104+
time.sleep(0.1)
105+
led.value = True
106+
time.sleep(0.1)
107+
led.value = False
108+
109+
while ble.connected or not ble_enabled.value:
110+
if not central.value:
111+
led.value = True
112+
print("Running")
113+
while True:
114+
i = random.randint(0, upper)
115+
if not buttons[i].value:
116+
break
117+
118+
audio.play(wave)
119+
if i == 0:
120+
print("Button 1")
121+
pixels.fill((0, 0, 255))
122+
if ble_enabled.value:
123+
kl.write("Button 1")
124+
elif i == 1:
125+
print("Button 2")
126+
pixels.fill((0, 255, 0))
127+
if ble_enabled.value:
128+
kl.write("Button 2")
129+
elif i == 2:
130+
print("Button 3")
131+
pixels.fill((255, 255, 255))
132+
if ble_enabled.value:
133+
kl.write("Button 3")
134+
135+
if not ble_enabled.value:
136+
print(
137+
"BLE HID has been disabled, slide the slide switch to the left to re-enable"
138+
)
139+
140+
print("Finished")
141+
led.value = False
142+
143+
while central.value:
144+
pass
145+
146+
print("reset")
147+
pixels.fill((0, 0, 0))
148+
led.value = True
149+
time.sleep(0.5)
150+
led.value = False
151+
print("Ready")
152+
if ble_enabled.value:
153+
if not ble.connected:
154+
break
155+
else:
156+
continue
157+
break
67.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)