I'm trying to use the USB Host Shield 2.0 library to send a control change message to a MIDI device. The MIDI device is connected to the Teensy 3.2 via a USB Host Shield. The device set to MIDI channel 2.
I'm not sure how the message should be formatted, I think I need an example to understand the how a CC message should look.
I have verified the USB host shield is working and have use it and the library successfully for other projects
From the library's usbh_midi.cpp file:
/////////////////////////
// MIDI MESAGES
// midi.org/techspecs/
//////////////////////////
// STATUS BYTES
// 0x8n == noteOff
// 0x9n == noteOn
// 0xAn == afterTouch
// 0xBn == controlChange
// n == Channel(0x0-0xf)
//////////////////////////
//DATA BYTE 1
// note# == (0-127)
// or
// control# == (0-119)
//////////////////////////
// DATA BYTE 2
// velocity == (0-127)
// or
// controlVal == (0-127)
///////////////////////////////////////////////////////////////////////////////
// USB-MIDI Event Packets
// usb.org - Universal Serial Bus Device Class Definition for MIDI Devices 1.0
///////////////////////////////////////////////////////////////////////////////
//+-------------+-------------+-------------+-------------+
//| Byte 0 | Byte 1 | Byte 2 | Byte 3 |
//+------+------+-------------+-------------+-------------+
//|Cable | Code | | | |
//|Number|Index | MIDI_0 | MIDI_1 | MIDI_2 |
//| |Number| | | |
//|(4bit)|(4bit)| (8bit) | (8bit) | (8bit) |
//+------+------+-------------+-------------+-------------+
// CN == 0x0-0xf
//+-----+-----------+-------------------------------------------------------------------
//| CIN |MIDI_x size|Description
//+-----+-----------+-------------------------------------------------------------------
//| 0x0 | 1, 2 or 3 |Miscellaneous function codes. Reserved for future extensions.
//| 0x1 | 1, 2 or 3 |Cable events. Reserved for future expansion.
//| 0x2 | 2 |Two-byte System Common messages like MTC, SongSelect, etc.
//| 0x3 | 3 |Three-byte System Common messages like SPP, etc.
//| 0x4 | 3 |SysEx starts or continues
//| 0x5 | 1 |Single-byte System Common Message or SysEx ends with following single byte.
//| 0x6 | 2 |SysEx ends with following two bytes.
//| 0x7 | 3 |SysEx ends with following three bytes.
//| 0x8 | 3 |Note-off
//| 0x9 | 3 |Note-on
//| 0xA | 3 |Poly-KeyPress
//| 0xB | 3 |Control Change
//| 0xC | 2 |Program Change
//| 0xD | 2 |Channel Pressure
//| 0xE | 3 |PitchBend Change
//| 0xF | 1 |Single Byte
//+-----+-----------+------------------------
My sample code, which does not work, i.e. the device does not respond. I think I have the hex values/message wrong.
I'm not sure how the message should be formatted, I think I need an example to understand the how a CC message should look.
I have verified the USB host shield is working and have use it and the library successfully for other projects
From the library's usbh_midi.cpp file:
/////////////////////////
// MIDI MESAGES
// midi.org/techspecs/
//////////////////////////
// STATUS BYTES
// 0x8n == noteOff
// 0x9n == noteOn
// 0xAn == afterTouch
// 0xBn == controlChange
// n == Channel(0x0-0xf)
//////////////////////////
//DATA BYTE 1
// note# == (0-127)
// or
// control# == (0-119)
//////////////////////////
// DATA BYTE 2
// velocity == (0-127)
// or
// controlVal == (0-127)
///////////////////////////////////////////////////////////////////////////////
// USB-MIDI Event Packets
// usb.org - Universal Serial Bus Device Class Definition for MIDI Devices 1.0
///////////////////////////////////////////////////////////////////////////////
//+-------------+-------------+-------------+-------------+
//| Byte 0 | Byte 1 | Byte 2 | Byte 3 |
//+------+------+-------------+-------------+-------------+
//|Cable | Code | | | |
//|Number|Index | MIDI_0 | MIDI_1 | MIDI_2 |
//| |Number| | | |
//|(4bit)|(4bit)| (8bit) | (8bit) | (8bit) |
//+------+------+-------------+-------------+-------------+
// CN == 0x0-0xf
//+-----+-----------+-------------------------------------------------------------------
//| CIN |MIDI_x size|Description
//+-----+-----------+-------------------------------------------------------------------
//| 0x0 | 1, 2 or 3 |Miscellaneous function codes. Reserved for future extensions.
//| 0x1 | 1, 2 or 3 |Cable events. Reserved for future expansion.
//| 0x2 | 2 |Two-byte System Common messages like MTC, SongSelect, etc.
//| 0x3 | 3 |Three-byte System Common messages like SPP, etc.
//| 0x4 | 3 |SysEx starts or continues
//| 0x5 | 1 |Single-byte System Common Message or SysEx ends with following single byte.
//| 0x6 | 2 |SysEx ends with following two bytes.
//| 0x7 | 3 |SysEx ends with following three bytes.
//| 0x8 | 3 |Note-off
//| 0x9 | 3 |Note-on
//| 0xA | 3 |Poly-KeyPress
//| 0xB | 3 |Control Change
//| 0xC | 2 |Program Change
//| 0xD | 2 |Channel Pressure
//| 0xE | 3 |PitchBend Change
//| 0xF | 1 |Single Byte
//+-----+-----------+------------------------
My sample code, which does not work, i.e. the device does not respond. I think I have the hex values/message wrong.
Code:
#include <usbh_midi.h>
#include <usbhub.h>
USB Usb;
//USBHub Hub(&Usb);
USBH_MIDI Midi(&Usb);
void setup()
{
Serial.begin(115200);
if (Usb.Init() == -1) {
while (1); //halt
}//if (Usb.Init() == -1...
delay( 200 );
}
void loop()
{
Usb.Task();
ccOn();
delay(400);
ccOff();
delay(100);
}
//note On
void controlChangeOn(void)
{
uint8_t buf[3];
buf[0] = 0x1B; // Control change type message on channel 2 ??
buf[1] = 0x51; // control change #81
buf[2] = 127; // turn effect off
Midi.SendData(buf);
}
//note Off
void controlChangecOff(void)
{
uint8_t buf[3];
buf[0] = 0x1B; // Control change type message on channel 2 ??
buf[1] = 0x51; // control change #81
buf[2] = 0; // turn effect off
Midi.SendData(buf);
}
Last edited: