Comments (4)
Sorry, but because this is HW related (I don't have any MIDI equipment or adapters for the RP2040) there's not much anyone but you can do to debug this.
I don't have experience with the Adafruit MIDI (just a wrapper for TinyUSB MIDI AIUI), but right off the bat I believe you're going to get callbacks from within a USB IRQ. Which means that writing to Serial
, which is also USB, is not legal or safe (Tiny
USB is NOT re-entrant!). Can you dump to a UART port (Serial1
instead, for example) instead?
My recommendation would be to hook up a PicoProbe and check what the Pico is doing when it seems to hang. The core stack trace from gdb
's where
is often enough to explain what's going on. If not, you could dump it and post it here for others to look at.
from arduino-pico.
PicoProbe! Thats what I'll do then. I have been working in the Arduino IDE until now and as far as I can tell I need to be using something else like VSCode + platformio to use the debugging properly.
P.S. the above example doesn't rely on any other hardware than a raspberry pi pico and a usb cable. MIDI can be sent and received by a computer using a plethora of free software like,MIDIOX(win) reaper, or even browser based alternatives like this: https://versioduo.com/webmidi-test/
from arduino-pico.
...the above example doesn't rely on any other hardware than a raspberry pi pico and a usb cable...
Oops! I was thinking of the old-style round DIN UART-based MIDI stuff. USB's eaten that, too, I guess. :)
In any case, before trying to learn VSCode (I myself just run openocd and gdb in a command shell) remove that Serial.xxxx
stuff from the note callbacks. That's not legal if TinyUSB is calling your callback from a USB interrupt (which I am 99% sure it is) and the root of your crashes. No need to run a debugger.
You should instead put note ons/note offs into a IRQ-safe queue and have the main loop
handle the printout or actual sound generation.
The Adafruit example may do it this way because for the basic Arduino boards Serial
used to be a simple UART and not USB-based (AVR-type boards, for example).
from arduino-pico.
I tried removing al Serial.xxx and this did indeed remedy the problem.
the code below blinks the LED to give visual feedback as to whether or not the pico has locked up and responds with MIDI messages to any incoming MIDI messages. I can send notes and midi clock to it at a rate of 999BPM (*24 clock ticks per beat) and the pico copes just fine and responds with MIDI messages in return.
`#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>
Adafruit_USBD_MIDI usb_midi;
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
void setup()
{
#if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
// Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
TinyUSB_Device_Init(0);
#endif
pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OMNI);
MIDI.turnThruOff();
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.setHandleClock(handleClock);
while( !TinyUSBDevice.mounted() ) delay(1);
}
int incrementor = 0;
bool ledState = false;
void loop(){
// read any new MIDI messages
MIDI.read();
//while(MIDI.read()){
//}
incrementor++;
incrementor = incrementor%10000;
if(incrementor == 0){
ledState = !ledState;
if(ledState){
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
}
}
void handleClock(){
int nombre = random(30,80);
MIDI.sendNoteOn(nombre, 100, 5);
MIDI.sendNoteOff(nombre, 100, 5);
}
void handleNoteOn(byte channel, byte pitch, byte velocity)
{
MIDI.sendNoteOn(pitch, velocity, channel);
}
void handleNoteOff(byte channel, byte pitch, byte velocity)
{
MIDI.sendNoteOff(pitch, velocity, channel);
}
`
from arduino-pico.
Related Issues (20)
- Flashing settings for Listfiles-USB - Docs HOT 4
- Version 3.8.0 Compiler Error HOT 1
- I2S Right Channel is One Sample Shifted in Time from Left HOT 1
- Feature Request: Integration of class MacAddress from arduino-esp32? HOT 2
- Fix enum redeclaration issue when using WiFi and Ethernet HOT 14
- WiFiServer and FreeRTOS - Repeatedly accepting connection eventually causes freeze HOT 4
- Joystick library - please update submodule HOT 1
- LittleFS file not opening on Pico HOT 3
- Question: What limits lwip usage within a FreeRTOS environment to setup/loop and not tasks?
- When using platformio, earlephilhower-based firmware doesn't run after reboot-to-bootloader (but does after hard BOOTSEL+RESET) HOT 4
- Hang with Pico W when using a W5500 and WiFi at the same time.
- SdFat speed regression (because of pico SPI driver change) HOT 5
- Fix for Linux hanging on PICO switching to storage mode for upload HOT 4
- Feature Request: Ability to change bluetooth device name from SerialBT
- Bluetooth reconnect fails HOT 1
- Error compiling A2DPSink
- New sketch not running with Arduino IDE OTA (Rpi Pico W) HOT 7
- PICO W STUCK DUE TO FLASH CORRUPTION. HOT 2
- Warning : "MEM_STATS" / "MEMP_STATS" redefined when not using NDEBUG
- Feature Request: Setting usb_hid_poll_interval in setup HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-pico.