Problems with hardware midi callbacks on Pico RP2040 #965
Replies: 1 comment 1 reply
-
I'm unable to reproduce the issue on my end. Messages with a value of 0xFF (all ones) may indicate a hardware problem. Here's what I tried (using the current #include <Control_Surface.h>
USBMIDI_Interface midi_usb;
HardwareSerialMIDI_Interface midi_ser{ Serial1, MIDI_BAUD };
BidirectionalMIDI_Pipe pipes;
void setup() {
midi_ser | pipes | midi_usb;
MIDI_Interface::beginAll();
}
void loop() {
MIDI_Interface::updateAll();
} Then I uploaded the MIDI-Input-Callback.ino example with the change you described to the second Pico: #include <Control_Surface.h> // Include the Control Surface library
HardwareSerialMIDI_Interface midi{ Serial1, MIDI_BAUD };
bool channelMessageCallback(ChannelMessage cm) {
Serial << F("Channel message: ") << hex //
<< cm.header << ' ' << cm.data1 << ' ' << cm.data2 //
<< dec << F(" on cable ") << cm.cable.getOneBased() << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
bool sysExMessageCallback(SysExMessage se) {
Serial << F("System Exclusive message: [") << se.length << "] " //
<< AH::HexDump(se.data, se.length) //
<< F(" on cable ") << se.cable.getOneBased() << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
bool sysCommonMessageCallback(SysCommonMessage sc) {
Serial << F("System Common message: ") << hex //
<< sc.header << ' ' << sc.data1 << ' ' << sc.data2 //
<< dec << F(" on cable ") << sc.cable.getOneBased() << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
bool realTimeMessageCallback(RealTimeMessage rt) {
Serial << F("Real-time message: ") //
<< hex << rt.message << dec //
<< F(" on cable ") << rt.cable.getOneBased() << endl;
return true; // Return true to indicate that handling is done,
// and Control_Surface shouldn't handle it anymore.
// If you want Control_Surface to handle it as well,
// return false.
}
void setup() {
Serial.begin(115200);
Control_Surface.begin();
Control_Surface.setMIDIInputCallbacks(channelMessageCallback, //
sysExMessageCallback, //
sysCommonMessageCallback, //
realTimeMessageCallback); //
// If you don't need all four callbacks, you can pass `nullptr` instead of a
// function pointer
}
void loop() {
Control_Surface.loop();
} When I send a MIDI message to the first Pico (I used amidi -p hw:1,0,0 -S "90 3C 7F" I get the expected response from the second Pico in the serial monitor:
To verify that you're getting meaningful data from the serial port, you can start with a minimal debugging sketch like this one: void setup() {
Serial.begin(115200);
Serial1.begin(31250);
}
void loop() {
if (Serial1.available() > 0)
Serial.println(Serial1.read(), HEX);
} Keep in mind that the Pi Pico is a 3.3V device. Many MIDI circuits you'll find online are designed for 5V. |
Beta Was this translation helpful? Give feedback.
-
Hello!
I am attempting to build a Midi Controller type device with both USB and Hardware midi ports, using a Raspberry Pi Pico (RP2040). This is the first time I have used this library, so am still quite unfamiliar.
I have hardware 5pin DIN midi in and out circuitry connected to pins 0 and 1 (uart0).
If I run this sketch it seems to work fine, midi notes and midi sysex messages via the USB midi all come up in the serial monitor as expected.
https://tttapa.github.io/Control-Surface-doc/Doxygen/d0/d32/MIDI-Input-Callback_8ino-example.html#a21
however if I change the 2nd line:
USBMIDI_Interface midi;
to be hardware midi instead of USB midi:
HardwareSerialMIDI_Interface midi {Serial1, MIDI_BAUD};
all midi data on the hardware ports do post messages in the serial monitor, but they all come through as real time messages no matter what midi I send to the hardware input:
"Real-time message: ff on cable 1"
Ive tried various other Control-Surface examples and the hardware midi usually sends midi correctly, but I'm finding the receiving midi callbacks either dont work at all, or come through as the wrong message type.
Any suggestions?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions