Skip to content

Commit 2a688db

Browse files
authored
Merge pull request #2526 from adafruit/code_updates
updating a few learn guides
2 parents 8719a60 + 4c2bc8e commit 2a688db

File tree

4 files changed

+16
-8
lines changed
  • Desktop_Air_Monitor
  • MIDI_Melody_Maker
  • MIDI_for_Makers/Receive_MIDI_Over_UART_and_Send_Over_USB
  • QT_Py_RP2040_USB_to_Serial_MIDI_Friends

4 files changed

+16
-8
lines changed

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)

MIDI_Melody_Maker/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
# USB MIDI:
115115
# midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)
116116
# UART MIDI:
117-
midi = adafruit_midi.MIDI(midi_out=busio.UART(board.TX, board.RX, baudrate=31250), out_channel=0)
117+
midi = adafruit_midi.MIDI(midi_out=busio.UART(board.TX, board.RX,
118+
baudrate=31250, timeout=0.001), out_channel=0)
118119

119120
# potentiometer pin setup
120121
key_pot = AnalogIn(board.A1)

MIDI_for_Makers/Receive_MIDI_Over_UART_and_Send_Over_USB/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from adafruit_midi.note_on import NoteOn
1212

1313
# uart setup
14-
uart = busio.UART(board.TX, board.RX, baudrate=31250)
14+
uart = busio.UART(board.TX, board.RX, baudrate=31250, timeout=0.001)
1515
# midi channel setup
1616
midi_in_channel = 1
1717
midi_out_channel = 1

QT_Py_RP2040_USB_to_Serial_MIDI_Friends/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from adafruit_midi.program_change import ProgramChange
1414

1515
# uart setup
16-
uart = busio.UART(board.TX, board.RX, baudrate=31250)
16+
uart = busio.UART(board.TX, board.RX, baudrate=31250, timeout=0.001)
1717
# midi channel setup
1818
midi_in_channel = 1
1919
midi_out_channel = 1

0 commit comments

Comments
 (0)