2
\$\begingroup\$

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:

raspberry pi pico midi out

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 on

Note off:

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:

midi messages

There are lots of double messages, problem between note ON and OFF, sometimes wrong note, wrong velocity?

\$\endgroup\$
11
  • \$\begingroup\$ What is the bit rate? \$\endgroup\$ Commented Jun 10, 2022 at 18:39
  • 2
    \$\begingroup\$ The waveforms are correct (90 28 7F, 80 28 00), and have the correct timing for 31250 baud. I'd guess your MIDI/USB converter is not MIDI compatible, which is a common problem with cheap Chinese crap. \$\endgroup\$ Commented Jun 10, 2022 at 18:48
  • \$\begingroup\$ @Justme midi should be 31250 but I don't think I can change it with the library I use. I assume it should set it properly ? \$\endgroup\$ Commented Jun 10, 2022 at 18:49
  • \$\begingroup\$ @CL. thank for checking up, please see my edit (I'm sorry I did not checked before...), it is working now but still I have very inconsistent values, do you know how I could debug that ? \$\endgroup\$ Commented Jun 10, 2022 at 18:52
  • \$\begingroup\$ Which MIDI adapter you have? Is it MIDI compliant and works with 3.3V voltage? \$\endgroup\$ Commented Jun 10, 2022 at 18:53

1 Answer 1

1
\$\begingroup\$

This is resolved. Leaving this here because schematics and code may be useful to someone in the future.

My issues were :

  1. Messed with MIDI DIN connector pins, switching pins 4 and 5 resolved the initial issue.
  2. MIDI to USB converter I used does not handle well 3V MIDI. I used a level shifter to boost the signal to 5V and swap both resistors to 220ohm to match MIDI specs for 5V. Now it works great.

Thanks to @Justme and @CL. who helped me in the comments (see full discussion for more info).

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.