USB Midi Controller

Hi there!

I am trying to build a USB MIDI controller with a Pro Micro and four touch sensors.

Here is whats wrong:

I have the touch sensors sending ON notes when I press them but my problem is that it is constantly sending OFF notes, which doesn't give a very good sound and means the four notes I am using on my softsynth don't work when I press them on my computer. you'll see why in my code:

#include "Midi_Functions.h"

const int but1 = 2;
const int but2 = 3;
const int but3 = 4;
const int but4 = 5;



void setup() {
  pinMode(but1, INPUT_PULLUP);
  pinMode(but2, INPUT_PULLUP);
  pinMode(but3, INPUT_PULLUP);
  pinMode(but4, INPUT_PULLUP);
}

void loop() {
  MIDIbutton(but1, 36, 64);
  MIDIbutton(but2, 37, 64);
  MIDIbutton(but3, 38, 64);
  MIDIbutton(but4, 39, 64);
}

And the MIDI_Functions.h file:

#include "MIDIUSB.h"

//MIDI Notes
void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

//Buttons
bool triggerState = false;

void MIDIbutton(int Pin, int Note, int Velocity){
  if (!triggerState && digitalRead(Pin) == HIGH) {
    triggerState = true;
    noteOn(0, Note, Velocity);     
    MidiUSB.flush();   
  } else {
    noteOff(0, Note, 0);
  }

  if (triggerState && digitalRead(Pin)) {
    triggerState = false;   
  }
}

I am not sure how to send a MIDI OFF note only once after the touch sensor is released, and help would be appreciated.

I can't see any reference to a touch sensor in any of the codes you posted.

What sort of touch sensor are you using? Where is it initialised and when is it read?

Did the MIDIUSB library come with any examples?

Hi there, sorry I didn't post anything about the touch sensors.

They are TTP223 Capacative Touch Sensors and here is a link to where I bought them.

As you can see they have GND, VCC, and I/O. I have GND and VCC to GND and VCC on the Pro Micro, and in the code i callde them "buttons", because they effectively act the same way.

And no, the MIDI USB library had no examples for buttons.

Thanks for supplying more detail. I have attached to this post a PDF of the data sheet for you to read. Just double click it to read it.

TTP223-Datasheet.pdf (245.7 KB)

Note what it says about not touching anything while it powers yo so it can auto calibrate

Now I found this link to perhaps a more verbose web site to show you how to read them and what to do with those links on the board.

TTP223 Explained.

However, I have my reservations about operating it at 5V, so close to the absolute maximum value of 5.5V. The data sheet shows 3V as the recommended working value.

Anyway way what I would do is rather jump in with the whole lot all at once, take a step by step approach. Write some code that tests the output of just one sensor and get that to work first. You might want to look at the State change tutorial in the IDE to get an idea of how the sensor can work, and the effect of continuously reading them.

It would be good to see a photograph of your wiring setup as well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.