USBMIDI-Adapter example doesn't send SysEx
Describe the bug
USBMIDI-Adapter example doesn't send SysEx message.
Even though SYSEX_BUFFER_SIZE set to 512 (in Settings.hpp) and SERIAL_BUFFER_SIZE set to 4096, it doesn't send SysEx messages.
To Reproduce Steps to reproduce the behavior.
- Connect Arduino Due to PC
- (optional)set
SYSEX_BUFFER_SIZEto512(default value128) in fileC:\Users\user\Documents\Arduino\libraries\Control_Surface\src\Settings\Settings.hpp - (optional)set
SERIAL_BUFFER_SIZEto4096(default value128) in fileC:\Users\user\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino\RingBuffer.h - upload USBMIDI-Adapter example to arduino due
- send any SysEx to
Arduino Duedevice - no sysex sent.
Expected behavior SysEx messages should be sent.
Code
- Please post the full code required to reproduce the problem.
- If the code doesn't do what you expect, include a detailed description of what you expected the code it to do.
- Don't post code that is too long. Try to narrow down the problem, try one component or aspect of your project at a time.
- Don't post snippets, always post a complete (compilable) sketch.
- Post your code between triple back ticks with the
cpplanguage specifier, as shown below. This ensures that the code is displayed correctly and that syntax highlighting is enabled. (See the GitHub Markdown guide.)
// just example. no changes made.
#include <Control_Surface.h>
// Instantiate a MIDI over USB interface
USBMIDI_Interface midi_usb;
// Instantiate a 5-pin DIN MIDI interface (on the TX and RX pins of Serial1)
HardwareSerialMIDI_Interface midi_ser {Serial1};
// Instantiate the pipe to connect the two interfaces
BidirectionalMIDI_Pipe pipes;
void setup() {
// Manually route MIDI input from the serial interface to the USB interface,
// and the MIDI input from the USB interface to the serial interface
midi_ser | pipes | midi_usb;
// Initialize the MIDI interfaces
MIDI_Interface::beginAll();
}
void loop() {
// Continuously poll all interfaces and route the traffic between them
MIDI_Interface::updateAll();
}
Hi, could you please provide more details about how you're sending SysEx messages to the Arduino?
I don't have any Dues at hand, but I just tried the same code on an Arduino Nano 33 BLE, and everything seems to work as expected: When executing the command below to send a long SysEx message of 262 bytes to the Arduino over USB, I see the same bytes being sent out over the Serial port:
amidi -p hw:1,0,0 -S "F0 30 61 30 62 30 63 30 64 30 65 30 66 30 67 30 68 30 69 30 6A 30 6B 30 6C 30 6D 30 6E 30 6F 30 70 30 71 30 72 30 73 30 74 30 75 30 76 30 77 30 78 30 79 30 7A 31 61 31 62 31 63 31 64 31 65 31 66 31 67 31 68 31 69 31 6A 31 6B 31 6C 31 6D 31 6E 31 6F 31 70 31 71 31 72 31 73 31 74 31 75 31 76 31 77 31 78 31 79 31 7A 32 61 32 62 32 63 32 64 32 65 32 66 32 67 32 68 32 69 32 6A 32 6B 32 6C 32 6D 32 6E 32 6F 32 70 32 71 32 72 32 73 32 74 32 75 32 76 32 77 32 78 32 79 32 7A 33 61 33 62 33 63 33 64 33 65 33 66 33 67 33 68 33 69 33 6A 33 6B 33 6C 33 6D 33 6E 33 6F 33 70 33 71 33 72 33 73 33 74 33 75 33 76 33 77 33 78 33 79 33 7A 34 61 34 62 34 63 34 64 34 65 34 66 34 67 34 68 34 69 34 6A 34 6B 34 6C 34 6D 34 6E 34 6F 34 70 34 71 34 72 34 73 34 74 34 75 34 76 34 77 34 78 34 79 34 7A 35 61 35 62 35 63 35 64 35 65 35 66 35 67 35 68 35 69 35 6A 35 6B 35 6C 35 6D 35 6E 35 6F 35 70 35 71 35 72 35 73 35 74 35 75 35 76 35 77 35 78 35 79 35 7A 36 61 36 62 36 63 36 64 36 65 36 66 36 67 36 68 36 69 36 6A 36 6B 36 6C 36 6D 36 6E 36 6F 36 70 36 71 36 72 36 73 36 74 36 75 36 76 36 77 36 78 36 79 36 7A 37 61 37 62 37 63 37 64 37 65 37 66 37 67 37 68 37 69 37 6A 37 6B 37 6C 37 6D 37 6E 37 6F 37 70 37 71 37 72 37 73 37 74 37 75 37 76 37 77 37 78 37 79 37 7A 38 61 38 62 38 63 38 64 38 65 38 66 38 67 38 68 38 69 38 6A 38 6B 38 6C 38 6D 38 6E 38 6F 38 70 38 71 38 72 38 73 38 74 38 75 38 76 38 77 38 78 38 79 38 7A 39 61 39 62 39 63 39 64 39 65 39 66 39 67 39 68 39 69 39 6A 39 6B 39 6C 39 6D 39 6E 39 6F 39 70 39 71 39 72 39 73 39 74 39 75 39 76 39 77 39 78 39 79 39 7A F7"
Some more questions:
- The Arduino Due is a 3.3V device. Are you using a buffer or level shifter between the TX pin and your MIDI output connector? Are you using appropriate resistor values for 3.3V (the standard value of 220Ω is for 5V only).
- Are you able to send/receive any other messages besides SysEx?
- Are you able to send SysEx messages using https://tttapa.github.io/Control-Surface/Doxygen/d2/d93/SysEx-Send-Receive_8ino-example.html? (After changing the MIDI interface in that example.)
- Which type of MIDI device do you have connected to pin D18/TX1 of the Due?
I used a wire to connect TX1 to RX1 and sent a sysex message. I used MIDITester(https://openmidiproject.opal.ne.jp/MIDITester_en.html), Sekaiju(https://openmidiproject.opal.ne.jp/Sekaiju_en.html) to send midi events, and I used MIDI-OX(http://www.midiox.com/moxdown.htm) to receive midi events.
answers at that time:
- I'm not using 5pin DIN midi output connector.
- Yes. Note On/Off, CC, Pitch bend works well.
- I don't have another 3.3v midi device.
- just wire from TX1 to RX1.
I bought new Due and tested.
Test 1:
Due1: USBMIDI-Adapter example uploaded.
Due2: modified MIDI-Monitor example uploaded(midi port changed). modified code:
code
#include <Control_Surface.h> // Include the Control Surface library
// Instantiate the two MIDI interfaces
//USBMIDI_Interface midiusb;
HardwareSerialMIDI_Interface midi_ser {Serial1};
USBDebugMIDI_Interface mididbg;
// Instantiate a MIDI pipe to connect the two interfaces
BidirectionalMIDI_Pipe mpipe;
void setup() {
// Create a bidirectional route between the interfaces:
// all input to one interface is sent to the output of the other
midi_ser | mpipe | mididbg;
// Initialize all MIDI interfaces
MIDI_Interface::beginAll();
}
void loop() {
// Continuously handle MIDI input
MIDI_Interface::updateAll();
}
wiring:
Due1's TX1 - Due2's RX1
I sent some sysex to Due1's USB MIDI port and serial monitor connected to Due2 shows complete sysex.
so no problem in sending sysex(pc -> arduino serial) with usb-midi example.
Test 2:
Due1: modified SysEx-Send-Receive example uploaded(midi port changed). code below
Due2: USBMIDI-Adapter example uploaded.
code
#include <Control_Surface.h>
// Instantiate the MIDI over USB interface
//USBMIDI_Interface midi;
HardwareSerialMIDI_Interface midi {Serial1};
// Custom MIDI callback that prints incoming SysEx messages.
struct MyMIDI_Callbacks : MIDI_Callbacks {
// This callback function is called when a SysEx message is received.
void onSysExMessage(MIDI_Interface &, SysExMessage sysex) override {
// Print the message
Serial << F("Received SysEx message: ") //
<< AH::HexDump(sysex.data, sysex.length) //
<< F(" on cable ") << sysex.cable.getOneBased() << endl;
}
} callback {};
// Push button connected between pin 2 and ground.
// SysEx message is sent when pressed.
Button pushbutton {2};
void setup() {
Serial.begin(115200);
pushbutton.begin(); // enables internal pull-up
midi.begin();
midi.setCallbacks(callback);
}
void loop() {
// Send a SysEx message when the push button is pressed
uint8_t sysex[] {0xF0, 0x11, 0x22, 0x33, 0xF7};
if (pushbutton.update() == Button::Falling)
midi.sendSysEx(sysex);
// Read incoming MIDI data and call the callback if a new
// SysEx message has been received.
midi.update();
}
wiring:
Due1's TX1 - Due2's RX1
Due1's pin 2 - wire(It works like a button by manually connecting and disconnecting the wire to GND.)
I connected pin 2 to GND and no message shown in MIDI-OX.
I think sending sysex like this direction arduino usb -> pc doesn't work.