Download free music MP3s on genuine quality, the world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, The world’s largest online music catalogue, powered by your scrobbles. Free listening, videos, photos, stats, charts, biographies and concerts. stats, charts, biographies and concerts.
Monday, December 9, 2024
ESP32 Simple MIDI Monitor
This project started as a bit of a test for my ESP32 WROOM Mozzi Experimenter PCB but ended up a little more functional, so I thought it worth writing up in its own right. Warning! I strongly recommend using old or second hand equipment for your …
This project started as a bit of a test for my ESP32 WROOM Mozzi Experimenter PCB but ended up a little more functional, so I thought it worth writing up in its own right.
Warning! I strongly recommend using old or second hand equipment for your experiments. I am not responsible for any damage to expensive instruments!
If you are new to microcontrollers, see the Getting Started pages.
It is very similar to the Simple MIDI Monitor but has a couple of significant changes to support the ESP32 and be a little more full-featured.
First and foremost, the ESP32 has several UART interfaces - three to be exact (later ESP32 models have two, but the original ESP32 I'm using has three). By default, UART0 is connected to the USB port, UART1 is connected to onboard flash memory, and UART2 is available for use.
In Arduino terms, these correspond to Serial, Serial1, and Serial2.
My ESP32 WROOM Mozzi Experimenter PCB supports UART0 and UART2, although I've slightly erroneously labelled it UART1 on the PCB! But these two are mapped as follows:
Board Label
Real Port
TX
RX
UART 0
UART 0
1
3
UART 1
UART 2
17
16
One quirk - it would appear from the ESP32 Arduino core that the default pins for UART2 are RX=4, TX=25 (see HardwareSerial.h), yet in the pinout for the module I'm using (see here), it shows GPIO17 and 16 for UART2, so that is what I wired up in my PCB.
To initialise the serial port using Serial2 thus requires changing the TX/RX pin. Unfortunately this cannot be done (as far as I could see) when initialsing the MIDI library - which always calls Serial.begin() automatically.
So I had to re-initialise the serial port with the new pins as shown below. This works as the ESP32 library will detach and re-attach the serial pins if already configured.
Once initialised, the main loop runs the following sequence:
loop(): IF MIDI.read() THEN IF MIDI channel message THEN Print out details of the MIDI channel message ELSE Print out just the command from a system message
I've written a number of helper functions to make printing the details easier. It will also light up the on-board LED (on D2) when a NoteOn is received and turn if off on NoteOff.
The code will also support using UART0 (Serial), but in that case all serial port printing to the seral monitor is disabled.
At the end, I turned on MIDI sync pulses and caught a few.
Find it on GitHub here.
Closing Thoughts
Working out how to use the second serial port wasn't quite as straight forward as I was expecting, but I got there in the end.
Curiously there doesn't seem to be much information about it online that I could easily find, and certainly not very much about how to use it with the MIDI library with custom pins.
I don't know why the core has different pins by default to those suggested in the pinout of my module, but seeing as the ESP32 has quite a comprehensive GPIO multiplexing setup, I'm not surprised.
No comments:
Post a Comment