Tutorial for creating a simple MIDI controller and using it in Ableton Live (or any other DAW)
Devices and components
Arduino Uno Rev3
Switch Actuator, APEM A01 Series Illuminated Pushbutton Switches
Jumper wires (generic)
Materials and tools
Soldering iron (generic)
Software and tools
loopMidi
Hairless MIDI Serial Bridge
Ableton Live 10 Review
Project description
Summary
Circuit
Button 3 ==> D2
Button 2 ==> D3
Button 1 ==> D4
Button 6 ==> D5
Button 5 ==> D6
Button 4 ==> D7
Button 9 ==> D8
Button 8 ==> D9
Button 7 ==> D10
MIDI mappings
#define NOTE_ONE 36
#define NOTE_TWO 37
// Define all notes here.
#define NOTE_ON_CMD 0x90
#define NOTE_OFF_CMD 0x80
#define MAX_MIDI_VELOCITY 127
MIDI via USB
Explanation of the code
int NUMBER_BUTTONS = 9;
Button Button1(4, NOTE_ONE);
Button Button2(3, NOTE_TWO);
Button Button3(2, NOTE_THREE);
Button Button4(7, NOTE_FOUR);
Button Button5(6, NOTE_FIVE);
Button Button6(5, NOTE_SIX);
Button Button7(10, NOTE_SEVEN);
Button Button8(9, NOTE_EIGHT);
Button Button9(8, NOTE_NINE);
Button *Buttons[] {&Button1,&Button2,&Button3,&Button4,&Button5,&Button6,&Button7,&Button8,&Button9};
//Buttons.cpp
pinMode(_pin, INPUT_PULLUP);
HIGH
LOW
(0)
// Button is pressed
if (state == 0)
{
midiNoteOn(Buttons[i]->Note,127);
}
// Button is not pressed
if (state == 1)
{
}
//Buttons.cpp
_state = 1;
//Buttons.cpp
_lastState = 1;
//Buttons.cpp
if(state!= _lastState)
{
//....
}
void midiNoteOn(byte note, byte midiVelocity)
{
Serial.write(NOTE_ON_CMD);
Serial.write(note);
Serial.write(midiVelocity);
}
void midiNoteOff(byte note, byte midiVelocity)
{
Serial.write(NOTE_OFF_CMD);
Serial.write(note);
Serial.write(midiVelocity);
}
updateButtons
void updateButtons() {
for (int i = 0; i < NUMBER_BUTTONS; i++) {
int state = Buttons[i]->getButtonState();
// Button is pressed
if (state == 0)
{
midiNoteOn(Buttons[i]->Note,127);
}
// Button is not pressed
if (state == 1)
\tmidiNoteOff(Buttons[i]->Note,0);
}
}
void loop() {
if (NUMBER_BUTTONS != 0) updateButtons();
}
Use your controller with DAW (Ableton Live)
Connect with Ableton
Use the controller as a drum rack or keyboard
My completed project
To do
MidiDrumPad.ino
arduino
1#include "Buttons.h"
2
3//------Notes-------------
4#define NOTE_ONE 36
5#define NOTE_TWO 37
6#define NOTE_THREE 38
7#define NOTE_FOUR 39
8#define NOTE_FIVE 40
9#define NOTE_SIX 41
10#define NOTE_SEVEN 42
11#define NOTE_EIGHT 43
12#define NOTE_NINE 44
13
14#define NOTE_ON_CMD 0x90
15#define NOTE_OFF_CMD 0x80
16#define MAX_MIDI_VELOCITY 127
17
18//------------------------
19
20int NUMBER_BUTTONS = 9;
21
22Button Button1(4, NOTE_ONE);
23Button Button2(3, NOTE_TWO);
24Button Button3(2, NOTE_THREE);
25Button Button4(7, NOTE_FOUR);
26Button Button5(6, NOTE_FIVE);
27Button Button6(5, NOTE_SIX);
28Button Button7(10, NOTE_SEVEN);
29Button Button8(9, NOTE_EIGHT);
30Button Button9(8, NOTE_NINE);
31
32Button *Buttons[] {&Button1,&Button2,&Button3,&Button4,&Button5,&Button6,&Button7,&Button8,&Button9};
33
34
35int red_light_pin= 11;
36int green_light_pin = 12;
37int blue_light_pin = 13;
38
39
40void setup() {
41 Serial.begin(9600);
42}
43
44void loop() {
45 if (NUMBER_BUTTONS != 0) updateButtons();
46}
47
48void updateButtons() {
49
50 for (int i = 0; i < NUMBER_BUTTONS; i++) {
51 int state = Buttons[i]->getButtonState();
52
53 // Button is pressed
54 if (state == 0)
55 {
56 midiNoteOn(Buttons[i]->Note,127);
57 }
58
59 // Button is not pressed
60 if (state == 1)
61 {
62 midiNoteOff(Buttons[i]->Note,0);
63 }
64 }
65}
66
67
68void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
69 {
70 analogWrite(red_light_pin, red_light_value);
71 analogWrite(green_light_pin, green_light_value);
72 analogWrite(blue_light_pin, blue_light_value);
73}
74
75// Send MIDI note ON
76void midiNoteOn(byte note, byte midiVelocity)
77{
78 Serial.write(NOTE_ON_CMD);
79 Serial.write(note);
80 Serial.write(midiVelocity);
81}
82
83//Send MIDI note OFF
84void midiNoteOff(byte note, byte midiVelocity)
85{
86 Serial.write(NOTE_OFF_CMD);
87 Serial.write(note);
88 Serial.write(midiVelocity);
89}
Buttons.h
arduino
1#ifndef Buttons_h
2#define Buttons_h
3
4#include <Arduino.h>
5
6//Button (Pin Number, Note Number)
7class Button
8{
9 public:
10 Button(int pin, short note);
11 int getButtonState();
12 int Note;
13
14 private:
15 int _pin;
16 short _note;
17 int _state;
18 int _lastState;
19};
20
21#endif
You can download the code from my Github
MidiDrumPad.ino
arduino
1#include "Buttons.h"
2
3//------Notes-------------
4#define NOTE_ONE 36
5#define NOTE_TWO 37
6#define NOTE_THREE 38
7#define NOTE_FOUR 39
8#define NOTE_FIVE 40
9#define NOTE_SIX 41
10#define NOTE_SEVEN 42
11#define NOTE_EIGHT 43
12#define NOTE_NINE 44
13
14#define NOTE_ON_CMD 0x90
15#define NOTE_OFF_CMD 0x80
16#define MAX_MIDI_VELOCITY 127
17
18//------------------------
19
20int NUMBER_BUTTONS = 9;
21
22Button Button1(4, NOTE_ONE);
23Button Button2(3, NOTE_TWO);
24Button Button3(2, NOTE_THREE);
25Button Button4(7, NOTE_FOUR);
26Button Button5(6, NOTE_FIVE);
27Button Button6(5, NOTE_SIX);
28Button Button7(10, NOTE_SEVEN);
29Button Button8(9, NOTE_EIGHT);
30Button Button9(8, NOTE_NINE);
31
32Button *Buttons[] {&Button1,&Button2,&Button3,&Button4,&Button5,&Button6,&Button7,&Button8,&Button9};
33
34
35int red_light_pin= 11;
36int green_light_pin = 12;
37int blue_light_pin = 13;
38
39
40void setup() {
41 Serial.begin(9600);
42}
43
44void loop() {
45 if (NUMBER_BUTTONS != 0) updateButtons();
46}
47
48void updateButtons() {
49
50 for (int i = 0; i < NUMBER_BUTTONS; i++) {
51 int state = Buttons[i]->getButtonState();
52
53 // Button is pressed
54 if (state == 0)
55 {
56 midiNoteOn(Buttons[i]->Note,127);
57 }
58
59 // Button is not pressed
60 if (state == 1)
61 {
62 midiNoteOff(Buttons[i]->Note,0);
63 }
64 }
65}
66
67
68void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
69 {
70 analogWrite(red_light_pin, red_light_value);
71 analogWrite(green_light_pin, green_light_value);
72 analogWrite(blue_light_pin, blue_light_value);
73}
74
75// Send MIDI note ON
76void midiNoteOn(byte note, byte midiVelocity)
77{
78 Serial.write(NOTE_ON_CMD);
79 Serial.write(note);
80 Serial.write(midiVelocity);
81}
82
83//Send MIDI note OFF
84void midiNoteOff(byte note, byte midiVelocity)
85{
86 Serial.write(NOTE_OFF_CMD);
87 Serial.write(note);
88 Serial.write(midiVelocity);
89}
You can download the code from my Github
Buttons.h
arduino
1#ifndef Buttons_h
2#define Buttons_h
3
4#include <Arduino.h>
5
6//Button (Pin Number, Note Number)
7class Button
8{
9 public:
10 Button(int pin, short note);
11 int getButtonState();
12 int Note;
13
14 private:
15 int _pin;
16 short _note;
17 int _state;
18 int _lastState;
19};
20
21#endif
Buttons.cpp
arduino
1#include "Buttons.h"
2
3
4Button::Button(int pin, short note)
5{
6 _pin = pin;
7 pinMode(_pin, INPUT_PULLUP);
8 _state = 1;
9 _lastState = 1;
10 Note = note;
11}
12
13
14int Button::getButtonState()
15{
16 int returnValue = -1;
17 int state = digitalRead(_pin);
18
19 if(state == _lastState)
20 return 5;
21 if(state!= _lastState)
22 {
23 if(state == 0)
24 {
25 returnValue = 0;
26 }
27 else
28 {
29 returnValue = 1;
30 }
31 }
32
33 _lastState = state;
34
35 return returnValue;
36}
Downloadable files
Unopad circuit - without LED
Unopad circuit - without LED
Unopad circuit - without LED
Unopad circuit - without LED
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.