loading

A Framework For Making Affordable & Stylish Modular Controllers (USB to MIDI, HID, or Serial)

FeaturedContest Winner
***********************************************************************************

I HAVE CREATED A NEW INSTRUCTABLE FOR DIY CONTROLLERS:
http://www.instructables.com/id/Teensy-Monster-v10-DIY-MIDI-Controllers/

***********************************************************************************




****************************************************************************************************************************

I have designed a framework for making affordable and stylish modular controllers. You can use the content of this Instructable to make a wide range of controllers for a wide range of applications relevant to artists, DJs, VJs, gamers, producers, and the like. The DJ controllers I showcase in this document serve only as examples of (more conventional) interfaces you can create within the framework.

I focused on making this project affordable, stylish, and most important, builder friendly. The controllers can be re-programmed to send serial, MIDI, or HID messages. The modular design allows you to plug the controllers into one another, thus requiring only one USB port on your computer. Each module can have approximately 28 digital inputs/outputs, 23 analog inputs, and 4 rotary encoders. Those more savvy could add components such as touchscreens, sensors, pressure pads, etc., to the controllers using this framework. No special tools or equipment are required to build these controllers beyond a basic soldering iron and wire stripper. Also, very little coding is necessary. Editing the code is more like filling in the blanks.

****************************************************************************************************************************

More info here.

Some hype at engadget.

**Remember to read this entire Instructable before beginning any of the constituent steps**



 
Remove these adsRemove these ads by Signing Up

Step 1: Components

I have spent endless hours searching for the best and most reasonably priced components from around the world. I ordered many different components to test out and compare, most of them were rubbish and were not used in project. Here is the list of the best stuff I found. The ones with * are my favorites.

Microprocessor

  • Teensy++ @ PJRC (USA)
  • Teensy suppliers in Europe: 1, 2, 3

Pushbuttons

(Many of these pushbuttons are available in different sizes and color - check the sites for more options. With pushbuttons, you usually get what you pay for.)

Faders

(If these are out of stock, they may also be available at digikey.com or newark.com. If you are a scratch DJ you probably demand a 'frictionless' fader. DJ Deals sells them for cheap, and they are simple enough to use with the DIY controllers.)

Slide knob

  • Many options available at Newark.

Potentiometers

Potentiometer Knobs

(Knurled knobs can only be attached to knurled shafts. Knobs with set screws will require a hex key to couple with the potentiometer. 6.4mm knobs coupled with 6mm shafts fit slightly non-concentric - this can be fixed with some scotch tape. 6.35mm potentiometers do exist although I was unable to find an economical option.)

Encoders

(Search 'PEC11-' on Newark to get a long list of nice and affordable encoders. I used PEC11-4115F-S0018 and PEC11-4215F-S0024 in my build. I tested many encoders and found the Bourns ones to be best. They have both D, and knurled shaft options available.)

PCB

Wires & Connectors

Multiplexer

Header Pins

  • Male @ All Electronics, Sparkfun, Futurlec, Adafruit, SureElectronics
  • Female @ Sparkfun, SureElectronics, Futurlec

(Sure electronics is by far the cheapest!)

LEDs

(Every site has plenty of different LED options. Keep in mind this controller framework is not really designed to control more than a few LEDs. Now that is not to say you can't use many LEDs in this project, you just can't control them, ie, turn them on and off when you please.)

Hardware
All hardware (nuts, bolts, standoffs) can be found at McMaster (USA). McMaster is the best!

Other
Soldering iron, wire cutters/strippers.

There are many other components you may want to include in your interface such as LCDs, touchscreens, trackballs, pressure pads, proximity sensors, etc. SparkFun and Adafruit are the best resources for these kinds of components. Although the controllers I showcased in this Instructable are somewhat conventional, I encourage you to get crazy. DIY gives you the power to do anything you can imagine - just wait till you see the next controller I am going to build!

Read the datasheets carefully before buying components.

Discount/surplus stores like Futurlec & All Electronics have excellent prices, but also carry some components which are totally bogus - be extra careful before buying from these stores.

Note that all these components are panel mount (with exception to the LEDs). There is an important distinction between surface mount and panel mount components. Surface mount components fasten directly to the printed circuit board (PCB) while panel mount components fasten to the top panel and connect to the PCB via wire and solder connections. It is usually not possible to use surface mount components unless you fabricate custom PCBs and have expert soldering skills. Using panel mount components makes this project accessible to anyone.

So how much do these controllers cost? I don't kow how much your controller is gonna cost but mine were cheap, really cheap!

If you are from Europe or Asia this list may not be totally relevant or useful. Please send me links to suppliers in your countries so I can add them to this document.

Step 2: Set Up Teensyduino (Arduino + Teensy)

Picture of Set Up Teensyduino (Arduino + Teensy)

Those of you who are familiar with Arduino may be wondering why I am using a Teensy instead of Arduino. Four good reasons. One, Arduino cannot act as a native MIDI/USB/HID device as Teensy can. Two, Teensy has many more inputs/outputs and more interrupt pins. Three, Teensy can be easily soldered to the protoboard. Four, Teensy is comparatively cheaper. I use Arduino for many projects, but not for controllers. We will, however, borrow the user friendly programming environment from Arduino and integrate it with Teensy to create the very awesome Teensyduino. 

Some of you also may be wondering, what the hell is Teensy or Arduino? Well don't worry if you are not familiar with these. They are just the small, programmable computers (microcontrollers) that are the brains of your controller. They are easy to use - just edit the code on your computer and upload it!

Follow the Teensyduino tutorial carefully. It contains all the step-by-step guide to get your Teensyduino up and running. 

If you are installing the Arduino environment on your computer for the first time I would recommend not installing the latest version (I still use v0022, the latest version is Arduino 1.0). 

Once you have installed Teensyduino, proceed to the getting started tutorial to ensure everything is working. Dont forget to use the Teensy loader.

Although the Teensy loader tells you to 'Press Button To Activate' you can upload the code directly to the Teensy using the 'Upload' button in the Arduino environment (see image). This is important because once your Teensy is secure inside your controller the hardware button will not be easily accessible. 



Step 3: Getting Familiar With Teensy++

Picture of Getting Familiar With Teensy++

The diagram above explains the Teensy++ pin configuration. You need to understand how these pins differ. 

Digital pins
All numbered pins on the Teensy++ board can be used as digital inputs/outputs. A digital pin is simply an on/off pin. It can be on (HIGH) or off (LOW). We use digital pins as input to read pushbuttons, or as outputs to turn LEDs on. 

PWM pins (14,15,16,24,25,26)
Pulse width modulation (PWM) means we can send a variable voltage out of that pin between 0 volts and 5 volts. PWM pins are ideal for LEDs as they allow us to vary the brightness of the LED

Interrupt pins (0,1,2,3,6,7,36,37)
Each pin with 'INT' is an interrupt pin. Interrupt pins are important cause we need them to read encoders. They are simply digital pins which have special functions attached to them and will notify the Teensy when their value has changed. The Teensy++ board has 8 interrupt pins, allowing you to read four encoders. 

Analog input pins (A0-A7)
Analog pins allow you to read variable voltages between 0 volts and 5 volts. We use analog pins to read potentiometers. These pins can also be used as digital inputs if specified (although I haven't yet tested this). 

+5V/GND
In the top right corner we have power (+5V) and in the top left we have ground (GND). All Components will need to use ground, and all analog components will need to use both ground and power.

I2C pins (0,1)
The I2C pins (SDA, SCL) are what we use to enable module->module communication. When module->module communication is enabled these two pins can no longer be used by a rotary encoder.

Other
Pin 6 is not used cause it already has an internal LED attached to it. Bottom pins (+5V, GND, RST) are not used, nor are the two side pins GND and AREF.

Internal pins (28-35,36,37)
Pins 28-37 are located internally on the board. These pins are digital.  



Step 4: Testing Individual Components


This is surely the most critical step of this Instructable. You need to build a test circuit so you can understand how the components are hooked up and used with the Teensy. This step will also cover serial communication using the Teensy. 

In the images you will see a breadboard which has the following components (left to right)
  • Teensy++ microcontroller
  • Two potentiometers 
  • One rotary encoder with pushbutton
  • One mini LED
  • Three mini pushbuttons
Hookup the circuit as you see it in the images. Likely, your pushbuttons will look much different than mine, but don't worry about that because all pushbuttons hook up the same - one end to ground and the other to a digital input. If you have pushbuttons which are not breadboard-friendly just solder some wire connections to them quickly. 

You may also notice my connections between the pushbuttons look a bit goofy (the one yellow wire). I did this for a reason. It shows that instead of connecting the pushbutton ground directly to the ground linked to the Teensy (blue strip) you can plug the ground from one pushbutton to the next, so long as one of the pushbuttons is linked to the Teensy ground. This is important cause when you are wiring your components into your panel the ground connection on the Teensy is usually not as convenient as the ground of the neighboring components. This is an excellent way to reduce the number of wires in your controllers. I also did the same thing for the potentiometers with the grey wires. 

Usually LEDs should have resistors in series to prevent them from burning out over time. Since this was just a quick test I left the resistor out of the circuit. Also note that LEDs are polarized, meaning they have a power and ground end. If not hooked up correctly they with fail to light up or burn out. 

Once you have the circuit hooked up, proceed to opening to code. Read the many comments within the code to help you understand what is going on. 

Upload the code attached to your Teensy++ and launch the serial monitor. The serial monitor should give you feedback as you interact with the components: 'button 24 pressed', 'analog 2 value: 344', 'encoder +'. If your serial monitor is constantly spewing out values then you have hooked up something incorrectly. Make sure your serial monitor is running at 9600bps. 

The LED is set to flash at different brightness levels depending on which pushbutton you click. 

Before you move onto the next step, ensure this is working and you (without doubt) understand how to hook up each of these components to the Teensy++.

All code can be found here on GitHub. For this section use the code titled 'Testing Components'. Click 'ZIP' in the top-left to download.



Step 5: Design, Layout & Body.

Picture of Design, Layout & Body.
Mixer-1712.jpg
body.jpg
Component-2084.jpg
6216016222_04c82ac9a8_b.jpg
IMG_4343.JPG

You may suspect I am some kinda master craftsman or something. No, I am terrible at working with my hands and thus must rely completely on laser cutting robots.

Ponoko is great for laser cutting services, they have an excellent material selection and super friendly staff. 

For my controllers I used the materials Bamboo Amber 3mm, Black Matte Acrylic 1/8", White Matte Acrylic 1/8"Clear Acrylic 4.5mm, and Clear Acrylic 3mm

In the diagram above you will see the sketch for my three layer design. This method of design allows components to be counter-sunk. Below is the breakdown of layers for both the decks and sampler.
  • Layer 1: Clear Acrylic 3mm
  • Layer 2: Matte 1/8"
  • Bottom: Clean Acrylic 4.5mm
  • Platter: Matter 1/8"
The bamboo mixer also uses a three layer design. Each layer is bamboo.

I designed my layouts in Adobe Illustrator (free one month trial). There are many other software options available, just ensure they can export the PDF-type document Ponoko requires (Inkscape is freeware). When using illustrator be sure to switch your units to millimeters and add a grid to aid in layout/spacing.

Very very very very very very helpful design tips (that I wish someone had told me)
  • Most important: Do not overcrowd your board! Leave lots of space between components. Think minimalist. Although your Teensy++ has many inputs available it is foolish to try and make use of all of them. It is best to begin creating more modules rather than overcrowding a single board. Hookup will be a nightmare if your overcrowd the board.
  • Don't start your design/cutting until you have the components in your hands.
  • A shift button is a great way to reduce the number of pushbuttons. Using one shift button is highly recommended. When you hold your shift button, all the pushbuttons on your board will then send a different message thus doubling the total number of pushbutton messages available on your controller.
  • If you use non-matte acrylics on the front face they easily become covered with smudges.
  • All wood material will require a coating of polyurethane (or some equivalent).
  • Etching is possible (although I did not use it on my design).
  • If you design your front face to be large, there will be undesirable flexing in the center when you engage a pushbutton. Keep your modules a reasonable size. My mixer is 230x230mm.
  • Bamboo is more flexible than acrylic. The acrylic is quite stiff.
  • To reduce flex you can add tiny bolts which join layer one and two (see image).
  • Do not try to glue the top two layers together.
  • When creating your layout you need to reference the datasheet constantly to ensure your cutouts match the components.
  • If the specific components cutout dimensions are not given, it is best to increase the size by 0.1mm. For example, the rotary potentiometers have a bore diameter of 9mm, thus the cutout should be 9.1mm.
  • Errors in laser cutting can get pricey so be sure to check your design numerous times before sending it off.
  • The upper and lower layers can be spaced using aluminum standoffs.
  • I made the standoffs at the front slightly shorter than the ones at the back to created a tilted front face.
  • You can 3D print some custom corners (shapeways, ponoko, imaterialise) and add walls to your design, much like I did in MK1. Personally, I prefer the no-wall design as it enhances the DIY aesthetic and reduces costs.
  • The gap between the slide potentiometer body and slide knob needs to be measured carefully to ensure there will be enough clearance for the slider to slide. 
  • If you are using bamboo, I would recommend using 3 ply for the bottom instead of single ply. It is a good idea to use a heavy/thick bottom for all of the modules. 
  • Print out your layout on paper before laser cutting to get a feel for the spacing. 
  • Pay close attention to the height of your components. Ones which are too tall will cause your controller to look bulky and odd. 
  • When using the software, design all three layers at once then separate the layers before cutting (see attached pdf).
Get creative and have fun with the design!

I have attached the PDF files for the mixer to this document. I would not recommend copying these cutouts as It is best to make your own custom design.



Step 6: Soldering Like A Pro

Picture of Soldering Like A Pro

As you can probably tell there is going to be some soldering necessary to build your controller. If you have not soldered before, don't fret, it's really easy (if you follow my tips). If you don't have a soldering iron here is a super cheap station. You can also get irons at most hardware stores as well as Radio Shack. Below are four important tips to help you solder like a pro!

Buy a flux pen
This is imperative! They can be purchased here. Never ever try to solder without a flux pen no matter what anyone tells you. 

Watch my videos

Use this method if you have a free hand available to feed the solder. 
 

Use this method if you don't have a free hand available to feed the solder. 

Clean your tip using a wet sponge
If you don't do this you iron will become useless very fast. 

Use stranded wire
Solder sticks better to wire with many strands. The crimped wire from Pololu is stranded. 



Step 7: Assembling The Top Panel


Fasten all your components
Some components will be snap fit, while others will have fastening nuts and bushings. All components should fit snug, if not, you may have made an error in the laser cutting.

Cut your crimped wires to appropriate lengths
The pre-crimped wires you bought can be cut in half to make two wires. The cut ends can then be soldered directly to your components and the crimped ends plugged into the crimp housings. It is helpful if you make the wires long enough so that your top panel can plug into the bottom PCB while the top panel remains standing next to it (see image). If you are building a medium/large controller it would be wise to purchase 24" crimped wires, as opposed to 12". It is also important to know approximately where your PCB will be positioned on the bottom panel so you can cut your wire to the appropriate length. Some components (like arcade buttons) have large heights and will interfere with the components on your PCB. Notice on my sampler I had to position the PCB slightly off-center as to not interfere with the Teensy++ on my PCB - I wanted to keep the height as low as possible. If you cut your wire too long it may stick out the side, so take care when cutting - not to short and not too long.

Solder your exposed wire to your components
Color coating is not imperative, but helpful if you have enough wires. In the case you were foolish in your design and have an abundance of wires, it is helpful to begin connecting your ground/power connections between components (as shown in step 4). You should only do this if necessary. On my sampler I had a mess of wires, so connected all the ground connections from the arcade buttons to each other (see images). This way I only had one ground connection which needed to be plugged into the board. I did the same for the power and ground of the potentiometers (see images). You may want to add either tape or glue gun glue (see images) to your soldered connections. This way when you tug on the wire, there is less risk of it becoming detached from the component. Personally, I found both tape and glue ineffective and ended up removing both of them after they became a nuisance.



Step 8: Assembling The PCB


Understanding the bare PCB
The first and most important thing to understand is which holes on your bare PCB are connected to one another. Notice how there are white lines/boxes outlining some of the holes. These outlines identify which holes are connected together. Although none of the holes look connected from the outside, the ones which are outlined by a white box are connected together internally. So if you solder any two connections within a box, think of this as soldering those connections directly together. Follow the +5V/ground connections from the Teensy++ board and notice how both the power/ground become connected around the entire perimeter of the board. The orange wires at the bottom of the board send power/ground from one side of the board to the other. 

Header pins
You way also be wondering what all these header pins poking out are for. Well, it's simple, those pins are what we 'snap' our wires to using the plastic crimp housing. I have attached images for the full featured PCB. This PCB makes use of every Teensy++ pin, as well as the CD4067BE multiplexer. None of my modules used every Teensy++ pin. This board was built just as an example. For example, if you had 10 pushbuttons and 10 potentiometers you wanted to hookup, you would need a total of 50 header pins. Each pushbutton would require one header pin that connected to the board, and another one that connected to ground (total 20). Each potentiometer would require one header pin that connected to the board, one to ground, and one to power (total 30). You could reduce the number of header pins needed by connecting the ground/power of the components together. 

CD4067BE
Okay what the heck does this CD4067BE chip do? Good question. As you probably noticed from the pin configuration diagram the Teensy++ only has eight analog inputs. Yikes! In some cases (like my mixer) you will require more than eight analog inputs. The CD4067BE easily adds 16 analog input to your board. The four red wired linked between the Teensy++ and CD4067BE allow the Teensy++ to tell the CD4067BE which of the 16 pins it wants to read. The brown then sends the information for that analog input from the CD4067BE to the Teensy++. So if you require eight analog inputs or less, you will not need to add the CD4067BE to your PCB. That said, it is nice to have it on your PCB in case you later want to add more analog inputs. The CD4067BE chip only costs ~$1.50.

Resistors on the top right of the board. 
This is the board I used for my mixer, which includes two LEDs on the interface. It is important you use resistors in series with your LEDs otherwise your LEDs will burn out. Different colors/types of LEDs require different resistor values usually around 200ohm-500ohm. Check online to make sure you have coupled the correct resistor with your LED. You will notice I soldered one end of the resistor directly to the header pin. This was a bit ugly. It is best to not include header pins where LEDs will be connected and instead solder these resistors directly to the PCB. Both work, the latter just looks a little nicer. 

I2C module->module communication
In the top left corner we can see the connections required for I2C: power (orange), ground (grey), SDA (yellow), SCL (yellow),  Even if you are only building one module I would still recommend adding these connections for future use. It is important to note that this is the I2C setup for the master module. The master module requires two 4.7 kilo ohm resistors connected between SDA/SCL and power. The other (slave) modules do not require these resistors, i.e. the slave modules look identical to this diagram except they are simply without the two resistors (see step 12 for more info). 

Teensy++ internal pins
You will notice eight headers and two wires coming out of the Teens++ board. This is because some of the pins on the Teensy++ board (for whatever reason) are located internally. We have to add these headers/wires so we can access these pins. 

Snap in Teensy++
The last two images show an alternative way of connecting the Teensy++ to the PCB. If something breaks on your Teensy++ board it is extremely difficult to remove from the PCB. By carefully cutting the female headers to the appropriate length we can create a port that the Teensy++ snaps into. You could also do this for the CD4067BE. The disadvantage to doing this is that your height will increase. On my mixer I soldered the Teensy++ directly to the PCB (see images). On all my other modules I connected the Teensy++ via female headers. 

Soldering to the PCB
The video (step 6) shows how to solder to the PCB. Ensure each connection has a nice cone of solder securing it. The solder should never bridge two holes/connections otherwise you may have some serious problems. 

Okay that is all you need to know. Follow the diagrams carefully and build your board. You can build the fully featured board (exactly as you see it) or if you have a better idea what is going on here, add header pins only where you need them. In the latter case, ensure you have planned out where each component will connect to the board before soldering. Know what sizes of crimp housings you have available to help plan out your header layout; i.e. If you only have 1x4 crimp housings it would be foolish to solder five or six neighboring headers (read next step to better understand). Personally, I would advise just building the full-featured board shown in the images. 

Here is a blown up image of the PCB. 

HERE is the next level PCB, the Teensy Monster. This thing is gonna be super slick. 




Step 9: Connecting It Together


Alright now that you have built the top panel and the PCB it is time to connect them together. 

First fasten your PCB to your bottom layer with some hardware. Note that I did not include the PCB mounting holes in my laser cutting files cause I knew I would want to specify the position of the PCB hereafter. 

Hopefully you were wise and purchased many sizes of crimp housing connectors. You need to connect you crimp wire ends into the crimp housings. There is a specific orientation that causes the crimp connection to 'click' into the housing. Once the wire is connected properly to the housing you will notice that you cannot pull it out - perfect. In the case you have made a mistake and need to remove the crimp connection from the housing just tilt the tiny plastic flap in the front backwards and gently remove.

Now it is important you plug all ground/power/reading connections into different housings. Note the orientation of the ground/power/reading header pins on the PCB. If you understood step 4 it should become obvious how the crimp housings are to be created and connected. Using zip-ties or tape to group wires for certain types of components is highly recommended (see image). 

Do not mix up the power/input/ground potentiometer connections when plugging them into your board. Since I did not color coat my wires very well I did this once. I plugged them incorrectly into my CD4067BE and smelled burning shortly after plugging in the Teensy++. I immediately unplugged the USB and luckily did not fry the chip - close call. 

If you have many components you may just want to hookup and test a few at a time.



Step 10: Hey, What About The Jogwheels?


Jogwheels are nothing more than rotary encoders. 

The only tricky party to the jogwheels is mounting them.You have to mount them to the underside of the top panel otherwise the lip/nut interferes when you try to spin them. 

I found the best way to mount the jogwheels is by soldering the encoder to a mini PCB, then using the mounting holes on the PCB to secure the PCB/encoder to the top panel (see images). I cut out the hole in the top panel to be almost exactly the same diameter (6mm) as the shaft of the encoder. The cutout on the platter is a 'D' shape to match that of the encoder. Clearly, you could do a better job mounting these by using a standoff. 

Use felt feet on the underside of the platter to reduce friction. 

MK1 used a similar design for the wooden jog wheels. They worked a bit better. The weight and the grip (added by the polyurethane) made them easier to spin, almost effortless. 

If you want the most superior and responsive platter you have a number of options. 
- Build the recommended noise filter and install it on the underside of the proto-board. 
- Use more expensive mechanical encoders. 
- Upgrade to a super fancy optical encoder
I feel the recommended Bourns encoders paired with the noise filters give extremely good response, but I am no scratch DJ!
 


Step 11: All About The Code

Picture of All About The Code

I did my absolute best to make the code user-friendly. The code includes many comments to help you understand what is going on. You are not required to write any code, more-so, just fill in the blanks. Easy. Only if you want to add some LED features will you need to append some basic code. There is an LED example provided within the code to get you started.   

I was never trained as a coder, but I do consider this code to be pretty damn good! Thanks to my brother Neil for help with some of the more difficult sections.

The code is broken up into five sections: 
  1. Edit - The section where you are required to make the appropriate edits related to your controller using a fill-in-the-blanks method.
  2. Variables and functions - Holds the variables and functions used by the code. 
  3. Setup - This is where we define out pin configuration, informing the Teensy which pin in an input and which is an output.
  4. Loop - The brains of our whole operation. This function loops over and over while the Teensy is running. 
  5. Communication functions - These functions handle our messages.
Within these five sections you will often find the subsections for pushbuttons, LEDs, analog-in Teensy, analog-in multiplexer, and encoders.

If you are not using Traktor software, you will likely have to edit the rotary encoder MIDI messages. Check your software's documentation to understand the expected message format. When you figure it out please message me so I can add it to this Instructable. 

Although it is not imperative to understand all the code, I just want to explain one snippet of code which will help you understand how the control messages work. The code below sends analog messages for a potentiometer. There are three modes (debug, I2C, and MIDI) which you turn on/off in the edits. If debug is enabled, messages will be sent through USB to the serial monitor to help with debugging. 'serialDebugOut' is a very basic function I wrote which sends these serial messages and it can be viewed at the bottom of the code. If I2C is enabled, messages will be sent through I2C to the master module which will then forward the messages through USB. If MIDI is enabled, then this controller will send MIDI messages directly through USB to the computer. 'usbMIDI.' is a specific message used by Teensy++ for MIDI messages. Read more about Teensy MIDI here. Keep in mind you can edit the code to send many kinds of messages: Teensy USB Serial, Teensy USB Keyboard, Teensy USB Mouse, Teensy USB Joystick, Teensy USB MIDI, and Arduino Serial.

        if(enableDebug==1){ //SERIAL debug is on
          serialDebugOut("Analog",i,tempAnalogInMap);
        }
        else if(enableI2C==1){ //I2C
          serialI2COut('a',i,tempAnalogInMap,channelNumber);
        }
        else{ //MIDI
          usbMIDI.sendControlChange(i,tempAnalogInMap,channelNumber);  
        }

Read the code/comments over and over, it make take a few iterations to wrap your head around. You can learn a lot from the code. Constantly reference the Arduino library for sections you don't understand. 

The rotary encoder code is a nasty beast. If you are feeling ambitious you can read more about it here

**Likely there will be some improvements made to the code over time so continue to check back for the latest version.**

All code can be found here at GitHub. For this section use the code titled 'Controller Code'. Click 'ZIP' in the top-left to download. 



Step 12: Linking Module Together With I2C

Picture of Linking Module Together With I2C

To enable module->module communication you simply connect the modules together and enable I2C-mode in the code. Only your master module will plug into the computer via USB. You must connect all your modules together, then plug in the USB. If you plug in USB before connecting the modules together there will be no communication and all the controllers will freeze. 

DO NOT plug the modular connectors in backwards to the PCB or bad things may happen. Ensure your red cable is lined up with the power and the black cable is lined up with ground at all times. 

Below is a video showing module->module connections between three modules (one master, and two slaves). 


You can link as many modules together as you like. As you can see from the video, each slave module had a free I2C slot allowing more modules to be connected in series. 



Step 13: Testing Your Device

Picture of Testing Your Device
upload_code.jpg

This section is a bit tricky because the modules can operate in one of three modes: serial (debug) mode, MIDI mode, or I2C mode. If you turn one mode on, you must disable the other modes. It is not recommended to jump straight into MIDI mode because it is impossible to debug your controller this way. 

If you are using only one module here are the steps. 
  • Enable debug mode in the code.
  • It is critical that you comment out ALL lines of code which have 'usbMIDI' in them otherwise the code will not compile (annoying, but necessary).
  • Select 'serial' device from the Arduino tools->USB type menu. 
  • Upload your code and open your serial monitor. Ensure the connection speed in 9600bps. 
  • If your serial monitor is getting flooded with output you have hooked something up incorrectly or have improperly edited to the code to identify which pins are in use. Like I said earlier, it is best just testing one set of components at a time as opposed to all of them at once. 
  • If your serial monitor is working correctly you should see some output when you interact with the components. This output also informs you which mode number is associated with each pushbutton (so you can change the modes later if necessary).
  • Once everything is working in the serial monitor you can now proceed to MIDI. 
  • Disable debug mode in the code.
  • Select 'MIDI' device from the Arduino tools->USB type menu. 
  • Uncomment all the 'usbMIDI' lines you commented out earlier. 
  • Your controller is now be ready to send MIDI messages, and your computer should recognize it as a native MIDI device (as easy as that).
  • Now I would not recommend jumping directly to hookup with your software, rather, download a free MIDI sniffer (there are many out there) and test your MIDI messages in that first.
  • The sniffer, as well as your software, should recognize the device as 'Teensy MIDI'. 
  • Once you are happy with the MIDI output then proceed to mapping your controller with your desired software. 
If you are using more than one module here are the steps.
  • Follow the one module steps above for each module (without them linked together).
  • Enable I2C mode on each of the modules except the master module. Never enable I2C on the master module.
  • Again, you need to comment out all 'usbMIDI' lines.
  • Enable debug mode on the master module. So the master module will be running in serial mode and all other modules will be running in I2C mode.
  • Connect all modules together.
  • Check the output in the serial monitor. Messages sent from your other modules should now appear in the serial monitor with prefixes '(I2C)'. 
  • Now enable MIDI mode on only the master module.
  • Uncomment all the 'usbMIDI' lines on your master module which you commented out earlier.
  • You don't need to make any changes to your other modules, only the master. 
  • Test your MIDI output in the MIDI sniffer - voila. 
  • Remember, you must connect all your modules together, then plug in the USB. If you plug in USB before connecting the modules together there will be no communication and all the controllers will freeze.
Alright, this whole operation is a bit convoluted, but once you go through it one time you will understand what is happening here. It is surely annoying you have to continue commenting/uncommenting the 'usbMIDI' lines but it is unfortunately unavoidable. 

There is a degree of fickleness you must overcome when trying to upload from Arduino to Teensy, especially when you switch from serial mode to MIDI mode and back. I am not sure what causes these problems, but it is good to know that nothing is broken and if you keep retrying you should have success.  

One thing I have noticed about DIY electronics over the years is they never work the first time. There is always a small soldering blunder or connection error along the way. Don't get discouraged if things don't run smoothly during the first attempt. 

Someone asked me, 'can I create a controller which behaves both as a module, and as a standalone controller?'. With the code right now, no -  you would have to upload new code to toggle modes. I am going to try and fix this in the next code version. It will likely require installing one small switch on your PCB. 



Step 14: Connecting To Software

Picture of Connecting To Software

You can connect these controllers to Ableton, Max/Msp, Traktor, custom software, etc.

I have attached my mapping file for Traktor II Pro. This file will only work for my device but you can load it into Traktor and get an idea of how I mapped my encoders, potentiometers and pushbuttons. Traktor has included many amazing features that make custom mapping a breeze - my hat goes off to the brilliant team at Native Instruments.

Since I have no idea what software you will be using your controller with I can not offer much help. You will need to rely on other online resources to help you connect your controller to your preferred software. It is important you check that  the software you plan to use has custom mapping options available AND documentation (some do not). 



Step 15: Outro

Picture of Outro

There you have it! Although it only took me a few days to create this Instructable, the design/testing for this project has been ongoing for about 8 months. I was never trained in electronics/programming so there was a great deal of learning involved to reach this goal. Great fun. Great project. Onto the next.

Here are some projects done by others:


PLEASE send me pictures of your completed controllers so I can add them to the Instructable!

Thanks to PJRC, NI and Ponoko for your excellent products and support. 



Learn, make, think, repeat. Bridge the esoteric gap. 




1-40 of 252Next »
AightPOTO2 months ago

Thanks for this awesome tutorial !!!

but i have a question, do you have a headphone output on your controller ?

dougbeney10 months ago

Very interesting tutorial. I thought the wood enclosures on your controllers were epic.! I made a tutorial on how to make a midi controller as well. My tutorial explains how to make a very simple and easy midi controller. You can find it here if you are interested: http://www.midilifestyle.com/blog/basic-controller-build/

this would be nice for photoshop!

When will teensy monster be available?
omega9o1 year ago

Would it be possible to add velocity sensative pads?

Fuzzy-Wobble (author)  omega9o1 year ago

Send me the part specs and I can let you know.

s00500 made it!1 year ago

Thanks for your Inspiration!
I've built a single piece controller quite some time ago. I finnaly ducumented it on my website! Check it out!

http://lbsfilm.at/custom-built-arduinobased-midi-dj-controller/

IMG_1103.JPGIMG_1081.JPG

Bad Ass!

How did you get that VU meter to work? what are you using to drive it?

pixel51 year ago
Thank you so much for probably the best tutorial in the world! Great stuff! Lots of info and all. I do have a couple of questions tho: I am planning on attaching an XLR mic to the controller itself (like on pioneer cdj mixer) and found a thing which you can attach the lead to. Im stuck here. Im not sure how to connect the wires and in what way from that into the teensy board to connect it to the pc to use it as a live mic. If anyone could help me out here i would be incredibly thankful! Also I am planning kn attaching an LCD touch screen on an extension on each deck. I found relaively cheap 3.5 LCD touch monitors which should be okay with teensy (i can use arduino if required) in order to either see the wave forms in Traktor DJ (like on Pioneer CDJ). I do not know how I can do this, but I though whether its possible to use that screen to show a part of my pc screen so i can adjust it to show these things. Sounds complicated, but I basically want to use these screens to see whats going on in my DJ software without having to look at my computer. Also another quick question, is it possible to màke a headphone port so I can attach my headphones to it and use these as a pre cue (again like on the pioneer CDJ). All help and comments will be incredibly usefull as I am a complete beginner to this and I am trying to do everything as slowly but as well as possible.
pixel5 pixel51 year ago
Apologies for poor spelling
nbarman1 year ago

Can i use teensy 2 or teensy 3.1 ?

For 14 rotary pot

and 2 encoders

and 18 push button

lenny961 year ago

Hey Fuzzy, my friend and i made a controller but there are some problems: sometimes the jitter extremely and sometimes they are all just on 127. we tested many different things, but we couldnt find the problem. we even tried to make a ground shield against interferences but somehow it only worked for a short period and then it went back like it was before. do you know what the mistake/ problem could be? thanks in advance
btw: your instructable is awesome!
orell and lenny

_1170225.JPG_1170219.JPG_1170166.JPG_1170228.JPGFoto am 15.01.14 um 21.00 #2.jpg
Fuzzy-Wobble (author)  lenny961 year ago
Wow awesome! Nice work.
Others have complained about jitter too. Unfortunately it was an issue I could never replicate. I can probably show you a hack for the code that will help, but best look at your circuit first. Make sure you have a solid ground (laptop power plugged in). Are you running your analog ins through Teensy or the analog mux?

Thank you. Yes we grounded it and even try to make a little shield to prevent interferences. I looked for short circuits or slack joints but i havent found anything. I used quite a lot analog inputs, so we had to use the demultiplexer and all analog inputs. I mostly solved the jittering problem by changing the analogThreshold of the teensy and the mux, but now most of the potentiometers don't work anymore while all digital inputs still work. the analog ins sometime spit out random values and sometimes many inputs appear to have the exact same signal(like they were connected). it appears to be a slack joint or something alike but i tested all connections and they were fine. Do you know what the source of this issue could be?

(and sorry for any writing mistakes, im not a native english speaker)

Fuzzy-Wobble (author)  lenny961 year ago
TeensyMonster is coming out this month: teensymonster.com

I will be updating all the documentation and code so everything is super easy to follow and reliable.

If your controller still has issues I suggest switching to the TeensyMonster framework!

still coming out this month? I am in the midst of building my controller and hoping to use this for my project.

The jittering in my controller was due to code issues. These are solutions that helped for me and might help with your problem.

(1) The original version of the code has a mistake with the analog teensy pins. See highlighted part in attached pic. It should be 38,39,40 etc.

(2) It's very important to set the analog pin values to 0 if there's no pots connected to those pins. This should be done for the teensy analogs and the mux analogs.

(3) I deleted the sample LED code. That also caused jitter issues with my controller. If you running your LED's from the Teensy, you can comment out the LED code and check for jitter again.

I'm no pro and this could be some basics that you've checked already, but maybe 1 of these can help.

Capture.PNG

Here's a few pics of my Virtual DJ based controller. 3 Of my pots on teensy analog pins 0-2 is not working properly. It's giving the same output as pins 0-2 in the mux eg. analog 1 for both pot 2 on the teensy and pot 2 on the mux in the serial monitor. I've got 19 pots - 16 on the mux and 3 on the teensy. Please see my previous post.

3.jpg4.jpg1.jpg2.jpg20140307_210652.jpg

I managed to find a solution to my issue. I don't think it's the most efficient solution but it works. I told the teensy that there's 24 analog pins and gave dummy pin values to the first 16 pins. This allowed it to assign values above 15 to the teensy analogs. The mux is using analog 0-15 and the teensy 16-23. See pic.

Capture.PNG

Please help!!!!!!!!! I'm not to familiar with coding. I have a problem with mapping my analog inputs in Virtual DJ. When I map the Teensy analogs, it gives me CTRL 0 to CTRL 6 and when I map the Mux Inputs, it's CTRL 0 to CTRL15. So the first 7 inputs of the mux and teensy have the same name in the mapping. That means if I turn 1 of the 2 knobs and both is maybe CTRL 3 for teensy and mux analog, it changes 2 controls on VDJ. Is there possibly a way to give the teensy or mux analogs other names or different signals?

Capture.PNG
commrace1 year ago

great work Mr. Fuzzy. i managed to modify your code for teensy 3.0 but i cannot map encoders in traktor to browse trough list for example.... can you help me please? thank you!!!

AmpOwl1 year ago

How difficult would it be to adapt the code for an Arduino UNO?

Fuzzy-Wobble (author)  AmpOwl1 year ago
very do-able but i would recommend teensy
hilukasz1 year ago

SO sick. thanks for sharing.

Awesome instructable. Started prototyping with an arduino and it only worked once. I've ordered my teensy++ (after stumbling across this instructable) and as you can imagine is very expensive in South Africa. But oh man, this is the best controller for midi projects and easy to setup via arduino IDE. I'm not a DJ, only an electronic enthusiast that accidentally saw an arduino project on youtube 3 months ago. Since then I've ordered a few arduinos to play with. Man, this is so much more interesting than fixing old car radios for friends. I've battled a bit with the jogwheel and browser wheel as this was my first time working with encoders. It was actually working and my issue was in the mapping of the dj software. That was because I did not follow step 4 to check if everything is working. What a waste of time. Nevertheless, I just wanted to know if I can add a 74HC595 shift register for more inputs. I'm about 4 inputs short and would rather do without it, than sell my other kidney to buy another teensy. Also I'm no coder and that is my problem. I can do minor tweeks in the code but would not be able to add the shift register in the code. Anybody please help.
Hallo again Mr.Fuzzy,
now I am really looking forward to some code-updates. I would especially be interested in how the teensy can not only send, but also receive MIDI-signals from Tractor. Example: an LED which lights up, when a Deck is playing. Tracktor can send MIDI-Out-Singnals, but which code do I have to insert where to make the teensy receive this signals? Do you have any experience with it, or do you know where to find soltions? Thanks for your help!
im not into arduino really, but this is a big instructable, thunbs up
jaxter1842 years ago
So my I2C connections aren't working. The master module works in the midi sniffer, but the other ones don't. Here is a picture of the first few lines of the code in each one.

I checked the hardware multiple times, and it turns out I accidentally had the resistors set up to the ground, but it turns out that wasn't the problem.
Trubleshooting.png
Sir,
Was waiting for this tutorial.
Can you please upload the schematic for better understanding?
And waiting for a DJ Vinyl Scratcher Tutorial
Could you point me in the right direction for programing button combinations that trigger separate actions for push buttons?
sunpialia2 years ago
more high quality LED lights at the site http://www.ledlightshub.com.
hello again. So i didnt get a bread board. how would you suggest testing my components? All i ordered is the teensy. not the other larger pcb. I am planning on soldering directly to the teensy so I am kind of hesitant to just solder everything then do the coding even though the only buttons im using now are arcade buttons, so simple on/off switches. I plan to use only 0-16 I/O's on the teensy then chaining all the grounds.
Fuzzy-Wobble (author)  nocturnalambition2 years ago
you must have a breadboard for prototyping.

https://www.adafruit.com/products/239

do not solder directly to the teensy unless you are pro and enjoy spending hours de-soldering.

thank you so much for posting this.

So, I have a question regarding the LED Situation. I was wanting color changing LEDs under some clear rim Sanwa buttons. I'm sure that I could get them to light up but I want complete control over every buttons color. for example when I play one song I want this color scheme/template and a different one for a different song. I am basicly just making a midi fighter/mixer. below is what I have been thinking:

8x8 arcade buttons(color changing led on button rims)
8 faders
solo and mute buttons on each fader(leds under each)
2 bus/eq knobs for each fader
8x8 fx knobs
spring loaded mod wheel

what kind of pcb would i need for this? It needs to be mac compatible and plug and play. I guess i'm willing to shell out if i have to considering that this is like 3 controllers in one. Please point me in the right direction master.
Fuzzy-Wobble (author)  nocturnalambition2 years ago
64 arcade buttons? That is a lot. This framework will not support that many inputs. You need to get some i2c i/o expanders (mcp23017) or some shift-registers. Basically that will require lots of custom circuitry and coding.
drsalty2 years ago
Hi there Fuzzy-Wobble!
First off this is a fantastic instructable. I have built a controller and done the coding, but I have one major problem left: how to use it with Ableton live. I haven't been able to work out how to map/script it, so sadly it has sat in the corner for the last few months. I tried a midi sniffer and the messages seem fine. If anyone could help me or point me to a tutorial that would be very much appreciated!
Ps. It's really nice to see that even so long after you released this instructable you still reply to comments.
Fuzzy-Wobble (author)  drsalty2 years ago
Looks like djerk may have the solution you are looking for. I have never mapped to Ableton but I know it is possible. I have seen it done many times.
djerk2 years ago
drsalty, you could try adding the controller manually if ableton's not picking it up.

1. Go to the following directory on your computer: Mac: [Your home folder]/Library/Preferences/Ableton/[your version]/User Remote Scripts/ Windows: [Windows boot drive]/Users/ [your Username]/AppData/Roaming/Ableton/[your version]/Preferences/User Remote Scripts/

2. You should see a UserConfiguration.txt file in this directory. This is the template that you will use to create custom controller mappings for Ableton.

3. Create a new directory under "User Remote Scripts" and name it what you want your controller named in Ableton.

4. Copy the UserConfiguration.txt file in to the new directory for your controller. (make sure to copy and not move, as you may need a clean template later.)

5. Open the UserConfiguration.txt you just copied in to the new controller directory and follow the template to specify what you want each knob/button/slider to control (You will need the MIDI CC data from each control on your controller to configure this file.) *note* defining Macro 1 - 8 is very powerful as you can place your soft synths in instrument racks and define macros for commonly used controls. (controls like: Cutoff, Resonance, Osc Pitch, modulation, Envelope settings, AMP Volume, etc.)

6. Save UserConfiguration.txt Now open Ableton and go back to the MIDI tab in preferences. If you've done everything correctly, you will now notice your custom controller name in the 6 pull downs for Instant Mappings.

Source : https://forum.ableton.com/viewtopic.php?f=1&t=167341
Hi Fuzzy-Wobble,



I'm so glad I've found your instructable, it has been really informative.

I'm currently at University in England, studying a degree in Music Technology. I'm basing my Final Year Project on the creation of a MIDI controller.



So far, I have added a MIDI output to an Arduino Uno (which seems a bad move now, looking at your instructable!) which is then connected to my computer via a MIDI to USB cable. The arduino is programmed to play MIDI notes.



I really like this instructable as I'm no coder. Is it going to be really difficult for me to follow this instructable with an Arduino? I understand your reasonining for not choosing one, but I've overcome the main issue of USB/MIDI now. Do you have any pointers to help me along?



Many thanks again, this instructable and your final products have reinspired me again :)
1-40 of 252Next »