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.

32 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. 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
  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
  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
    Replies
    1. Watch the Multi Plexer tutorial.

      Delete
  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