hairless-midiserial icon indicating copy to clipboard operation
hairless-midiserial copied to clipboard

Control Change command "Unexpected data byte"

Open alexrhodes opened this issue 10 years ago • 7 comments

Windows 8, Arduino Duemilnove, Midi Yoke.

I have found that the program reports "unexpected data byte" whenever I attempt to send a Control Change command. I sent the command using the arduino MIDI library, and by sending it directly in binary. I have verified the correct structure of the midi command is being sent over serial, as well as the correct baud rate. Intermittently it functions correctly, and the commands are sent perfectly. For example, I sent control change 20 to 127 on channel 1 with binary in a loop, 2 seconds apart. the program ran perfectly, I then disconnected the arduino, reconnected and i received the unexpected data byte error again. I have not been able to consistently send the commands correctly. Note On/Off commands work perfectly, it's just the control change commands.

alexrhodes avatar Nov 26 '13 00:11 alexrhodes

I was also getting the same error for a while, although my set up is quite different than yours. Try changing the baud rate again in Preferences, personally I started from the top down until I was able to receive appropriate MIDI messages from my COM Port. The 'unexpected data byte" error disappeared and my controller was stable, but only stable after changing 'flow control' to XON/XOFF. Experiment around a bit and you may find the sweet spot.

ibanman555 avatar Dec 09 '13 17:12 ibanman555

Hi, I have the same issue with ControlChange messages. I did a small test and found: CC works only if I also send NoteOn and NoteOff message NoteOn messages are not recognised ,until I also send NoteOff message. UPDATE: Seems it works but I have to set a message(CC,NoteOn/OFF) going out twice. Is it a bug? EDIT: Sorry for the multiple edits but I isolated some issues: If I send a single CC it's not recognised.But if I send 2 CC but on different channels then both are recognised.

korakios avatar May 25 '14 21:05 korakios

@korakios are you also receiving these messages on Windows?

projectgus avatar May 26 '14 01:05 projectgus

I am on Windows 64bit. Tested on win7_64 and win8.1_64. Also if I send a single NoteOn it's not recognised ,but if I send a NoteOn and then NoteOff message it's ok. Tell me If you need any more info.Thank you.

korakios avatar May 26 '14 07:05 korakios

I'm on Windows 7 64-bit. I also had the same problem when using the arduino midi library with hairless.

Sending the control change on two channels (thanks @korakios) seemed to help remedy the problem (although not an ideal fix).

MIDI.sendControlChange(16, val, 1); //send to midi control change
MIDI.sendControlChange(16, val, 2); //send to midi control change

slyt avatar Oct 01 '14 05:10 slyt

Hi,

I had similar issues and found a solution for my case. I'm not sure if it applies to those cases above, but maybe it helps.

My setup is very simple: a single potentiometer sending ControlChange when I rotate it.

I got lots of "Unexpected data byte" unless I did @slyt's trick.

Solution: Use

struct HairlessMidiSettings : public midi::DefaultSettings
{
   static const bool UseRunningStatus = false;
   static const long BaudRate = 115200;
};
MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, HairlessMidiSettings);

instead of

MIDI_CREATE_DEFAULT_INSTANCE();

Reason: a ControlChange message consists of 3 bytes: 1 "status" byte indicating the type of message and the channel and 2 "data" bytes for controller number and value.

Now there's a MIDI-feature called "running status" to save some bytes. If the status byte doesn't change (because we send lots of ControlChanges on the same channel), instead of sending

S D1 D1   S D2 D2   S D3 D3   S D4 D4   S D5 D5 ...

a midi device can just omit the repetitions of status byte S and just send

S D1 D1   D2 D2   D3 D3   D4 D4   D5 D5 ...

Now guess what happens if your MIDI controller (like mine) ONLY sends ControlChange messages... it will only send one single status byte followed by an endless stream of data bytes. And if Hairless MIDI connects to your Arduino only after it already runs for a while it will never see the status byte, leading to "unexpected data bytes".

The code above disables the "running status" feature in the MIDI library.

jgefele avatar Sep 15 '16 17:09 jgefele

Incredible that you figured it out what's going on. I tried a lot of programs and no one worked well for me that custom trick is awesome. Thanks for sharing it. Saved me a lot of time for my homework.

LuisChris avatar Nov 10 '16 04:11 LuisChris