genuinequality

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 …
Read on blog or Reader
Site logo image Simple DIY Electronic Music Projects Read on blog or Reader

ESP32 Simple MIDI Monitor

By Kevin on December 9, 2024

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.

Parts list

  • ESP32 WROOM-DA module or DevKit (see photos).
  • ESP32 WROOM Mozzi Experimenter PCB.
  • Serial MIDI interface.

The Circuit

This is using my ESP32 WROOM Mozzi Experimenter PCB but it would be possible to hook up a 3V3 compatible MIDI module (see Ready-Made MIDI Modules) to the following pins on the ESP32 module:

GPIO 16 MIDI Receive
GPIO 17 MIDI Transmit
3V3 MIDI VCC
GND MIDI GND

The UART configuration should be set to UART 1 as shown below.

The Code

This code uses the Arduino MIDI Library from https://github.com/FortySevenEffects/arduino_midi_library.

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.

MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, MIDI);

void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial2.begin(31250, SERIAL_8N1, 16, 17);
}

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.

Here is some example output.

1	0x90 NoteOn	0x35	0x60
1 0xE0 PBend 0x00 0x60
1 0xE0 PBend 0x00 0x68
1 0xE0 PBend 0x00 0x70
1 0x80 NoteOff 0x32 0x40
1 0x80 NoteOff 0x35 0x40
1 0x80 NoteOff 0x34 0x40
1 0x80 NoteOff 0x30 0x40
1 0xC0 ProgCh 0x00
1 0xB0 CtrlCh 0x00 0x00
1 0xB0 CtrlCh 0x20 0x00
1 0xC0 ProgCh 0x1E
3 0xB0 CtrlCh 0x0B 0x00
0xFB
0xF8

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.

Kevin

Comment
Like
You can also reply to this email to leave a comment.

Simple DIY Electronic Music Projects © 2024.
Manage your email settings or unsubscribe.

WordPress.com and Jetpack Logos

Get the Jetpack app

Subscribe, bookmark, and get real‑time notifications - all from one app!

Download Jetpack on Google Play Download Jetpack from the App Store
WordPress.com Logo and Wordmark title=

Automattic, Inc.
60 29th St. #343, San Francisco, CA 94110

Posted by BigPalaceNews at 1:03 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
View mobile version
Subscribe to: Post Comments (Atom)

Search This Blog

About Me

BigPalaceNews
View my complete profile

Blog Archive

  • October (69)
  • September (112)
  • August (116)
  • July (96)
  • June (100)
  • May (105)
  • April (95)
  • March (131)
  • February (111)
  • January (104)
  • December (98)
  • November (87)
  • October (126)
  • September (104)
  • August (97)
  • July (112)
  • June (113)
  • May (132)
  • April (162)
  • March (150)
  • February (342)
  • January (232)
  • December (260)
  • November (149)
  • October (179)
  • September (371)
  • August (379)
  • July (360)
  • June (385)
  • May (391)
  • April (395)
  • March (419)
  • February (356)
  • January (437)
  • December (438)
  • November (400)
  • October (472)
  • September (460)
  • August (461)
  • July (469)
  • June (451)
  • May (464)
  • April (506)
  • March (483)
  • February (420)
  • January (258)
  • December (197)
  • November (145)
  • October (117)
  • September (150)
  • August (132)
  • July (133)
  • June (117)
  • May (190)
  • January (48)
Powered by Blogger.