First project - simple midi control

Hello all

Just received my uno today and have started on my first project, a simple midi controller.

Now I’ve seen a few options/ examples around and am looking for some advice on which is best. Basically I’m looking to start with a simple push button program change midi controller.

This one is very basic, with the bush button linked to ground via 10k resister until a button push puts +5v on the assigned pins. Programming req is minimal.

Alternatively, the notes and volts design is based around grounding the assigned pin via the button. Programming seems a lot more complicated but includes pots and multiplexer which I’m not bothered about.

Both will need some tweaking to get to where a I want but Is there a right or wrong way, ultimately I’m looking at a 8 button program controller which I can add features to as I learn more.

Thanks. Dave

seems you have a good link to a tutorial... go with it.
after the first tutorial you will have a good idea of how and how well these things work and how much more you might want to add.

Using INPUT_PULLUP and grounding the pin is the preferred way of dealing with pushbuttons (saves buying extra resistors and finding somewhere to fit them). But would be easy to change the first code to use that method so I'd probably start with that.

Steve

Personally, I wouldn't waste too much time with the notes and volts code, it's messy and contains a lot of bad and confusing practices, like the arrays of pointers.

What it does do correctly is using the internal pull-up resistors as mentioned by slipstick.

If you want a simple and extensible program change controller, I can recommend the Control Surface library I'm working on.

Here are two Program Change examples:

PCButton.ino
ProgramChanger.ino

With the first one, you just create some PCButtons that read the button state from the given pin, and send out a MIDI Program Change event for the given program and MIDI channel when pressed.
If you need to add more buttons, just add more PCButtons in the code (you can create an array of them). You can also enter the program number instead of the program name if you want to.

[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color] [color=#434f54]// Include the Control Surface library[/color]

[color=#434f54]// Instantiate a MIDI over USB interface that will be used by Control Surface[/color]
[b][color=#d35400]USBMIDI_Interface[/color][/b] [color=#00979c]midi[/color][color=#000000];[/color]

[color=#434f54]// Instantiate a PCButton that reads the input from a push button and sends out  [/color]
[color=#434f54]// a MIDI Program Change message when it's pressed.[/color]
[b][color=#d35400]PCButton[/color][/b] [color=#000000]pcBtn[/color] [color=#434f54]=[/color] [color=#000000]{[/color]
  [color=#000000]2[/color][color=#434f54],[/color]                                 [color=#434f54]// pin[/color]
  [color=#000000]{[/color][b][color=#d35400]MIDI_PC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Steel_Drums[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_1[/color][color=#000000]}[/color][color=#434f54],[/color] [color=#434f54]// address[/color]
[color=#000000]}[/color][color=#000000];[/color]

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Initialize Control Surface[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Update the Control Surface[/color]
[color=#000000]}[/color]

Pieter

thanks for all the advice so far, am really quite confused as there's so many different ways of doing this.

Was starting with the very basics like pin assignment, reading about the Input_Pullup, how it works etc, then looking at some basic tutorial examples to develop some understanding.

Looking at the examples Pieter kindly posted, i see there's alternative code that automates some of the basic functions, for example PCButton takes care of Input_Pullup, debounce and send midi program change events - making the code very tidy but probably too big a step for me.

So i'm going to start from scratch and keep plugging away with tutorials and put something very basic together

One question, Pieters example uses the Control Surface Library whereas i have a standalone DMX controller with a midi input, will that work or do i need to use the midi library and ammend any code - would like to see it working

in particular, how would i change this so i can send the midi parameter 127 (which is blackout on my controller) on channel 1

// Instantiate a PCButton that reads the input from a push button and sends out
// a MIDI Program Change message when it's pressed.
PCButton pcBtn = {
2, // pin
{MIDI_PC::Steel_Drums, CHANNEL_1}, // address
};

Thanks

Dave

Control Surface comes with many different MIDI Interfaces.
If you want to use the usual 5-pin DIN MIDI connection instead of MIDI over USB, you can use something like this:

[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color] [color=#434f54]// Include the Control Surface library[/color]

[color=#434f54]// Instantiate a Serial MIDI interface that will be used by Control Surface[/color]
[b][color=#d35400]HardwareSerialMIDI_Interface[/color][/b] [color=#00979c]midi[/color] [color=#434f54]=[/color] [color=#000000]{[/color][b][color=#d35400]Serial[/color][/b][color=#434f54],[/color] [color=#00979c]MIDI_BAUD[/color][color=#000000]}[/color][color=#000000];[/color]

[color=#434f54]// Instantiate a PCButton that reads the input from a push button and sends out [/color]
[color=#434f54]// a MIDI Program Change message when it's pressed.[/color]
[b][color=#d35400]PCButton[/color][/b] [color=#000000]pcBtn[/color] [color=#434f54]=[/color] [color=#000000]{[/color]
  [color=#000000]2[/color][color=#434f54],[/color]                [color=#434f54]// pin[/color]
  [color=#000000]{[/color][color=#000000]127[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_1[/color][color=#000000]}[/color][color=#434f54],[/color] [color=#434f54]// address: program change #127 on MIDI Channel 1[/color]
[color=#000000]}[/color][color=#000000];[/color]

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Initialize Control Surface[/color]
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Update the Control Surface[/color]
[color=#000000]}[/color]

This way, it's very similar to the MIDI library.
I also changed the MIDI program to #127 instead of "steel drums".

Thank you Pieter, that's great.

I kind of steamed ahead and hooked up my DMX controller only to find it didn't work. I don't have a midi to usb device here so wasn't sure what was the weak link.

I have now found some additional information on my controller which isn't in the manual. Apparently the controller only responds to midi when in auto mode but also only responds to note on and note off data rather than CC or PC commands.

I've googled around for some simple sketches that may test to see if this is the case and did have a tiny instance of success when the scene changed from 8 to 1, nothing else happened after that, which was probably due to an out of date sketch, and my inexperience/tinkering.

More reading required!

If you post a link to the DMX controller you use and post the schematic you're using we might be able to help.

The Control Surface library has the NoteButton class to send note on/off events.

The dmx controller is a chauvet obey 40 - very entry level until that has midi input available. Midi channel is currently set to 1

https://www.chauvetdj.com/wp-content/uploads/2015/12/Obey_40_UM_Rev9_ML5-1.pdf Page 32 for the midi information.

My schematic is as the basic midi controller on the Arduino midi tutorial with push buttons linking pins to ground as req.

I’ve been through some tutorials, switching the led on, button testing using serial monitor etc so know uploading and the board works.

Edit...Just found this, should do the job by changing the note value to one of the required midi notes.

#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

using namespace MIDI_Notes;

// Instantiate a NoteButton object
NoteButton button = {
5, // Push button on pin 5
{note(C, 4), CHANNEL_1}, // Note C4 on MIDI channel 1
};

void setup() {
Control_Surface.begin(); // Initialize Control Surface
}

void loop() {
Control_Surface.loop(); // Update the Control Surface
}

Success! So...am making some progress after literally finding a weak link on my ebay breadboard. Basic prototype is up and running so it's hardware time. Have currently got 8 inputs, controlling 8 different elements on my DMX controller.

Sadly my current controller is very basic so am quite limited to what it can do but with some tweaking of how i program it, I should be able to deliver something half decent ...However, i do have a software based DMX system which is far more versatile so that could be an interesting step up.

A sincere thank you for the input to date..much appreciated!

Regards
Dave