New to Coding. I just want to make 4 midi push buttons work. I have loaded what was recommended and I am at a loss. Not sure what else to do.

Diggable

Member
/* Buttons to USB MIDI Example

You must select MIDI from the "Tools > USB Type" menu

To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"

This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;

// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5); // which is appropriate for good
Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5); // to rapid touch, you can
Bounce button7 = Bounce(7, 5); // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);

void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP); // Teensy++ 2.0 LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP); // Teensy 2.0 LED, may need 1k resistor pullup
}

void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();

// Check each button for "falling" edge.
// Send a MIDI Note On message when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4
}
if (button3.fallingEdge()) {
usbMIDI.sendNoteOn(63, 99, channel); // 63 = D#4
}
if (button4.fallingEdge()) {
usbMIDI.sendNoteOn(64, 99, channel); // 64 = E4
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4
}
if (button6.fallingEdge()) {
usbMIDI.sendNoteOn(66, 99, channel); // 66 = F#4
}
if (button7.fallingEdge()) {
usbMIDI.sendNoteOn(67, 99, channel); // 67 = G4
}
if (button8.fallingEdge()) {
usbMIDI.sendNoteOn(68, 99, channel); // 68 = G#4
}
if (button9.fallingEdge()) {
usbMIDI.sendNoteOn(69, 99, channel); // 69 = A5
}
if (button10.fallingEdge()) {
usbMIDI.sendNoteOn(70, 99, channel); // 70 = A#5
}
if (button11.fallingEdge()) {
usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5
}

// Check each button for "rising" edge
// Send a MIDI Note Off message when each button releases
// For many types of projects, you only care when the button
// is pressed and the release isn't needed.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel); // 60 = C4
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOff(63, 0, channel); // 63 = D#4
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOff(64, 0, channel); // 64 = E4
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4
}
if (button6.risingEdge()) {
usbMIDI.sendNoteOff(66, 0, channel); // 66 = F#4
}
if (button7.risingEdge()) {
usbMIDI.sendNoteOff(67, 0, channel); // 67 = G4
}
if (button8.risingEdge()) {
usbMIDI.sendNoteOff(68, 0, channel); // 68 = G#4
}
if (button9.risingEdge()) {
usbMIDI.sendNoteOff(69, 0, channel); // 69 = A5
}
if (button10.risingEdge()) {
usbMIDI.sendNoteOff(70, 0, channel); // 70 = A#5
}
if (button11.risingEdge()) {
usbMIDI.sendNoteOff(71, 0, channel); // 71 = B5
}

// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
}
 
Here is what I have connected. Teensy USB_MIDI is what its set up for.
 

Attachments

  • 1732759344127blob.jpg
    1732759344127blob.jpg
    82.8 KB · Views: 24
Teensy 4.0 and not sure how to hook up the buttons. I plugged a push button between pin 0 and pin 1. Nothing happens.
 
Maybe this tutorial can help? It explains how to connect pushbuttons and how to troubleshoot them.


If you're unsure how to wire the buttons, or if you're using those 2 wires as a button and it's not working, the troubleshooting info in that tutorial can help you use a voltmeter and the serial monitor to get the pushbutton working.

With all projects, when things don't work the process usually involves testing each piece as separately as possible with the simplest test you can do. Then when you know the individual pieces are working (like pushbuttons) combine them with other parts (USB MIDI) which you have also tested alone.
 
What have you connected the Teensy USB to in order to receive/detect the midi messages? The code is sending note C4 on MIDI Channel 2 (internal channel 1).
If you're sending to a synthesizer/DAW/whatever, it must be set receive the correct channel.

Pete
 
FYI I tried your code on a Teensy 2 connected to Windows 10 and with a piece of wire as a button on Pin 0.
MIDI-Ox on Windows sees the midi messages.
So the code works as advertised. There must be something wrong with how you are detecting the MIDI message.

Pete
 
I am very new to coding. Im an electrician by trade, my buttons are standard momentary buttons. Im trying to just set up 4 midi buttons to stop and start a sequence. No synth just for buttons. Im trying to understand how tis board works. I will watch the tutorial. Do I attach a button to O and 1?
 
The code you posted sends a MIDI NoteOn when you press a button and a MIDI NoteOff when you release the button.
The message is sent to whatever you have connected the Teensy USB port to.

What is the Teensy USB connected to?
What is playing "a sequence"?

Pete
 
Again, recommend using Arduino Serial Monitor (not USB MIDI) and a DC voltmeter to troubleshoot the pushbutton, as explained in the tutorial.

Return to USB MIDI only after you are 100% certain the pushbutton is working.
 
Good morning. I followed the tutorial and I managed to set the button per the example and was able to get the 3.3 volts to the positive and negative of the button. Per my midi software. I'm using the 4 buttons to start, stop, next sequence, previous sequence. That is easy to do in the software, but I need the buttons to send the midi notes to do so. The software is in the computer connected thru a serial port.
 
I doubt that sending midi notes will affect the sequence. It is more likely to need a Program Change or Control Change message. Which midi software are you using and does it have any documentation?

Pete
 
For USB MIDI troubleshooting, have you run something like MIDI-OX (Windows) or "aseqdump" (Linux) which shows ALL MIDI messages your computer receives?

This is important because the MIDI messages that example program transmits may be different from whatever messages are expected by the software you're running on your PC. Much like how you can't see voltage without a multimeter, for troubleshooting whether MIDI is really working you need a program which shows you ALL messages, rather than a program which responds to only some of them and ignores all others.
 
I got the press button code loaded and when the button is pushed it goes from off to on and stays on. it doesn't turn back off. So Im getting close... midi Ox is for windows. Is there a midi monitor for Mac? I have the Controller attached to wind a
Midi-Ox and this is the message I got. Also Got the buttons to have 8 pressed 7 not pressed.
 

Attachments

  • pressed-1.jpg
    pressed-1.jpg
    478.5 KB · Views: 16
  • midi ox.jpg
    midi ox.jpg
    275.1 KB · Views: 14
  • board(1).jpg
    board(1).jpg
    282.1 KB · Views: 30
Looks like your wiring may have some misunderstanding.

Here are 4 specific suggestions:

1732994542404.png


1: Eliminate this wire to the 3.3V power. Buttons only need to connect between digital pins and GND. Do not use any 3.3V connection, as it is unnecessary and only gives opportunity for things to go very wrong (eg, shorting out the power supply).

2: Every pushbutton connects to GND. Remove these 5 wires, which connect to 2 of the digital pins. Instead, connect all pushbuttons to the GND row on the bottom of your breadboard (where the gray wire is already connected). Check the first photo on this tutorial page for the way breadboard connections are made.

3: Connect the non-GND wire from button #1 to digital pin 0. (or any other digital pin, if you have changed the pin number in the code - but the example program uses pin 0 for the first button)

4: Connect the non-GND wire from button #2 to digital pin 1. (or any other digital pin, if you have changed the pin number in the code - but the example program uses pin 1 for the second button)
 
Maybe I'm over-thinking things from your photo, but perhaps this wiring may have come from a misunderstanding that 3.3V power is needed for logic high. If so, before you do anything more, please read "Connecting A Pushbutton" on the pushbuttons tutorial page. The critically important concept is about pullup resistors, which provide logic high when the button is normally open. Logic high should NOT come from a direct connection to 3.3V power. For this project, you should connect nothing to that 3.3V power pin!

If you scroll down to "Built In Pullup Resistor", you'll see this suggested wiring and the example code is using the resistors inside the chip, so you don't need to add your own resistors (but using real resistors can give a stronger signal which might help in extremely noisy environments). But understanding the nature of those pullup resistors is important for correctly connecting a normally open mechanical switch.
 
Hi Diggable.
It looks like you want to get this project going as fast as possible.
Here is my take on your question and thread replies so far and where you could go from here to get the best results.

The code comments in your original post provide what i belive are adequate instructions on how to make the electrical connections for you're switch. If you would like to know more ask and somebody like me will reply.

Toyosm was quick to give you the solution, If you do not understand what he means, ask and somebody like me will reply.

PaulStoffregen provides you a way to understand the concept of pushbuttons and pull-ups in more detail in what looks to be a very good guide. You provide some test results which i doubt were suggested in the guide so you could provide more details on what you were testing and someone like me will help.

Genuinely interested in helping like everyone here.
Gavin.
 
Good morning Gavin and thank you for your response. I have been working on the unit based on the information given, but what I have noticed is there are other components added to the tutorials given. That seems to complicate the basics. Although to many that is basic, but to a newbie like myself, the simplest explanation on the board would be helpful. I did look at the wiring diagram Paul suggested and simplified my wiring. I managed to get the button to trigger on but not off. If my understanding is correct, I believe its because I don't have the 10k resistor in place. I will have those today. Here is a picture of what I have redone today. Once I get this to work properly, then I will deal with the computer recognizing the the board as a midi device. Any help you can give would be greatly appreciated. I really want to learn how to use these boards to the best way possible.
 

Attachments

  • update.jpg
    update.jpg
    70.4 KB · Views: 12
In this latest photo, the button on the left appears to be connected incorrectly. Both of its wires connect to GND. You need to have 1 of its wires connect to GND and the other wire connect to a digital pin.

The button on the right looks good. Its red wire connects to GND, and its yellow wire appears to connect to Teensy digital pin 2.


If my understanding is correct, I believe its because I don't have the 10k resistor in place.

Please read the tutorial again. It tries to explain the pullup resistor concept.

The main chip has built in pullup resistors, so you can make this work without adding 10K resistors. But the concept is still important to understand. It will only work without the 10K resistors because you are using the resistors that are inside the main processor. The tutorial text tries to explain this concept, so you understand the *reason* it works rather than blindly follow a recipe without knowing why it works. Please, read the tutorial carefully. This information is important to understand.
 
Last edited:
Quick question, as I reconnect the board wiring I have the serial monitor open. I get button pressed !!! but nothing else happens. If this is correct, shouldn't I get button pressed when initially pressed then released get button not pressed?
 

Attachments

  • just updated.jpg
    just updated.jpg
    76.7 KB · Views: 7
If this is correct, shouldn't I get button pressed when initially pressed then released get button not pressed?

Please remember we can't see your computer screen. To say what should or should not happen, we need to see which code you're really running.

To show us your code, in Arduino press CTRL-A to select all and CTRL-C to copy (or Command instead of CTRL if using MacOS). Then here on the forum, click the </> code button (first in the editor's tools) and press CTRL-V to paste. Easy stuff, but critically important for getting useful help.

Or if you're running one of the examples with absolutely no changes, just clearly saying which example is usually good enough. But if even 1 seemingly inconsequential thing has changed, show us the whole program. Small details can really matter.
 
Hi diggable.
I can relate to the point your at in your at with your coding knowledge. As Paul has suggested we would need to see the code… but can I suggest you put a freeze on making changes to the hardware. That last picture looks good.
The software is likely incorrect if you are not getting the button released message.

I suspect this will be because you haven’t got the internal pull-up enabled… but it would be a mistake for me to assume that.

One thing you will learn in this hobby assumptions can waste allot of time. You may have several issues In Your code for all I know.

Copy and paste the code here and someone will tell you what is incorrect.

Gavin.
 
void setup() {
Serial.begin(38400);
}

void loop() {
if (digitalRead(8) == HIGH) {
Serial.println("Button is not pressed...");
} else {
Serial.println("Button pressed!!!");
}
delay(3000);
}
 
/* Buttons to USB MIDI Example

You must select MIDI from the "Tools > USB Type" menu

To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"

This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;

// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5); // which is appropriate for good
Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5); // to rapid touch, you can
Bounce button7 = Bounce(7, 5); // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);

void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP); // Teensy++ 2.0 LED, may need 1k resistor pullup
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP); // Teensy 2.0 LED, may need 1k resistor pullup
}

void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();

// Check each button for "falling" edge.
// Send a MIDI Note On message when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4
}
if (button3.fallingEdge()) {
usbMIDI.sendNoteOn(63, 99, channel); // 63 = D#4
}
if (button4.fallingEdge()) {
usbMIDI.sendNoteOn(64, 99, channel); // 64 = E4
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4
}
if (button6.fallingEdge()) {
usbMIDI.sendNoteOn(66, 99, channel); // 66 = F#4
}
if (button7.fallingEdge()) {
usbMIDI.sendNoteOn(67, 99, channel); // 67 = G4
}
if (button8.fallingEdge()) {
usbMIDI.sendNoteOn(68, 99, channel); // 68 = G#4
}
if (button9.fallingEdge()) {
usbMIDI.sendNoteOn(69, 99, channel); // 69 = A5
}
if (button10.fallingEdge()) {
usbMIDI.sendNoteOn(70, 99, channel); // 70 = A#5
}
if (button11.fallingEdge()) {
usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5
}

// Check each button for "rising" edge
// Send a MIDI Note Off message when each button releases
// For many types of projects, you only care when the button
// is pressed and the release isn't needed.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel); // 60 = C4
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOff(63, 0, channel); // 63 = D#4
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOff(64, 0, channel); // 64 = E4
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4
}
if (button6.risingEdge()) {
usbMIDI.sendNoteOff(66, 0, channel); // 66 = F#4
}
if (button7.risingEdge()) {
usbMIDI.sendNoteOff(67, 0, channel); // 67 = G4
}
if (button8.risingEdge()) {
usbMIDI.sendNoteOff(68, 0, channel); // 68 = G#4
}
if (button9.risingEdge()) {
usbMIDI.sendNoteOff(69, 0, channel); // 69 = A5
}
if (button10.risingEdge()) {
usbMIDI.sendNoteOff(70, 0, channel); // 70 = A#5
}
if (button11.risingEdge()) {
usbMIDI.sendNoteOff(71, 0, channel); // 71 = B5
}

// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
}
 
Back
Top