Hi. I'm making a midi controller. It was all working on an Uno R3, but that board was too slow so I've just bought a Nano ESP32 (I think it's a legit one?) .
The midi controller sends data through USB Serial to my PC, Hairless midi receives it and sends it to Midi Loop, which picks it up in Ableton Live. This was all working fine on the Uno R3.
For the ESP32, it didn't work right away, so I've been searching and trying things out. I've uninstalled and reinstalled the VCP / FTDI drivers, then I saw that they aren't used for ESP32, so I installed Silicon Labs CP210x VCP drivers. I updated the firmware on my ESP32 using Zadig - to LibusbK.
I'm quite the newb, so this is all totally new for me. I naively thought my ESP32 would work right out the box!
Thanks, hope you can help. I want to get back to dialing in my air sensors!
I did check the baud rate in Hairless, I've set it to 115200 as per sketch.
I may have installed some incorrect drivers / firmware by accident.
I have made some updates to my code, which chat GPT recommended. This is my code:
#include <MIDI.h>
// Create a MIDI instance
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
// Define pin numbers
const int button1Pin = 2; // Valve 1
const int button2Pin = 3; // Valve 2
const int button3Pin = 4; // Valve 3
const int pitchButtonPin = 5; // Pitch change
const int pressureSensorPin = 36; // ADC1 channel 0, GPIO36
int currentNote = 60; // Middle C
const int velocity = 127; // Maximum velocity
bool notePlaying = false;
void setup() {
// Initialize buttons as input
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
pinMode(pitchButtonPin, INPUT_PULLUP);
// Initialize MIDI communication
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(115200); // USB Serial communication
Serial1.begin(31250, SERIAL_8N1, -1, 17); // MIDI Serial communication on GPIO 17 for TX
}
void loop() {
// Read button states
bool button1State = digitalRead(button1Pin) == LOW;
bool button2State = digitalRead(button2Pin) == LOW;
bool button3State = digitalRead(button3Pin) == LOW;
bool pitchButtonState = digitalRead(pitchButtonPin) == LOW;
// Read pressure sensor
int pressureValue = analogRead(pressureSensorPin);
// Calculate base note based on valve combination
int baseNote = 60; // Default to Middle C
if (button1State) baseNote -= 2; // Valve 1
if (button2State) baseNote -= 1; // Valve 2
if (button3State) baseNote -= 3; // Valve 3
// Adjust for pitch button
if (pitchButtonState) baseNote += 7; // Perfect 5th
// Determine if we should play the note
if (pressureValue > 2048) { // Adjust threshold as needed (ESP32 ADC range is 0-4095)
if (!notePlaying || currentNote != baseNote) {
if (notePlaying) {
sendMIDIMessage(0x80, currentNote, 0); // Note Off
}
sendMIDIMessage(0x90, baseNote, velocity); // Note On
currentNote = baseNote;
notePlaying = true;
}
} else {
if (notePlaying) {
sendMIDIMessage(0x80, currentNote, 0); // Note Off
notePlaying = false;
}
}
delay(10); // Small delay to debounce buttons and avoid overwhelming the serial communication
}
void sendMIDIMessage(byte command, byte pitch, byte velocity) {
Serial1.write(command);
Serial1.write(pitch);
Serial1.write(velocity);
}