SysEx from Arduino Uno, and why my method doesn't work

Hi, I’m new here and to Arduino. I’ve learned quite a bit already and made a simple FX on/off MIDI pedal which works fine using a MIDI Control Change to a digital mixer thanks to a few of you here :slight_smile:

So, I’m trying to send SysEx codes to my Roland Integra sound module.

There’s hundreds of commands and I’m fine with SysEx itself, been using it years. I have all the codes I need (deleted from here for space). Most are 14byte (but some can get up in the 70s).

The first 7 bytes are always the same, the next 3 are offsets, next 1 is the parameter I need to address, next come the value bytes (usually only 1), then the checksum (not using that at the moment as it seems to be ok for now…), then the stop byte.

Did it like this because it seemed a lot more intuitive to me, saves space, and easier to catergorize so many codes etc.

So, if any one of you could please tell me why the commented line near the end doesn’t work, but sending the full message does (the sendSysEx command wraps the start and end automatically), I’d greatly appreciate it! Surely using the full SysEx code for everything would be madness?

Thanks

Adam

#include <MIDI.h>

byte x = (0x20); // holder for the value byte

MIDI_CREATE_DEFAULT_INSTANCE();

// SYSEX HEADERS

const byte sysexStart[6] = {0x41, 0x10, 0x00, 0x00, 0x64, 0x12}; // Sysex Send Start

const byte sysexEnd[1] = {0x00}; // SysEx Send End


// OFFSETS //

// Part Common Offset
const byte PartCommon [3] = {0x18, 0x00, 0x20}; // for parts 2-16 (0x20 > 0x2F) last byte
//
// lots more 'offsets'
//




// PARAMETERS

const byte levelSet [1] = {0x09}; // Level (0 - 127)
//
// lots and lots more 'parameters'
//

void setup() {

MIDI.begin();

byte SysEx [] = {0x41, 0x10, 0x00, 0x00, 0x64, 0x12, 0x18, 0x00, 0x20, 0x09, x, 0x00};
//byte SysEx [] = {sysexStart, PartCommon, levelSet, x, sysexEnd}; 


MIDI.sendSysEx(sizeof(SysEx), SysEx);


}

void loop() {

}

Using the full code, I receive:

From DIN 1 . SysEx . Roland 14 bytes . F0 41 10 00 00 64 12 18 00 2F 09 7F 00 F7

which is correct.

Using the other method, I receive:

From DIN 1 . SysEx . Lexicon 14 bytes . F0 06 00 05 20 03 00 34 00 5B 18 00 20 F7

byte SysEx [] = {0x41, 0x10, 0x00, 0x00, 0x64, 0x12, 0x18, 0x00, 0x20, 0x09, x, 0x00};
//byte SysEx [] = {sysexStart, PartCommon, levelSet, x, sysexEnd};

An array specifier takes a list of array elements. A byte array's elements must be bytes. Your commented-out code does not compile for me - which compiler are you using?

Like MarkT says the C language simply does not work like you expect it to here:-

//byte SysEx [] = {sysexStart, PartCommon, levelSet, x, sysexEnd};

For example I think you expect sysexStart to add the bytes 0x41, 0x10, 0x00, 0x00, 0x64, 0x12 into the array you are defining. What you get when you just use an array name with no index is a pointer to that array. In other words you don't get the data but the address of where the data is stored. That pointer is 16 bits long, which is not a byte ( 8 bits long ) which is why the compiler complains.

In order for you to get what you want you would have to use:-

byte SysEx [] = {sysexStart[0], sysexStart[1], sysexStart[2], sysexStart[3], sysexStart[4], sysexStart[5], PartCommon[0], ..... and so on

Thanks for your time, guys. That makes more sense now.