ruby.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
If you are interested in the Ruby programming language, come join us! Tell us about yourself when signing up. If you just want to join Mastodon, another server will be a better place for you.

Administered by:

Server stats:

1.1K
active users

#esp32

33 posts15 participants3 posts today

I'm having a look at an ESP32-A1S audio kit that is widely available.

There is what looks like a handy GPIO breakout on the board.

Until you realise that 4 of the pins are pulled high for use with the buttons; 1 is a strapping pin and has to be left floating to use the built-in audio codec; 1is the shutdown pin for the amplifier; and 2 are the USB RX/TX link so their use is limited too.

So from the 9 IO pins broken out, only one is (as far as I can see) actually free to use!

#ESP32-A1S

Using a Cheap 5V MIDI Interface at 3V3

I had a query about using one of the common Arduino MIDI Shields with an ESP32 and when I looked into it, this is where I got to.

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 Arduino, see the Getting Started pages.

Parts list

  • Arduino Uno MIDI Shield
  • ESP32 or other 3V3 microcontroller
  • 1x 22KΩ, 1x 33KΩ resistors for MIDI IN
  • 1x 10Ω, 1×30Ω resistors for MIDI OUT
  • Breadboard and jumper wires

Arduino MIDI Shield

These shields are available very cheaply and designed to plug directly onto an Arduino Uno. They are a variation of an original Olimex open source design (details here) but details of the specifics of this shield seem pretty sparse. But it isn’t too complex to figure out.

Essentially it is a 6N139-based 5V MIDI IN circuit and a non-buffered 5V MIDI OUT and THRU. The boards include a switch to cut off RX from MIDI to allow for sketch uploading. There is often a footprint for a button for RESET which may or may not be populated, and there is a block of breakout connectors for all the Arduino’s IO pins.

I did eventually happen upon an uncredited schematic in a random online cloud service file storage, so I’ve copied it over here.

And mapping this over to the board itself I found this PCB diagram. Note this has a URL for “soliddigi” on it, but that doesn’t seem to exist (or do anything) that I could see.

But whilst on the topic of this board, we can map out the IO pin breakouts for future reference too by simply examining the underside of the board:

From this we can see the following pinouts for the board.

Anyway, back to MIDI…

Converting MIDI IN

The output (to the Arduino) from the MIDI IN circuit of this board is a UART RX connection pulled high to 5V. The easiest way to drop that to 3V3 for use with a 3V3 logic system is to use a resistor divider as shown below.

The MIDI shield will still need to be powered by 5V but the output from the RX pin will now be dropped by the ratio 33K/(22K+33K) which is approximately 0.6. So 5V x 0.6 = 3V.

The choice of resistor for this specific application is relatively arbitrary as it is the ratio that is important, but it should be remembered that this is connecting both the optoisolator’s output (RX) and the microcontrollers IO pin (GP19 above) to GND so there will be limits on the amount of current that can be sourced from the two IO pins and that can be sunk into GND.

Converting MIDI OUT

Converting MIDI OUT isn’t quite so easy unfortunately. If the MIDI interface had included a buffer, like the 74HCT14 I’ve used in the past, then no conversion would be necessary – a 3V3 logic signal can drive that directly and the output would be a 5V signal to the rest of the MIDI circuit.

But it doesn’t – it is a directly connected 5V-expecting MIDI OUT circuit involving two 220Ω resistors. If this is driven from a 3V3 level then it is unlikely that there would be enough current to drive the optoisolator at the other end of the MIDI link.

The basic calculation goes as follows (see my MIDI Connections Cheat Sheet for details of the circuits) – this assumes one 220Ω resistor on the receiving side and two on the sending side as per the MIDI spec, and a typical 1.7V drop across the optoisolator.

For 5V operation, from Ohm’s law: Current = (5 – 1.7) / (220+220+200) = 5mA

For 3V3 operation: Current = (3.3 – 1.7) / (220+220+200) = 2mA

This is why the MIDI spec recommends 10Ω and 30Ω resistors for a 3V3 logic OUT circuit:

For proper 3V3 operation: Current = (3.3 – 1.7) / (220+30+10) = 6mA

Really, the easiest method, assuming the MIDI connectors/hardware are required to be used “as is” would be to include a 74HCT14 (the HCT variant, not the HC version) as a buffer by passing the 3V3 signal through two of the inverters.

But at this point, as this is just a couple of resistors, I’d probably look to remove the two 220Ω resistors in the OUTPUT circuit and attempt to patch in a 10Ω and 30Ω instead with the 30Ω pulling up to 3V3 rather than 5V.

Patching the Shield

Given all the above, I believe it is possible to patch this shield to support 3V3 logic operation by performing the following:

  • Remove R3 and R4.
  • Cut the track to the RX Pin.
  • Add 10Ω between MIDI OUT R3 connector and TX.
  • Add 33Ω between MIDI OUT R4 connector and 3V3.
  • Add 22KΩ between RX and the centre pin of the ON/OFF switch (check this with a meter though – it was the middle pin for me!).
  • Add 33KΩ between RX and GND.

WARNING: All of this is theoretical. I’ve not actually done it myself.

Step 1: Remove R3, R4, cut RX track.

Step 2: Add resistors.

Note: I don’t believe that anything has to be done to the THRU as it is taken directly off the RX side of the 6N139, so that will continue to work (as I understand things) off the 5V circuit directly.

Closing Thoughts

Given the number of off-the-shelf 3V3 MIDI boards now available, I suspect in most cases acquiring one directly would be the better option to the above.

But having said that, these boards are available so cheaply and widely that it is worth considering. Also, there are 3V3 logic level boards in Uno form factor, so having a 3V3 version of the shield would be useful in any case.

But I repeat, other than testing the resistor divider on RX, I’ve not tested any of the modifications to the board itself. Do let me know if you’re brave enough to give it a go 🙂

At some point I might make my own 3V3 Uno format shield PCB…

Kevin

PrettyOTA (1.0.6) for esp32 by LostInCompilation

➡️ github.com/LostInCompilation/P

OTA (over the air) update library. A modern looking OTA web interface for easy updates, rollbacks and infos about your board and firmware, directly inside your browser.

A better looking Web OTA updater for ESP32 microcontrollers - LostInCompilation/PrettyOTA
GitHubGitHub - LostInCompilation/PrettyOTA: A better looking Web OTA updater for ESP32 microcontrollersA better looking Web OTA updater for ESP32 microcontrollers - LostInCompilation/PrettyOTA

PrettyOTA (1.0.5) for esp32 by LostInCompilation

➡️ github.com/LostInCompilation/P

OTA (over the air) update library. A modern looking OTA web interface for easy updates, rollbacks and infos about your board and firmware, directly inside your browser.

A better looking Web OTA updater for ESP32 microcontrollers - LostInCompilation/PrettyOTA
GitHubGitHub - LostInCompilation/PrettyOTA: A better looking Web OTA updater for ESP32 microcontrollersA better looking Web OTA updater for ESP32 microcontrollers - LostInCompilation/PrettyOTA