-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
examples/3. MIDI Interfaces/BLEMIDI-Adapter/BLEMIDI-Adapter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Turns an Arduino into a Bluetooth Low Energy (BLE) to 5-pin DIN MIDI adapter. | ||
* | ||
* @boards Nano 33 IoT, Nano 33 BLE, ESP32, ESP32-S3 | ||
* | ||
* Connections | ||
* ----------- | ||
* | ||
* - TXD: connected to a MIDI 5-pin DIN output connector | ||
* (with series resistor, possibly through a buffer) | ||
* - RXD: connected to a MIDI 5-pin DIN input connector | ||
* (with an optocoupler) | ||
* | ||
* See https://midi.org/specifications/midi-transports-specifications/5-pin-din-electrical-specs | ||
* for the schematic, optocoupler models and resistor values. | ||
* | ||
* Behavior | ||
* -------- | ||
* | ||
* - The Arduino will advertise itself as a Bluetooth Low Energy MIDI device | ||
* with the name `MIDI Adapter`. | ||
* - When you connect to the Arduino using your phone or computer, the built-in | ||
* LED turns on to indicate that the connection was successful. | ||
* - Any MIDI messages sent to the Arduino over BLE are sent out to the 5-pin | ||
* DIN output connector. | ||
* - Any MIDI messages sent to the Arduino through the 5-pin DIN input connector | ||
* are sent over BLE. | ||
* | ||
* @see @ref md_pages_MIDI-over-BLE | ||
* @see @ref midi-tutorial | ||
* | ||
* Written by PieterP, 2024-01-21 | ||
* https://github.com/tttapa/Control-Surface | ||
*/ | ||
|
||
#include <Control_Surface.h> | ||
|
||
// Instantiate a MIDI over BLE interface | ||
BluetoothMIDI_Interface midi_ble; | ||
// 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() { | ||
// Change the name of the BLE device (must be done before initializing it) | ||
midi_ble.setName("MIDI Adapter"); | ||
// Manually route MIDI input from the serial interface to the BLE interface, | ||
// and the MIDI input from the BLE interface to the serial interface | ||
midi_ser | pipes | midi_ble; | ||
// Initialize the MIDI interfaces | ||
MIDI_Interface::beginAll(); | ||
// Initialize the built-in LED | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
// Continuously poll all interfaces and route the traffic between them | ||
MIDI_Interface::updateAll(); | ||
// Display the connection status using the built-in LED | ||
digitalWrite(LED_BUILTIN, midi_ble.isConnected() ? HIGH : LOW); | ||
} |
53 changes: 53 additions & 0 deletions
53
examples/3. MIDI Interfaces/USBMIDI-Adapter/USBMIDI-Adapter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Turns an Arduino into a USB to 5-pin DIN MIDI adapter. | ||
* | ||
* @boards AVR USB, Due, Nano 33 IoT, Nano 33 BLE, Pi Pico, ESP32-S3, Teensy 3.x | ||
* | ||
* Connections | ||
* ----------- | ||
* | ||
* - TXD: connected to a MIDI 5-pin DIN output connector | ||
* (with series resistor, possibly through a buffer) | ||
* - RXD: connected to a MIDI 5-pin DIN input connector | ||
* (with an optocoupler) | ||
* | ||
* See https://midi.org/specifications/midi-transports-specifications/5-pin-din-electrical-specs | ||
* for the schematic, optocoupler models and resistor values. | ||
* | ||
* Behavior | ||
* -------- | ||
* | ||
* - The Arduino will show up as a USB MIDI device. | ||
* - Any MIDI messages sent to the Arduino over USB are sent out to the 5-pin | ||
* DIN output connector. | ||
* - Any MIDI messages sent to the Arduino through the 5-pin DIN input connector | ||
* are sent over USB. | ||
* | ||
* @see @ref md_pages_MIDI-over-USB | ||
* @see @ref midi-tutorial | ||
* | ||
* Written by PieterP, 2024-01-21 | ||
* https://github.com/tttapa/Control-Surface | ||
*/ | ||
|
||
#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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters