In one of my previous posts I gave an overview on how we can connect an microcontroller to a MIDI Device.

The simplest solution is to connect the MIDI Keyboard to the PC and use a FTDI serial adapter to communicate with your microcontroller. Because the keyboard is only sending data, we only need to connect the TX pin on the FTDI to the RX pin on the AudioKit board. Please make sure that the device is set to 3V (because 5V might destroy your AudioKit).

The PC Software

On the PC you need to run a software tool that forwards the midi messages from the keyboard to the serial port. I am using Hairless MIDI Serial Bridge.

The Arduino Sketch

For the example I am using my Arduino MIDI library.

#include "Midi.h"

#define RXD2 21
#define TXD2 22

MidiCallbackAction action;
MidiStreamIn in(Serial, action);

void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
  Serial.print("onNoteOn: ");

void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
  Serial.print("onNoteOff: ");

void setup() {
  Serial2.begin(119200, SERIAL_8N1, RXD2, TXD2);
  action.setCallbacks(onNoteOn, onNoteOff);

void loop() {


The ESP32 AudioKit provides a RX0 and TX0 pin, but this is already used by the USB connection and in order to avoid any conflicts we use any separate unused pins (e.g. GPIO21 or GPIO22).


Final Comments

You can replace the ‘Hairless MIDI Serial’ tool with a simple Python Program. Details can be found in my next blog.

I this example I concentrated on using the AudioKit as synthesizer and processing inbound MIDI messages from a MIDI keyboard. Naturally we can use the AudioKit also as MIDI source to generate MIDI messages. You can find the corresponding code in the examples directory.

The examples directory also contains a demo how to build as simple synthesizer with the STK framework.

If you want to use these examples in the AudioKit, you just need to adapt the Serial interface with the approach described in this blog.

Categories: ArduinoMachine Sound

1 Comment

Andreas · 9. October 2023 at 21:40

I think I just found the answer to my question:

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *