adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
MIT License
3.93k stars 1.14k forks source link

Adafruit_MIDI incompatible .mpy file #9258

Closed Tom-Vulpes closed 1 week ago

Tom-Vulpes commented 2 weeks ago

CircuitPython version

adafruit-circuitpython-raspberry_pi_pico-en_GB-9.0.4

Code/REPL

import time
import board
import touchio
import usb_midi
import adafruit_midi
from adafruit_midi.note_on import NoteOn
from adafruit_midi.note_off import NoteOff

# Define the touch pins
touch_pins = [board.GP0, board.GP1, board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7, board.GP8, board.GP9, board.GP10, board.GP11, board.GP12, board.GP13, board.GP14, board.GP15, board.GP16, board.GP17, board.GP18, board.GP19, board.GP20, board.GP21, board.GP22, board.GP26, board.GP27, board.GP28]

touch_sensors = []
for pin in touch_pins:
    try:
        touch_sensors.append(touchio.TouchIn(pin))
    except ValueError:
        print(f"No pulldown resistor found on pin {pin}, skipping...")

# MIDI setup - If you want to assign the midi device to a specific channel or port then just change the values in this line.
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

# MIDI note numbers corresponding to each touch pin - change these to whatever midi note you prefer. The default is a 2 octave diatonic scale.
midi_notes = [30, 32, 34, 35, 37, 39, 41, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 59, 61, 63, 65, 66, 68, 70, 71, 73] 

# State variables to track if a note has been played for each touch pin
note_played = [False] * len(touch_pins)

# Main loop
while True:
    for i, touch_sensor in enumerate(touch_sensors):
        # Capacitive touch sensing
        if touch_sensor.value:
            # Check if the note has already been played
            if not note_played[i]:
                # Send MIDI note on message when touch is detected. The Velocity is set to 120, change the value if you want to.
                midi.send(NoteOn(midi_notes[i], 120))
                note_played[i] = True  # Update state variable
        else:
            # Check if the note has been played and turn it off
            if note_played[i]:
                # Send MIDI note off message when touch is released
                midi.send(NoteOff(midi_notes[i], 120))
                note_played[i] = False  # Update state variable

Behavior

Traceback (most recent call last): File "", line 7, in ValueError: incompatible .mpy file

Description

Code works perfectly in version 8.2.10 but updating to 9.0.4 gives errors with the adafruit_midi library.

Additional information

No response

RetiredWizard commented 2 weeks ago

The mpy format changed with version 9. Did you update to the version 9 bundle? circup update

Tom-Vulpes commented 1 week ago

I did not. Mark this one down as user error. Thank you!