Skip to content

Commit ee64d15

Browse files
authored
Merge branch 'adafruit:main' into main
2 parents 1b16ced + ad35352 commit ee64d15

File tree

50 files changed

+11324
-106
lines changed

Some content is hidden

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

50 files changed

+11324
-106
lines changed

2020_shake/.matrixportal.test.only

Whitespace-only changes.

2020_shake/2020_shake.ino

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ bool show_new_year = true;
2727
#define SHAKE_PERIOD 2000 // Period (in ms) when SHAKE_EVENTS must happen
2828
#define SAND_TIME 6000 // Time (in ms) to run simulation before restarting
2929

30+
#if defined(_VARIANT_MATRIXPORTAL_M4_) // MatrixPortal M4
3031
uint8_t rgbPins[] = {7, 8, 9, 10, 11, 12};
31-
uint8_t addrPins[] = {17, 18, 19, 20};
32+
uint8_t addrPins[] = {17, 18, 19, 20, 21};
3233
uint8_t clockPin = 14;
3334
uint8_t latchPin = 15;
3435
uint8_t oePin = 16;
36+
#else // MatrixPortal ESP32-S3
37+
uint8_t rgbPins[] = {42, 41, 40, 38, 39, 37};
38+
uint8_t addrPins[] = {35, 36, 48, 45, 21};
39+
uint8_t clockPin = 2;
40+
uint8_t latchPin = 47;
41+
uint8_t oePin = 14;
42+
#endif
3543

3644
// 64x32 pixel matrix, 6-bit depth
3745
Adafruit_Protomatter matrix(

Adafruit_I2S_BFF/Arduino/I2S_BFF_QT_Py_RP2040_Audio_Playback/.qt_py_rp2040.test.only

Whitespace-only changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-FileCopyrightText: 2023 Ladyada for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
/*
6+
This example plays a 'raw' PCM file from memory to I2S
7+
*/
8+
9+
#include <I2S.h>
10+
11+
#include "startup.h" // audio file in flash
12+
13+
// Create the I2S port using a PIO state machine
14+
I2S i2s(OUTPUT);
15+
16+
// GPIO pin numbers
17+
#define pBCLK A2 // QT Py BFF default BITCLOCK
18+
#define pWS A1 // QT Py BFF default LRCLOCK
19+
#define pDOUT A0 // QT Py BFF default DATA
20+
21+
#define USERBUTTON 21 // QT Py RP2040 built in button
22+
23+
// variable shared between cores
24+
volatile bool playaudio = false;
25+
26+
void setup() {
27+
Serial.begin(115200);
28+
//while (!Serial) delay(10);
29+
Serial.println("I2S playback demo");
30+
31+
pinMode(USERBUTTON, INPUT_PULLUP);
32+
}
33+
34+
void loop() {
35+
// on button press tell the other core to play audio clip!
36+
if (!digitalRead(USERBUTTON)) {
37+
playaudio = true;
38+
} else {
39+
playaudio = false;
40+
}
41+
}
42+
43+
void setup1() {
44+
i2s.setBCLK(pBCLK);
45+
i2s.setDATA(pDOUT);
46+
i2s.setBitsPerSample(16);
47+
}
48+
49+
void loop1() {
50+
// the main loop will tell us when it wants us to play!
51+
if (playaudio) {
52+
play_i2s(startupAudioData, sizeof(startupAudioData), startupSampleRate);
53+
}
54+
}
55+
56+
void play_i2s(const uint8_t *data, uint32_t len, uint32_t rate) {
57+
// start I2S at the sample rate with 16-bits per sample
58+
if (!i2s.begin(rate)) {
59+
Serial.println("Failed to initialize I2S!");
60+
delay(500);
61+
i2s.end();
62+
return;
63+
}
64+
65+
for(uint32_t i=0; i<len; i++) {
66+
uint16_t sample = (uint16_t)data[i] << 6; // our data is 10 bit but we want 16 bit so we add some gain
67+
// write the same sample twice, once for left and once for the right channel
68+
i2s.write(sample);
69+
i2s.write(sample);
70+
}
71+
i2s.end();
72+
}

Adafruit_I2S_BFF/Arduino/I2S_BFF_QT_Py_RP2040_Audio_Playback/startup.h

Lines changed: 4377 additions & 0 deletions
Large diffs are not rendered by default.

Adafruit_I2S_BFF/Arduino/I2S_BFF_QT_Py_RP2040_Tone/.qt_py_rp2040.test.only

Whitespace-only changes.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-FileCopyrightText: 2016 Sandeep Mistry
2+
// SPDX-FileCopyrightText: 2022 Earle F. Philhower, III
3+
// SPDX-FileCopyrightText: 2023 Ladyada for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
/*
8+
This example generates a square wave based tone at a specified frequency
9+
and sample rate. Then outputs the data using the I2S interface to a
10+
MAX08357 I2S Amp Breakout board.
11+
12+
created 17 November 2016
13+
by Sandeep Mistry
14+
modified for RP2040 by Earle F. Philhower, III <earlephilhower@yahoo.com>
15+
16+
17+
bool setBCLK(pin_size_t pin);
18+
- This assigns two adjacent pins - the pin after this one (one greater)
19+
is the WS (word select) signal, which toggles before the sample for
20+
each channel is sent
21+
22+
bool setDATA(pin_size_t pin);
23+
- Sets the DOUT pin, can be any valid GPIO pin
24+
*/
25+
26+
#include <I2S.h>
27+
28+
// Create the I2S port using a PIO state machine
29+
I2S i2s(OUTPUT);
30+
31+
// GPIO pin numbers
32+
#define pBCLK A2 // QT Py BFF default BITCLOCK
33+
#define pWS A1 // QT Py BFF default LRCLOCK
34+
#define pDOUT A0 // QT Py BFF default DATA
35+
36+
const int frequency = 440; // frequency of square wave in Hz
37+
const int amplitude = 500; // amplitude of square wave
38+
const int sampleRate = 16000; // 16 KHz is a good quality
39+
40+
const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave
41+
42+
int16_t sample = amplitude; // current sample value
43+
int count = 0;
44+
45+
void setup() {
46+
Serial.begin(115200);
47+
while (!Serial) delay(10);
48+
Serial.println("I2S simple tone");
49+
50+
i2s.setBCLK(pBCLK);
51+
i2s.setDATA(pDOUT);
52+
i2s.setBitsPerSample(16);
53+
54+
// start I2S at the sample rate with 16-bits per sample
55+
if (!i2s.begin(sampleRate)) {
56+
Serial.println("Failed to initialize I2S!");
57+
while (1); // do nothing
58+
}
59+
60+
}
61+
62+
void loop() {
63+
if (count % halfWavelength == 0) {
64+
// invert the sample every half wavelength count multiple to generate square wave
65+
sample = -1 * sample;
66+
}
67+
68+
// write the same sample twice, once for left and once for the right channel
69+
i2s.write(sample);
70+
i2s.write(sample);
71+
72+
// increment the counter for the next sample
73+
count++;
74+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S Tone playback example.
5+
"""
6+
import time
7+
import array
8+
import math
9+
import audiocore
10+
import board
11+
import audiobusio
12+
13+
TONE_VOLUME = 0.1 # Increase this to increase the volume of the tone.
14+
FREQUENCY = 440 # Set this to the Hz of the tone you want to generate.
15+
16+
audio = audiobusio.I2SOut(board.A2, board.A1, board.A0)
17+
18+
length = 8000 // FREQUENCY
19+
sine_wave = array.array("h", [0] * length)
20+
for i in range(length):
21+
sine_wave[i] = int((math.sin(math.pi * 2 * i / length)) * TONE_VOLUME * (2 ** 15 - 1))
22+
sine_wave_sample = audiocore.RawSample(sine_wave)
23+
24+
while True:
25+
audio.play(sine_wave_sample, loop=True)
26+
time.sleep(1)
27+
audio.stop()
28+
time.sleep(1)
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2023 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""
4+
CircuitPython I2S WAV file playback.
5+
"""
6+
import audiocore
7+
import board
8+
import audiobusio
9+
10+
LOOP = False # Update to True loop WAV playback. False plays once.
11+
12+
audio = audiobusio.I2SOut(board.A2, board.A1, board.A0)
13+
14+
with open("chikken.wav", "rb") as wave_file:
15+
wav = audiocore.WaveFile(wave_file)
16+
17+
print("Playing wav file!")
18+
audio.play(wav, loop=LOOP)
19+
while audio.playing:
20+
pass
21+
22+
print("Done!")

Desktop_Air_Monitor/code.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@
2626
reset_pin = None
2727

2828
pm25 = PM25_I2C(i2c, reset_pin)
29-
aqdata = pm25.read()
3029

3130
scd4x = adafruit_scd4x.SCD4X(i2c)
3231
scd4x.start_periodic_measurement()
3332

3433
time.sleep(5)
3534

35+
try:
36+
aqdata = pm25.read()
37+
pm2 = int(aqdata["pm25 standard"])
38+
except RuntimeError:
39+
pm2 = 0
40+
3641
co2 = scd4x.CO2
3742
temp = scd4x.temperature
3843
humidity = scd4x.relative_humidity
3944

40-
pm2 = int(aqdata["pm25 standard"])
41-
4245
def rate_pm25(pm25_data):
4346
if pm25_data <= 12:
4447
pm25_outline = 94
@@ -98,8 +101,12 @@ def c_to_f(temp_data):
98101
co2 = scd4x.CO2
99102
temp = c_to_f(scd4x.temperature)
100103
humidity = scd4x.relative_humidity
101-
aqdata = pm25.read()
102-
pm2 = int(aqdata["pm25 standard"])
104+
try:
105+
aqdata = pm25.read()
106+
pm2 = int(aqdata["pm25 standard"])
107+
except RuntimeError:
108+
print("Unable to read from PM2.5 sensor, no new data..")
109+
continue
103110
pm2_color, pm2_outline.x = rate_pm25(pm2)
104111
sensor_data = [pm2, co2, temp, humidity]
105112
pixels.fill(pm2_color)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# SPDX-FileCopyrightText: 2023 Trevor Beaton for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import os
5+
import ssl
6+
import time
7+
import wifi
8+
import board
9+
import displayio
10+
import terminalio
11+
import socketpool
12+
import adafruit_requests
13+
from adafruit_display_text import bitmap_label
14+
15+
# Initialize Wi-Fi connection
16+
try:
17+
wifi.radio.connect(
18+
os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")
19+
)
20+
print("Connected to %s!" % os.getenv("CIRCUITPY_WIFI_SSID"))
21+
except Exception as e: # pylint: disable=broad-except
22+
print(
23+
"Failed to connect to WiFi. Error:", e, "\nBoard will hard reset in 30 seconds."
24+
)
25+
26+
pool = socketpool.SocketPool(wifi.radio)
27+
requests = adafruit_requests.Session(pool, ssl.create_default_context())
28+
29+
# Set up the URL for fetching time data
30+
DATA_SOURCE = "http://worldtimeapi.org/api/timezone/" + os.getenv("TIMEZONE")
31+
32+
# Set up display a default image
33+
display = board.DISPLAY
34+
default_bitmap = displayio.OnDiskBitmap("/images/blanka-chan.bmp")
35+
default_tile_grid = displayio.TileGrid(default_bitmap, pixel_shader=default_bitmap.pixel_shader)
36+
37+
group = displayio.Group()
38+
group.append(default_tile_grid)
39+
40+
# Create label for displaying time
41+
time_label = bitmap_label.Label(terminalio.FONT, scale=5)
42+
time_label.anchor_point = (0.2, 0.5)
43+
time_label.anchored_position = (display.width // 2, display.height // 2)
44+
45+
# Create main group to hold all display groups
46+
main_group = displayio.Group()
47+
main_group.append(group)
48+
main_group.append(time_label)
49+
# Show the main group on the display
50+
display.show(main_group)
51+
52+
current_background_image = "/images/blanka-chan.bmp"
53+
54+
def set_background_image(filename):
55+
global current_background_image # pylint: disable=global-statement
56+
tile_bitmap = displayio.OnDiskBitmap(filename)
57+
new_tile_grid = displayio.TileGrid(tile_bitmap, pixel_shader=tile_bitmap.pixel_shader)
58+
group[0] = new_tile_grid
59+
current_background_image = filename
60+
61+
def parse_time(datetime_str):
62+
# Extract the time part from the datetime string
63+
time_str = datetime_str.split("T")[1].split(".")[0]
64+
hour, minute, _ = map(int, time_str.split(":"))
65+
66+
# Convert 24-hour format to 12-hour format and determine AM/PM
67+
period = "AM"
68+
if hour >= 12:
69+
period = "PM"
70+
if hour > 12:
71+
hour -= 12
72+
elif hour == 0:
73+
hour = 12
74+
75+
return hour, minute, period
76+
77+
while True:
78+
# Fetch time data from WorldTimeAPI
79+
response = requests.get(DATA_SOURCE)
80+
data = response.json()
81+
82+
# Parse the time from the datetime string
83+
current_hour, current_minute, current_period = parse_time(data["datetime"])
84+
85+
# Display the time
86+
time_label.text = " {:2}{}\n :{:02}".format(current_hour, current_period, current_minute)
87+
88+
# Switch between two images
89+
if current_background_image == "/images/blanka-chan.bmp":
90+
set_background_image("/images/blanka-chan-charged.bmp")
91+
else:
92+
set_background_image("/images/blanka-chan.bmp")
93+
94+
time.sleep(5)

0 commit comments

Comments
 (0)