Hi, I'm building a custom midi keyboard with an Arduino and I'm hoping to get some help with some kind of noise or interference problem I'm having.
The keyboard has 28 keys, so I'm using an Arduino Mega and a sensor shield. The keys are just push buttons I've connected to ground and input pin via dupont connectors (I'm using the built in pullup resistors). The only other connection is to a 5pin midi connector. This then goes to usb via this
midi to usb cable.
It works fine when I set it up to work with just one button. But when I have all 28 buttons set up in code, the notes come out jittery, like I'm getting some kind of interference. Interestingly, if I remove the line of code that turns notes off, then the jittering goes away (but the instrument doesn't work as intended anymore).
One possibility was that the numerous buttons are somehow interfering (maybe the internal pullup resistors are too weak). However, when I check the serial plotter (set to 9600 baud rate), I don't see any noise. I would try the midi baud rate of 31250 but that's not an option in the plotter. I did try 38400 and that also showed no noise.
Does anyone have any idea what might be causing this jittery sound (perhaps interference)? And any suggestions on how to further trouble shoot it?
Thanks,Sam
Code:
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int ledPin = 13;
int i;
int Pins[28] = { 2, 3, 4, 5, 6, 7, 14, 15, 16, 17, 18, 19, 20, 21, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45 };
int Notes[28] = { 62, 74, 61, 73, 60, 72, 75, 63, 76, 64, 77, 65, 78, 76, 72, 60, 71, 59, 70, 58, 69, 57, 68, 56, 67, 55, 66, 54 };
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
//Serial.begin(9600);
pinMode(ledPin, OUTPUT);
for (i = 0; i < 28; i++){
pinMode(Pins[i], INPUT_PULLUP);
}
}
void loop() {
for (i=0; i < 28; i++){
if (digitalRead(Pins[i]) == LOW) {
//Serial.print(1);
MIDI.sendNoteOn(Notes[i], 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
}
else{
//Serial.print(0);
MIDI.sendNoteOn(Notes[i], 0, 1); // Send a Note (pitch 42, velo 127 on channel 1)
}
}
//Serial.println("");
}