Saturday 30 April 2016

Arduino MIDI Controller: Buttons

Push It!

In this installment of the MIDI for the Arduino Series, we will add Push Buttons to the Midi Controller we started building in the last chapter.

Before You Start

This tutorial will ONLY work with the Arduino UNO. (Please don't ask if it will work on other Arduino models.) I am using some direct port manipulation in the code that is currently specific to the UNO. I'll let you know if this changes in the future.

The Software

To make things simple, I have created a plug and play program that will allow you to customize your controller. All you need to do is tell the software the number of controls you will be using and how these controls should behave and the software will take care of the details. The video explains how to configure the software for your project.

Download the software HERE

Build It!

Watch this video for a step by step guide.

57 comments:

  1. Quick question, I am using an infrared distance sensor for a high filter pass, is there any way I can invert the signal so the number goes up as it gets closer instead of visa versa?

    ReplyDelete
    Replies
    1. is the signal out of your infrared sensor analogue? If it is, you may be able to use a transistor circuit to invert the signal like you say, but you may be able to also do that through the use of some code in your arduino.

      Delete
    2. Hello, what do I have to type in the program to change the tone value. For example C -20 (notes tuning)

      Delete
  2. this is really interesting, but I just bought a NANO :-( I have never programmed before and have no idea what direct port manipulation is but love the idea of creating my own custom controllers and this looks like a better way to do it than my NOCTURN

    ReplyDelete
    Replies
    1. 1)Read
      3)Practice
      2)Git gud
      there are lots of tutorials for everything, start with the Arduino IDE, free in the official website

      Delete
  3. Okay here is a question - can I use an Atmega 328P-PU chip with Arduino UNO boot Loader - essentially this would be an UNO ??? so I can build the whole thing a bit smaller? Thanks

    ReplyDelete
    Replies
    1. Hi Mark. Yes you can. I cover that topic in this article http://www.notesandvolts.com/2014/07/fun-with-arduino-arduino-on-proto-board.html

      Delete
  4. Hi, i have MEGA 2560. i have mailed you my issue please reply.... thanks

    ReplyDelete
  5. Hello, you could make a tutorial on how to put more analog and digital inputs and outputs to arduino? I'm doing a midi controller and I need more analog and digital connections. In the code that is shared programming but do not know how to connect and configure, you could help me with that?
      Thank you very much

    ReplyDelete
    Replies
    1. Hi Carlos. Use multiplexers like this http://www.notesandvolts.com/2016/07/arduino-midi-controller-multiplexers.html

      Delete
  6. hi,fantastic job,,,,is it possible to reduce the volume of the notes as I am using them to set off track play and stop buttons etc and i get this annoying note playing everytime i hit the switch

    ReplyDelete
    Replies
    1. Make sure that there are no other instruments or plug-ins set to the same Midi channel as you transport controls.

      Delete
  7. Hey Dave, is it posibel to use the code for sending over sreival/usb

    ReplyDelete
  8. Awsome Tutorials!! ive been looking for something like this for a long time. I started proototyping this weekand ran into a small problem, when i set the buttons to output CC data(cmd1 or 2) it works until i stop pressing the buttons for 2 or more seconds.

    It then somehow forgets to send midi.

    BUT strange thing, if i then press a note button the CC buttons work again until i stop pressing them for about 2 seconds. Any Help?

    ReplyDelete
  9. Hi,

    I used your code and my setup works fine. Thank you for that. I need a little MOD in the code that IF A BUTTON IS PRESSED IT GENERATES A NOTE AND WHEN RELEASED IT GENERATES ANOTHER NOTE.

    Please Help.

    Thank you.

    ReplyDelete
  10. Is there a way to get this to work with Photocell sensors?

    ReplyDelete
  11. please tell me ,how to create programme change button ?(ex Button BU1(9, 1, 0, 10, 1 );)

    ReplyDelete
  12. Hello Dave,
    Is possible to use only USB port to send CC notes to
    e.g. example Guitar Rig, without standard MIDI socket?

    Kind Regards
    Beardini

    ReplyDelete
    Replies
    1. Sure you can, pal, use HINDUINO, flash it, google for more, I made it ;)

      Delete
  13. Pascal van Harten13 October 2017 at 12:48

    Hi man,

    Could i use piezo disks for this. I wanna make this by stepping on a 'button'.

    Kind regards

    ReplyDelete
  14. If AT ALL possible, could you post a video with this same concept but with a board like the Leonardo that will transmit Midi over USB? A LOT of people would really appreciate it!

    ReplyDelete
  15. i got my controller working but i want to add two led lights to two of the buttons.how do i do that ?

    ReplyDelete
    Replies
    1. try this, it's working for me with 6 buttons with leds:

      const int ledButtonPin1 = 8;
      const int ledLedPin1 = 24;
      int buttonState1 = 0;

      long time = 0;
      long debounce = 200;

      void setup() {
      pinMode(ledLedPin1, OUTPUT);
      pinMode(ledButtonPin1, INPUT);
      }

      void loop() {
      buttonState1 = digitalRead(ledButtonPin1);
      if (buttonState1 == HIGH) {digitalWrite(ledLedPin1, LOW);}
      else {digitalWrite(ledLedPin1, HIGH);}
      }

      Delete
    2. Hello, using this code for the leds do they work simply put they in the same positive and negative of the switch that they are associeted?

      Delete
  16. Hi Dave,

    Amazing tutorials, all of them, thank u very much.

    I made a controller with pots and buttons and works perfect. Now i'm to develop a foot controller with 9 DPDT (toggle) footswitchs.

    I need 4 of them to work like momentary switches to trigger clips on Ableton Live.

    There is any way to modify the buttons setting to make de toggle switches work like momentary?

    Something like this but for MIDI:

    ______________
    const int footPin1 = 45;
    void setup() {
    pinMode (footPin1, INPUT);

    Serial.begin(9600);
    }
    void loop() {
    int footA1 = digitalRead (footPin1);
    delay(5);
    int footB1 = digitalRead (footPin1);

    if (footA1 != footB1)
    {digitalWrite(footPin1, HIGH);
    Serial.println(1);
    }
    else
    {digitalWrite(footPin1, LOW);
    Serial.println(0);
    }
    }

    MUCHAS GRACIAS!!!!!!

    ReplyDelete
    Replies
    1. I'm only using CC command parametrs, can i change any configuration on toggle (case2)?

      Delete
    2. Solved!

      Set the Command Parameter of the footswitchs to "2" them made some mods on the "void updateButtons()" settings.

      Thanx again for all the tutorials and the controller program!
      ___________________________________

      void updateButtons() {

      // Cycle through Button array
      for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
      byte message = BUTTONS[i]->getValue();

      // Button is pressed
      if (message == 1) {
      switch (BUTTONS[i]->Bcommand) {
      case 0: //Note
      MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
      break;
      case 1: //CC
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
      break;
      case 2: //Toggle
      if (BUTTONS[i]->Btoggle != message) {
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
      BUTTONS[i]->Btoggle = 0;
      }
      else if (BUTTONS[i]->Btoggle == message) {
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
      BUTTONS[i]->Btoggle = 0;
      }
      break;
      }
      }

      // Button is not pressed
      if (message == 0) {
      switch (BUTTONS[i]->Bcommand) {
      case 0:
      MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
      break;
      case 1:
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
      break;
      case 2: //Toggle
      if (BUTTONS[i]->Btoggle != message) {
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
      BUTTONS[i]->Btoggle = 0;
      }
      else if (BUTTONS[i]->Btoggle == message) {
      MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
      BUTTONS[i]->Btoggle = 0;
      }
      break;
      }
      }
      }
      }

      Delete
  17. Hi people, I'm wondering that if anyone knows how to implement a 4x4 button matrix to this project. Cheers! :)

    ReplyDelete
  18. can I use a cadmium light sensor instead of a button I am trying to make a laser harp so when the laser is interrupted it send a midi cc to ableton any help please

    ReplyDelete
  19. anyone else having issues compiling the midi library with the controller code. I am able to compile the MIDI_Input code with no problem but the MIDI_Controller code is not. Any ideas? here is the error:

    libraries/MIDI/MIDI.cpp.o (symbol from plugin): In function `midi::encodeSysEx(unsigned char const*, unsigned char*, unsigned int)':
    (.text+0x0): multiple definition of `midi::encodeSysEx(unsigned char const*, unsigned char*, unsigned int)'
    sketch/MIDI.cpp.o (symbol from plugin):(.text+0x0): first defined here
    libraries/MIDI/MIDI.cpp.o (symbol from plugin): In function `midi::encodeSysEx(unsigned char const*, unsigned char*, unsigned int)':
    (.text+0x0): multiple definition of `midi::decodeSysEx(unsigned char const*, unsigned char*, unsigned int)'
    sketch/MIDI.cpp.o (symbol from plugin):(.text+0x0): first defined here
    collect2: error: ld returned 1 exit status
    exit status 1
    Error compiling for board Arduino Nano.

    ReplyDelete
  20. Thanks Dave. Yours are the only tutorials that make it crystal clear of what is what etc. regarding DIY Midi on Arduino controllers. Two questions.
    1. I'm using a joystick for two of the analog inputs but I can'f figure out how to make one way Pitch Bend. I didn't find a MIDI CC number for that. Is that done a different way?
    2. Toggle switch/ Rotary switch to shift octaves? 7 ocatves with a 7 postion rotary would be awesome. Could it be done analogue as well?
    I guess that's more than two. Tia

    ReplyDelete
  21. Thanks Dave!! I would like to switch banks in a guitar processor, using 3 buttons one foot to change the channel and to move forward and backward. How do you define the buttons?

    ReplyDelete
  22. Hi! I want to use this as a stomp box midi controller to control my looper. My first question is, how would I go about using stronger momentary switches that would connect to the encolsure? Woould it just be about wiring them down into the breadboard? I see only two pin ones everywhere. Second would be how to add a midi thru/out jack if I wanted to run another devices midi clock through this pedal? Thanks!

    ReplyDelete
  23. Hi,
    This is great stuff!!! Forgive my ignorance, as I know nothing about coding (I'm just a lowly guitar player). But if I wanted to add program changes to the command parameters, would it be as simple as adding 3=PC and a case 3 with MIDI.sendProgramChange? Thanks so much!

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. I'm really stuck. I've tried to add a case 3 with a MIDI.sendProgramChange, but I keep getting errors. Anyone know what I'm doing wrong?

    ReplyDelete
  26. Ah, I figured out that I had to remove the value because program changes don't have a value. Now I'm not getting any errors, but it still doesn't work. Pressing a button assigned to a program change always makes the device go to the first program, no matter which CC number I've given it. AAAARG!

    ReplyDelete
  27. EVerything works perfect for the MIDI buttons. Is there any way to modify the code to incorporate the dmxsimple library so I only need to use one Arduino to trigger a dmx scene when I press one of the MIDI buttons?

    ReplyDelete
  28. Do you have a link where I can buy good quality buttons ?

    ReplyDelete
  29. And the MIDI socket as well!

    ReplyDelete
  30. goran.svoboda@gmail.com30 April 2020 at 16:37

    cool project, got me hooked up, so...
    im now using:
    Bu1, on pin8, sends cc, on my 4th note, ch1... but i want my 4th note to be on value 90... how do i do that?

    ReplyDelete
  31. How would you add a rotary encoder with push button with sample code

    ReplyDelete
  32. Hi Dave, first of all i really thank you for your efforts for this Arduino MIDI controller project.

    I want to make a simple MIDI program change device with 128 push buttons. I learned so much from you post. but i am new to coding or i can say i don't know much about coding.
    i want to accomplish this MIDI program change project on Arduino MEGA 2560.

    Please help me on this for coding.

    any help really appreciated.

    Thanks.

    ReplyDelete
  33. Code compiles w/o issue, but won't load.
    tried the Blink program same result

    and
    <avrdudestk500_getsync()
    wiring quadruple checked OK.
    I even tried different brand new Nano boards (from Amazon) with nothing wired I got the same result
    Any ideas??

    ReplyDelete
  34. Weird, some of my comment didn't get thru....
    <arvdude: stk500_recv() : Programmer not responding
    and <avrdude:stk500_getsync() attempt 10 of 10: not in sync: resp=0xa9

    ReplyDelete
  35. Hello, what do I have to type in the program to change the tone value. For example C -20 (notes tuning)

    ReplyDelete
  36. Hi,
    If I wanted each button to activate three notes simultaneously so as to trigger a chord with each button pressed would I just add two extra lines of code for each button each containing a different note value would it be done some other way? Thanks.

    ReplyDelete
  37. Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"





















    C:\Users\georg\AppData\Local\Temp\cc1Y8lBr.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_MIDI_Controller_v1_2.ino.cpp.o.1912':

    :(.text.startup+0x12e): undefined reference to `Button::Button(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

    :(.text.startup+0x13c): undefined reference to `Button::Button(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

    :(.text.startup+0x14a): undefined reference to `Button::Button(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

    :(.text.startup+0x158): undefined reference to `Button::Button(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'

    C:\Users\georg\AppData\Local\Temp\cc1Y8lBr.ltrans0.ltrans.o: In function `updateButtons':

    C:\Users\georg\AppData\Local\Temp\arduino_modified_sketch_461154/MIDI_Controller_v1-2.ino:144: undefined reference to `Button::getValue()'

    collect2.exe: error: ld returned 1 exit status

    Multiple libraries were found for "MIDI.h"

    Used: C:\Users\georg\OneDrive\Documents\Arduino\libraries\MIDI

    Not used: C:\Users\georg\OneDrive\Documents\Arduino\libraries\arduino_midi_library-master

    exit status 1

    Error compiling for board Arduino Uno.



    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    ReplyDelete
  38. After reading the post , I got some descriptive information which is very helpful for me. Thanks for posting it. Keep it up. microsonic ultrasonic sensors

    ReplyDelete
  39. Is it possible to use pins that are not included in the software, such as pins 10, 11, 12, 13 and even A0, A1, ..., A5?

    ReplyDelete
    Replies
    1. I mean adding buttons as BU10, BU11 and such

      Delete
  40. I made it. 11 buttons, one serve as "shift", so I have 20 effective switches. Added 6 LEDs for Power, Shift and 4 for presets within a bank. Box is 3D printed. I had to add some code to get Shift working and LEDs turned on/off in a correct manner. Your code was great base for that, as I am not a programmer and it took some time (and help from my friend) to figure out how to do it. I may publish entire project on Thingiverse or github, if I have time.

    ReplyDelete
  41. Hi all! Does it could work with a Arduino leonardo Midi Usb (i want to use CC change buttons) ? tks

    ReplyDelete