2

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?

JYelton
  • 32,302
  • 33
  • 134
  • 249
risk
  • 213
  • 2
  • 7
  • What is the bit rate? – Justme Jun 10 '22 at 18:39
  • 2
    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](https://audiodestrukt.wordpress.com/2012/11/18/inexpensive-usb-midi-interfaces/). – CL. Jun 10 '22 at 18:48
  • @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 ? – risk Jun 10 '22 at 18:49
  • @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 ? – risk Jun 10 '22 at 18:52
  • Which MIDI adapter you have? Is it MIDI compliant and works with 3.3V voltage? – Justme Jun 10 '22 at 18:53
  • But maybe you're right and the problem comes from my MIDI/USB converter ? what's strange is that I tested it with a midi keyboard and it worked great. – risk Jun 10 '22 at 18:55
  • If the MIDI keyboard uses 5V current loop then it works better. Completely different scenario. – Justme Jun 10 '22 at 18:56
  • @Justme you were right. Just tested adding a level shifter to 5V and swapping resistors for 220ohm (like specified in MIDI specs for 5V) and it works great ! – risk Jun 10 '22 at 19:15
  • @Risk Another test would be to disconnect ground pin 2 from your output connector. A proper MIDI input has optoisolation which only uses pins 4 and 5 to operate. If it stops working the MIDI interface you have is not compliant or even compatible with MIDI standard and should not be sold as a MIDI device. Or open the MIDI interface to see if it even contains an opto-isolator, or if it does, is it implemented correctly. – Justme Jun 10 '22 at 19:18
  • @Justme still working after disconnecting ground :) – risk Jun 10 '22 at 19:22
  • do you have your full code in platformio somewhere? Including the dependency libraries and versions? I can't get even your example running where it just loops through a random noteon/noteoff... it compiles and uploads but I can't see it as a midi device on my mac – tsdexter Apr 02 '23 at 23:03

1 Answers1

1

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

risk
  • 213
  • 2
  • 7