I'm trying to make to make a simple MIDI communication with a Raspberry Pi Pico (2040) microcontroller (Arduino core/PlatformIO).
I've successfully made it work using USB MIDI with this code (using tinyUSB):
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#include <MIDI.h>
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
void setup()
{
// Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
TinyUSB_Device_Init(0);
// Initialize MIDI, and listen to all MIDI channels
// This will also call usb_midi's begin()
MIDI.begin(MIDI_CHANNEL_OMNI);
// wait until device mounted
while( !TinyUSBDevice.mounted() ) delay(1);
}
void loop() {
// Send Note On for current position at full velocity (127) on channel 1.
MIDI.sendNoteOn(40, 127, 1);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
// Send Note Off for previous note.
MIDI.sendNoteOff(40, 0, 1);
digitalWrite(LED_BUILTIN, LOW);
delay(4000);
}
But now I would like to use hardware MIDI with a MIDI socket. I use a MIDI to USB converter to monitor my signal (tested with a MIDI keyboard). I use UART port 0 (serial 1) on the Raspberry Pi Pico.
Here is my circuit:
I changed the MIDI object creation to this:
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
and removed tinyUSB intialization code.
But I cannot see any MIDI event from my MIDI to USB converter. I checked with an oscilloscope between socket pins 2 and 5 and I can see the signal changing on note ON and OFF events:
Note on:
Note off:
I have no clue on how to debug this... Is the voltage correct (seems to be around 3V) ? Am I missing something on my circuit ?
EDIT: I feel very stupid, I just swapped pins 4 & 5 on my MIDI socket and now I receive messages...
But still I got very inconsistent MIDI messages:
There are lots of double messages, problem between note ON and OFF, sometimes wrong note, wrong velocity?