Coder Social home page Coder Social logo

Comments (4)

earlephilhower avatar earlephilhower commented on June 12, 2024

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.

CaptainCredible avatar CaptainCredible commented on June 12, 2024

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.

earlephilhower avatar earlephilhower commented on June 12, 2024

...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.

CaptainCredible avatar CaptainCredible commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.