MIDI Controller Note Data Issue

Hello,

This is my first post, it's nice to be part of the community. I'm new to this, so apologies if I'm missing something.

I'm making a MIDI controller using and Arduino Uno and buttons to send note data to a synthesiser, and I'm having some issues with it. From what I can see using a MIDI monitoring program, the circuit is sending data but not the correct information - it isn't sending note data. It's definitely sending something, but it's not actually making any notes. The code and schematic is from this website, and I'll put it below as well: How to Make a MIDI Controller with an Arduino

I have downloaded the Arduino MIDI Library v5.0.2 as stated, and I've gone over the circuit closely and am confident it is correct. There are no error messages when I'm verifying the code.

Here is the code I'm using:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
const int buttonOne = 6; // assign button pin to variable
const int buttonTwo = 7; // assign button pin to variable
MIDI_CREATE_INSTANCE(HardwareSerial,Serial, midiOut); // create a MIDI object called midiOut
void setup() {
  pinMode(buttonOne,INPUT); // setup button as input
  pinMode(buttonTwo,INPUT); // setup button as input
  Serial.begin(31250); // setup MIDI output
}
void loop() {
  if(digitalRead(buttonOne) == HIGH) { // check button state
    delay(10); // software de-bounce
    if(digitalRead(buttonOne) == HIGH) { // check button state again
      midiOut.sendControlChange(56,127,1); // send a MIDI CC -- 56 = note, 127 = velocity, 1 = channel
      delay(250); 
    }
  }
 
  if(digitalRead(buttonTwo) == HIGH) { // check button state
    delay(10); // software de-bounce
    if(digitalRead(buttonTwo) == HIGH) { // check button state again
      midiOut.sendControlChange(42,127,1); // send a MIDI CC -- 42 = note, 127 = velocity, 1 = channel
      delay(250);
    }
  }

(I'm aware I'm meant to auto-format the code, but I can't find where to do that - sorry)

Here's the layout:

Using test code on the website, the two buttons are working as they should, so it's an isolated issue with the MIDI. Here is the information being received by the MIDI monitoring program by running the MIDI out into my audio interface. The channel number matches the code, but as you can see there is no note data recognised. Data 1 changes from 38 to 2A when I press and hold button 2 instead of button 1 (though I'm not quite sure what the Data 1 means).

If anyone could point me in the right direction, that would be great. Thanks!

1: missing "}" in void loop().
2: Tools -> Auto Format (or Ctrl+T).

tmrj2:
it isn't sending note data. It's definitely sending something, but it's not actually making any notes.
[...]

midiOut.sendControlChange(42,127,1); // send a MIDI CC -- 42 = note, 127 = velocity, 1 = channel

Your code is sending MIDI Control Change messages, not MIDI Note messages. See the MIDI library documentation for functions to send notes.

Don't use delays for debouncing. 250 milliseconds delay is unacceptable when sending MIDI notes to a synthesizer.

The pull-down resistors are redundant, you have built-in pull-up resistors.

You might be interested in this NoteButton.ino example.

Pieter

Using test code on the website, the two buttons are working as they should,

No they are not. This code:-

  pinMode(buttonOne,INPUT); // setup button as input
  pinMode(buttonTwo,INPUT); // setup button as input

means that the buttons when not pressed are floating so the pins can read anything due to picking up interference.

Remove the resistors attached to the button and connect them directly to ground. Then use this code in the setup function:-

  pinMode(buttonOne,INPUT_PULLUP); // setup button as input with the internal pull ups enabled 
  pinMode(buttonTwo,INPUT_PULLUP); // setup button as input

Your display is showing that you are sending exactly what you code says it should. As PieterP says you are not sending note on messages but control messages. These are used to change parameters like the channel volume and Tremolo. They do not in themselves make any sound. For that you need to send a note on message to start a note going, followed by a note off message to stop a note playing.

Thanks for all the replies, I've had a go at improving it with the suggestions in mind, but I think the basis of the code isn't really up to the task, so I'll be trying somewhere else to start.

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