MicroPython ESP32 Synth Module: Part 2 :: Receiving Gates

Overview

This series is about developing Eurorack modules using Python and ESP32 boards (or any that supports MicroPython)

In the previous part: MicroPython + ESP32 + Eurorack: Part 1 :: setting up!

We learned how to setup the board and flash the right firmware with some test code using MicroPyton.

In this part we will focus on

  • Gate input (5 volts)
  • GPIO digital output

Pinout

here I am just going to highlight the 2 dev versions I know about, I personally use v1, but you could be using the dev3. so please have a look at these because we are going to need to know which pin is which

ESP32 DEVKIT V1 Pinout
ESP32 WROOM-32 DEVKITC Pinout

Testing GPIO

In this section we are just doing a sanity check to check if the right pin number is configured from out script

so we are going to connect an LED, a resistor to a GPIO pin and flash it, just to make sure we are on the correct pin number on our board.

So for this to be successful we are going to have a look at the pinout of the board, and pick a GPIO pin and connect the LED there.

For this section we need the following components:

1x breadboard
1x LED
1x resistor between (166, 1k Ohm)
1x ESP32 WROOM-32 DEVKIT

The connection diagram looks like this

GPIO 23 — → LED positive leg

LED negative leg —-> resistor — → GND

Now let’s flash the LED with some python code

Connect to serial port

picocom /dev/cu.usbserial-0001 -b115200from machine import Pinled = Pin(23, Pin.OUT)led.value(1) # shall light onled.value(0) # shall light offctrl+a, ctrl+x to exit

if this was successful, then move on to the rest of this article, if not, then double check the pin number. On the pinout diagram the pin number is denoted by a D then a pin number, for my board which is
WROOM-32 devkit v1, I am using D23 which is pin number 23

Receiving gates — 5v

Our next mission for this tutorial is to receive a gate signal and just light on the LED when the gate is active

For us to be able to do this we are going to use this part of schematic to receive the gate and read it in python, then light on the LED on the rising edge, and turn it of on the falling edge of the gate.

We are going to need the following components

1x breadboard/veroboard
2x 100k resistor
1x 10k resistor
1x 3904 NPN Transistor
1x 1n4148 diode
1x Mono Jack 3.5mm (I’m using thonkiconn jacks but any would work as well)

And components from the first part

1x LED
1x resistor between (166, 1k Ohm)

We have made use of the jack to receive the gate in, and using the diode to clip negtive voltages and also deal with impedance issues.

The NPN transistor acts as switch, switches on the circuit when there is an incoming voltage to the base of the transistor.

We are making use of pin 22 to have the gate in, and pin 23 to output to the LED

Our circuit shall look like this:

Now that we have our circuit, we need to operate it using some python code, it’s dead simple and easy to follow.

Our code will consist of 2 classes (GateIn, LED) and the client/main.py script.

Let’s get right to it.

create a file gates.py with the following

Here we have the constructor which sets up the pin, and the method to check if the gate is high.

Next we create the LED class

here we just need the setup, turn on, and turn off the LED

Now our client script which will utilize those classes to check if we are receiving a gate and lights the LED accordingly

now we do the last thing, which is uploading our files to the board.

open up upload.py (from the first part of the series)

and add the includes as follows:

includes = []
includes.append('boot.py')
includes.append('main.py')
includes.append('leds.py')
includes.append('gates.py')

now let’s upload

python3 upload.py

Now I’ll use the clock signal from my keystep pro

eurorack esp32 gate in

and… the light works as expected!!!

Hope you enjoyed this part, next we get into more complex topics, such as CV

--

--

Omar Shaban
MicroPython ESP32 + Eurorack Synthesizer Modules

Omar Shaban is a software engineer, socialpreneur, and sound artist with a passion for programming and open source. He began programming as a youngster in 2002.