Fall 2018 Digital Lab 8

In this lab you’ll:

1) Make a multi channel MIDI drum sequencer.
2) Solidify your final project idea.

Part 1) Multi Channel Drum Sequencer

a) Start with your one channel drum sequencer from last week. Make sure it still works.

b) Add two buttons right next to each other, set their pin numbers nextChannelButtonPin and prevChannelButtonPin and set their pinModes. Make the one on the left the prevChannelButtonPin, and the one on the right the nextChannelButtonPin.

c) Add an int variable called channelDisplayed.

This variable should work exactly the same as the counter variable from the lecture homework from last week. You press the one button, its value goes down by one. You press the other button, its value goes up by one. If it’s value goes less than 0, set it back to 2. If it’s value goes above 2, set it to 0.

d) Replace your on[4] array with a multidimensional array containing 3 arrays, each of which has a length of 4.

boolean on[3][4] = {
  { LOW, HIGH, LOW, HIGH },
  { LOW, HIGH, HIGH, HIGH },
  { LOW, LOW, LOW, HIGH }
};

Think of each of the three arrays as a channel or instrument in your sequencer.

e) Anywhere you had on[someVariableOrNumber] replace it with on[0][someVariableOrNumber]. Upload and make sure it still works.

So right now you have a three channel sequencer, but you can only see and edit the first channel.

f) Use your two new buttons and channelDisplayed to control which of the three channels is being displayed on the LEDs.

It should still be sending the MIDI notes according to what’s on the first channel.

g) Update your code so that the channel currently displayed on the LEDs is also the one that controls your MIDI noteOns.

h) Make an array of 3 called midiNotes.

int midiNotes[3] = { 60, 62, 64 };

You can set the three numbers to whatever MIDI notes you want it to play.

i) Add one or more for loops to the part of your code that sends the MIDI notes to your DAW so that it will work with and play all three channels simultaneously.

As usual take a good clear video and include your code in your lab report.

I highly recommend in Arduino going to Edit -> Copy As HTML and using that you paste your code into WordPress rather than using  anymore since lately that seems to have all kinds of bugs in it and Copy As HTML seems to work way better.

Part 2) Start to finalize your Final Project

In class next week we will go around the room and everyone will share their Final Project idea. Be prepared to talk about your project for a minute or two at the start of class.

Lab 13 – Final Project Report

Final Assignment: Final Project Report

Next week’s class on 12/12 is our last class.  Next week in class you will be sharing your final project with everyone.

Your final assignment, due by next Friday, is your Final Project Documentation, which will be your final blog post for the semeseter.  It will consisting of the following:

1) At least one clear photo of your project.

2) An explanation of what your project is and what it does from a non technical perspective.  Think about this is as how you would explain your project to friends, family, students on the first day of this class next year, and random people on the internet without any knowledge of electronics.

3) A thorough technical explanation of how your project works in terms of code and circuits.  Imagine you are trying to explain it someone who wants to learn how your project actually works but hasn’t taken this class, or to yourself 3 months ago.  A schematic or diagram would also be helpful but is not required.

4) Your code, commented.

5) A clear, coherent video of your project working.  This should be at least 30 seconds long.  If you are the one demoing it, you must find a tripod or another person to do the camera work for you.  You may not hold your camera with one hand and demo your project with the other.  It must be 100% clear what’s happening in the video.

Lab 12 – Final Project Day 2

We’ll be working on Final Projects in class today.  You should do a lab report just like the one from last week with a status report.  On account of the holiday it’s due by midnight Monday 12/1, though it is in your best interest to get it done before then.

For students looking to make MIDI controllers I’ve added two tutorials on sending Midi from Teensy to Ableton Live.

Tutorial 1: Controlling MIDI Instruments with Ableton Live

Tutorial 2: Controlling Effects with MIDI Control Change Messages in Ableton Live

Timeline for rest of the semester:

12/5 – Final Project finished and working

12/12 – In class presentation and report on your Final Project due.

Your report will consist of an in depth documentation of your project, the code, the circuit, and will include a good 1+ minute video demo.

Controlling Effects with MIDI Control Change Messages in Ableton Live

This tutorial assumes you’ve gone through the Controlling MIDI Instruments with Ableton Live tutorial, and have successfully gotten MIDI communication working between Teensy and Ableton.

Part 1) Make sure Teensy is able to talk to Ableton

Make sure you have connectivity between Teensy and Ableton as described in Part 2 of Controlling MIDI Instruments with Ableton Live.

Part 2) The code

Take a look at the following code and upload it to your Teensy.  It uses one potentiometer, which you’ll need to wire up.

int pot1Val = 0;

int midiChannel = 3;

int controlChange1Val = 0;
int lastControlChange1Val = 0;

void setup() {
}

void loop() {

  lastControlChange1Val = controlChange1Val;
  pot1Val = analogRead(1);
  controlChange1Val = pot1Val/8;
  if(controlChange1Val != lastControlChange1Val) {
    usbMIDI.sendControlChange(1, controlChange1Val, midiChannel);
  }

  //its good to have some small delay in here
  delay(1);
}

Part 2) Add some audio.

Drag an mp3 or other audio file from Finder or directly from iTunes into one of the Audio channels.

add audio

It will pop up in one of the rows and load itself into Ableton. Once its done uploading hit the spacebar and it should play. (It will stop when you hit it again).

Part 3) Add an effect

From the left menu select Audio Effects and then select an effect. I selected Auto Filter. If you haven’t used Ableton before you should probably pick Auto Filter too.

select audio effect

Click and drag Auto Filter or your other effect into the empty box on the bottom of Ableton that says “Drop Audio Effects Here”.  It’ll pop up with a bunch of options.

filter

 

Turn your potentiometer all the way off.

Right click the frequency cutoff parameter and select Edit MIDI Map.

editimidimap1

Turn the pot and the name of the parameter should suddenly pop up, along with the Channel and the Control Change number (under Note/Control) which you set in your code.  If you want to undo this mapping, just click and select it on the list and hit Delete.

midi mapping set

Now, go back to the effect, right click, and uncheck Edit MIDI Map.

deselect edit midi map

Everything should return to normal colors.  Turn your pot and you should see it changing the filter cutoff on the graph.

Hit space bar to turn on your music.  Your music should be plugged into your filter.

You can add as many more pots as you want, set them to different Control Change values, and then add more effects to Ableton and go through the same steps and add all of them.

If you’d like to use your effects to process the instrument you created in the other tutorial, on the Audio channel you where you added the effects set it’s Audio From: dropdown to your instrument.

Controlling MIDI Instruments with Ableton Live

Take a look at the following code and upload it to your Teensy. Note the button which will send the MIDI notes and wire it up.

Part 1) The code

int button1Pin = 12;
boolean button1Pressed = false;

int button1Note = 65;
int midiChannel = 3;
int midiVelocity = 127;

void setup() {
  pinMode(button1Pin, INPUT);
}

void loop() {
  if(digitalRead(button1Pin) == HIGH) {
    if(button1Pressed == false) {
      button1Pressed = true;
      usbMIDI.sendNoteOn(button1Note, midiVelocity, midiChannel);
    }
  }

  if(digitalRead(button1Pin) == LOW) {
    if(button1Pressed == true) {
      button1Pressed = false;
      usbMIDI.sendNoteOff(button1Note, 0, midiChannel);
    }
  }
}

Part 2) Enable MIDI from Teensy in Preferences

Open Ableton. Find the Preferences menu (In Windows it’s under Options > Preferences). It should open this popup:

preferences for midi

In the gray buttons on the left side click MIDI Sync.

On the top middle where you see a bunch of dropdowns under Input, click the first one and select Teensy MIDI.

In the middle where it says Input: Teensy MIDI, click the buttons directly to the right under Track and Remote so they’re turned on.

Close Preferences (it will save automatically).

3) Make your MIDI instrument

You should see 4 columns that look like this:

4 ableton instrument columns

These are “tracks” where you can create your instruments. Click on the top of the leftmost on on top where it says MIDI.

In the middle of that column, MIDI From: should be set to Teensy MIDI.  The dropdown underneath that can be either All Channels (if you’re just using one channel for your project), or the MIDI Channel you set in your code.   Monitor should be set in In.

All the way on the left side of your screen you should see CATEGORIES.

categories

Click Sounds and then select an instrument/sound from the options.  Decide whichever one you want and then click and drag in onto the column of the track you set up.  The top part, which said MIDI a second ago, should now be titled with whatever instrument you chose.  I chose “Bowed Square” as you can see below.

track with instrument

Try it! Your instrument should play.

Quick Multiplexer Lesson

Please create the following circuit and post a 10 second video clip of it working on your blog. You have until the end of the semester to do this.

A multiplexer allows you to route a single signal or voltage to a large number of different output channels, or to route a large number of inputs into a single input channel.

Take a look at your multiplexer (or, the photo of it above).  On the right side you’ll see pins SIG, S0, S1, S2, and S3.  On the left side you’ll see C0 through C15.

Connect VCC to power.
Connect EN and GND to Ground.
Connect S0 to digital pin 2.  S1 to digital pin 3.  S2 to digital pin 4. S3 to digital pin 5.
Connect SIG to whatever resistor you normally use for an LED and connect the other end of it to power.
Connect C0, C1, C2, and C3 to LEDs to ground.

Upload this code:

int controlPins[] = {2,3,4,5};

void setup() {
  for(int i=0; i<4; i++) {
    pinMode(controlPins[i], OUTPUT);
  }
}

void loop() {
  for(int i=0; i<4; i++) {
    routeSignalToPin(i);
    delay(500);
  }
}

void routeSignalToPin(int pinNum) {

  for(int j=0; j<4; j++) {
    digitalWrite(controlPins[j], (pinNum >> j) & 1);
  }
}

It should turn on the 4 LEDs one at a time.

How it works.

SIG is the signal you want to route – it can be audio, MIDI, Serial data, or just a set, unmoving voltage.  Really anything, so long as its about 5 volts or less.
S0, S1, S2, and S3 are the select pins.  You connect these 4 pins to 4 digital pins on your microcontroller, and depending on which ones you set HIGH and LOW, it will connect the SIG pin to one of the 16 output pins C0 to C15.

Think of S0 to S3 as the 4 bits of a 4 bit number.  As you know, a 4 bit number can be from 0 to 15.  S0 represents the first bit, S1 represents the second bit, s2 the third bit, and s3 the fourth bit.

Say you want to route your signal (whatever you’ve connected to the SIG pin) to pin C11.  To set this you need to know the binary, 4 bit number for 11.  This number in binary is 1011.

If the first bit (the 1 in 1011) is a 1, you digitalWrite the Teensy pin connected to S0 HIGH.  If it’s a 0 you set it LOW.
If the second bit (the 1 from 1011) is a 1, you digitalWrite the Teensy pin connected to S1 HIGH.  If it’s a 0 you set it LOW.
Third bit is a 0 (1011), so, you digitalWrite the pin S2 connected to LOW.
You hopefully can guess what you do with S3 and the fourth bit (1011).

And that’s how it works.  You set S0 to S3 with digitalWrite()s, and it controls which of the 16 channels C0 to C15 is currently connected to SIG.  You can also connect pots or switches on any of the 16 different channels, and use SIG as a digital or analog input into your microcontroller and doing the standard digitalRead or analogRead on it.