• Welcome to Circuitbenders Forum.

I made an Arduino-based MIDI-to-trigger for the CB55

Started by Jaytee, September 21, 2016, 08:15:38 PM

Previous topic - Next topic

Jaytee

Not sure if anyone is still building these or still needs a MIDI-to-trigger solution, but I finally got around to wrapping mine up. Should be pretty easy to set up, even if you have zero experience with Arduino. If you can build the CB55, you can make this MIDI-to-trigger work.

Anyway, if anyone has interest in this, I'll post my code and write up hookup instructions.

Circuitbenders

This kind of thing is always useful, especially if its simple.

Any details you can post would be gratefully received.   :)
i am not paid to listen to this drivel, you are a terminal fool

Jaytee

#2
Sure, just let me figure out how to make one of those pretty arduino diagrams!

In the meantime, here's the code.

#include <MIDI.h>

//some basic code for the CB55 drum machine
//currently, you must use the trigger conditioner (TRIG IN 1),
//as this code outputs gate signals instead of actual trigs
//for everything but accent

//should be easy enough to convert them all to triggers if needed, just
//take a look at the accent code

MIDI_CREATE_DEFAULT_INSTANCE();

const int rimPin = 2;     //define pins for 4 instrument gates and accent trig
const int kickPin = 3;
const int snarePin = 4;
const int hatPin = 5;
const int accentPin = 8;

int accentState = LOW;              //some variables so that accent
unsigned long previousMillis = 0;   //sends as a trigger, not as a gate
const long interval = 10;

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
    //a series of if/elses to parse incoming MIDI data and turn on gates
    //MIDI notes for the four voices correspond to GM drums
  if(pitch == 36){
    digitalWrite(kickPin, HIGH);
  }else if(pitch == 37){
    digitalWrite(rimPin, HIGH);
  }else if(pitch == 38){
    digitalWrite(snarePin, HIGH);
  }else if(pitch == 42){
    digitalWrite(hatPin, HIGH);
  }

    //triggers an accent if velocity is 100 or more
    //note: CB55/DR55 accents are GLOBAL, they affect all voices at once
  if(velocity > 99){
    previousMillis = millis();
    accentState = HIGH;
    digitalWrite(accentPin, accentState);
  }
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
    //turn off gate signals at note off
  if(pitch == 36){
    digitalWrite(kickPin, LOW);
  }else if(pitch == 37){
    digitalWrite(rimPin, LOW);
  }else if(pitch == 38){
    digitalWrite(snarePin, LOW);
  }else if(pitch == 42){
    digitalWrite(hatPin, LOW);
  }
}

// -----------------------------------------------------------------------------

void setup()
{
    // Connect the handleNoteOn function to the MIDI library,
    // so it is called upon reception of a NoteOn.
  MIDI.setHandleNoteOn(handleNoteOn);

    // Do the same for NoteOffs
  MIDI.setHandleNoteOff(handleNoteOff);

    // Initiate MIDI communications, listen to all channels
  MIDI.begin(10); //currently set to listen only on channel 10
  //MIDI.begin(MIDI_CHANNEL_OMNI); //for omni

  pinMode(rimPin, OUTPUT);   //set pin modes to output
  pinMode(kickPin, OUTPUT);
  pinMode(snarePin, OUTPUT);
  pinMode(hatPin, OUTPUT);
  pinMode(accentPin, OUTPUT);
 
}

void loop()
{
  MIDI.read();  //listens for incoming MIDI

    //following code makes sure that the accent pins is only triggered for 10ms
    //could be adapted for other pins if trigs are desired rather than gates 
  unsigned long currentMillis = millis();

  if (accentState == HIGH) {
    if (currentMillis - previousMillis >= interval) {
      accentState = LOW;
      digitalWrite(accentPin, accentState);
    }
  }
}

Jaytee

Ok, every time I try to post the tutorial I wrote, it throws up a FORBIDDEN error and then the site won't load for like ten minutes.

Anyway, I posted to Muff Wiggler the exact tutorial I going to post here; perhaps just a simple link won't break the whole site?

https://www.muffwiggler.com/forum/viewtopic.php?p=2343333#2343333

Edit: Hey! Success!

Jaytee

Sorry for bumping this old thread. Just wanted to make sure this tutorial was backed up somewhere besides muffs.

Here's the how-to. Hopefully even a complete newbie to Arduino can follow this guide.

First of all, you want an Arduino. Arduino Uno (actually SparkFun RedBoard, but they're equivalent) is what I used. If you want to save money, you can find cheap clones on eBay, but you may have to find some special USB drivers to make them work. If this is your very first Arduino project, I suggest getting either an official Uno or a RedBoard, since they're more of a "known quantity."

Next, you need a way to interface your Arduino with MIDI. By far the simplest solution here is to grab one a SparkFun MIDI Shield. This plugs directly into the top of your Arduino, quickly adding a MIDI IN and MIDI OUT port (and the MIDI OUT can apparently be configured as MIDI THRU on the most recent version by adding a solder jumper). Wiring up your own MIDI circuit to add to the Arduino is really pretty easy and cheap, but it's beyond the scope of this tutorial; I went with the shield option because I had one handy already.

Lastly, you want something to power both your Arduino and your CB55. Pretty much any 12v AC/DC, center-positive wall wart should do; make sure it fits the barrel connector of your Arduino, but don't plug it all in yet.

You're also going to need the Arduino software (IDE) and the Arduino MIDI library. For the latter, scroll down a bit, and look for the section titled "What do I need to do?" which will give you the download link and instructions on installing it for use in the Arduino IDE.

Now for the fun stuff! Plug your Arduino into your computer using USB. Open up the Arduino software. Under Tools/Board, choose Arduino Uno, and under Tools/Port, choose the USB port that your Arduino is hooked into. If you're using the MIDI Shield, make sure the small switch on top is set to "PROG" (program), or just unplug it for the time being. Copy and paste the above code into a new sketch, then hit the little arrow in the upper left (Upload). Your Arduino should go all blinky-blinky for a few seconds, then, hopefully, the sketch window will say "Upload successful." Good work, the custom software is now loaded onto the Arduino.

Unplug your Arduino from USB now, and if you haven't yet, plug the MIDI shield into the top of the Arduino (at this point, you want the small switch on your MIDI shield to be set to "RUN"). Set up your wiring according to the image below. You can use the stackable headers that came with the MIDI shield, or if you want a more permanent solution, you can put a "screw shield" between the MIDI shield and the Arduino, which breaks all the pins out to screw terminals. Or, there's at least a half dozen other ways to make a nice permanent connection, but those are the two I used (headers while debugging, then screw shield once it was finished).

Here's the hookup diagram: https://m.imgur.com/aWDT1Gl


After that, you're done! Plug in your power supply and start pumping out some analog drums!

A few notes:

- Right now, it's hard-coded to conform to GM drums. In other words, it only listens on channel 10, and the drums are triggered by MIDI notes 36 (kick), 37 (rimshot), 38 (snare) and 42 (closed hat). The accent is triggered with any velocity over 99. I tried to include enough comments in the code to make it easy to change this stuff if anyone felt like it
- Currently, you *must* use TRIG IN 1 along with the accompanying trigger conditioning circuit. Only the accent sends a trigger signal, the other instruments send gates. It wouldn't be too hard to convert the code to send out only 10ms triggers, but I had already installed the trigger-conditioning circuit, and the code should run marginally quick this way (no idea if changing to all gates would significantly slow it down; probably not). Again, there are comments in the code to help anyone interested in doing this.
- Overall, I spent a decent amount on name brand Arduinos and fancy shields. If you're a scrappy DIYer, you could figure out how to do a lot of this on stripboard *much* more cheaply than I did mine. If I were doing it all again, that's exactly the approach I would take, but I bought all of this stuff a year or two ago when I was much newer to DIY electronics; it was definitely nice to have my hand held a bit by avoiding designing my own boards. So it really comes down to how much money you want to spend vs how much time and effort you want to spend.