Code Monkey home page Code Monkey logo

midi-footswitch-converter's Introduction

MIDI Footswitch Converter

Photo of a prototype enclosed and in use Photo of a prototype enclosed with the top of the enclosure removed

Description

The goal of this project is to build a device that converts a simple analog on/off signal to a MIDI message. A simple footswitch or sustain pedal can be plugged into it and trigger the MIDI message over USB. I deliberately kept it quite simple to keep the source code hackable for Arduino beginners. For a similar but more advanced project, see the spiritual successor https://github.com/ledeniz/arduino-multi-switch

This code makes use of the Arduino library MIDIUSB.

Features

  • Acts as a native USB MIDI device
  • Configurable MIDI channel, CC number and on/off values
    • Note mode available: send a MIDI Note On/Off message (with or without CC)
  • Toggle Switch mode
  • Invert setting
    • To switch pedal polarity

See the section Configuration for all supported settings.

Building it

Hardware needed

  • 1x arduino board with native USB port functionality (Zero, Due, 101, Micro, Leonardo)
    • (I used a Sparkfun Pro Micro clone) (aliexpress)
  • 1x mono or stereo 1/4inch input jack
  • 1x simple footswitch or sustain pedal

Wiring

Connect sleeve to ground and the tip to a pin with digital input capability. Be aware to not use a shunt contact if one is present on your jack.

Photo of a prototype enclosure 3D printed and wired

Enclosure

STLs / Printables / Thingiverse

Remixed from “Enclosure for DIY Ambilight with Arduino Pro Micro controller” by Florian J. aka ShreddedABS: https://www.thingiverse.com/thing:4660540

Currently this is just a rough prototype, but it works ;) (I'm currently trying to learn CAD; I may update the models in in the future)

Configuration

The device configuration is hard-coded. At the top of the sketch, you can find this configuration block:

//////// Configuration section 
// CC mode:   `MODE = MODE_CC` 
// Note mode: `MODE = MODE_NOTE`
// Both:      `MODE = MODE_CC | NOTE_NOTE`
const unsigned short MODE = MODE_NOTE; 

// Act as a momentary switch (false) or toggle switch (true)
const bool TOGGLE = false;
// Inverts output values
const bool INVERT = false;

// MIDI channel 1-16, zero based
const byte MIDI_CHANNEL = 0;

// MIDI CC number. 4 = Foot Controller; 64 = Sustain Pedal
// https://www.midi.org/specifications-old/item/table-3-control-change-messages-data-bytes-2
const byte MIDI_CC = 64;
// MIDI value for state 'off' (0-127)
const byte MIDI_CC_MIN = 0;
// MIDI value for state 'on' (0-127)
const byte MIDI_CC_MAX = 127;

// MIDI note pitch value (0-127; 48 = middle C)
const byte MIDI_NOTE = 48;
// MIDI note velocity value (64 = normal, 127 = fastest)
const byte MIDI_NOTE_VELOCITY = 100;

// Pin number the jack tip is connected to
const int  INPUT_PIN = 3;
// Threshold for when to allow the next trigger, in milliseconds
const int  DEBOUNCE_MS = 30;

//////// END of Configuration section

License

This document, the photos and the source code is licensed under the GPL v3. The STL files are licensed under CC BY 4.0.

midi-footswitch-converter's People

Contributors

denalena avatar

Watchers

 avatar

midi-footswitch-converter's Issues

Add polarity detection

I think the shunt contact of the socket could be used to detect the pedals polarity. This could be used to do the "invert" logic, without reflashing.

The logic could be implemented like this (assuming that the pedal is unpressed (or if you want to switch polarity, keep it pressed while plugging it in):

(pseudo code)

var polarity = LOW

if (SHUNT) {
  polarity = read(INPUT_PIN)
}

// switch STATE based on same logic as INVERT logic

Add Keyboard support

This may blow up the scope of this project (fork?) but I found out that its possible to use Keyboard.h alongside MIDUSB.h, so it would be possible to send keystrokes along/instead of MIDI data. Could be useful because for example in Ableton Live you can map keys to most midi mappable things as well. Also it wouldnt be limited to programs that support MIDI (Guitar Pro, PDF page turner, etc).

Implement NC/NO fix

Currently there is no built in option for choosing if we are using a normal closed or normally open switch.

There is the INVERT option but it doesnt double as a keyup/keydown invert.

Add wiring schematics

Provide schematics for wiring a stereo and mono input jacks.

Also, in the one picture that is currently depicting the wiring of a mono jack, the wiring is reverse (tip to gnd and sleeve to pin3) :P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.