m-audio trigger – hacking the 4051 (analog multiplexer)

PCB from M-audio trigger finger

I salvaged some boards from my old M-Audio trigger finger drum/midi pad, i do this to keep some modules around that might be handy someday. This is the potentiometer board originally for MIDI CC commands.

 

This is a basic but useful foundation for whatever you want to create with potentiometers. Im also hoping this could inspire someone to try something similiar, instead of throwing your old stuff away. You could also easily build this circuit if you would like, since the components are minimal.

The M-Audio board uses a 4051 analog multiplexer, which i have no previous experience in using. The circuit is just 8 standard potentiometers wired 5v & gnd and middle pin to the 4051 inputs. The 4051 has 6 wires coming out for us to test. One wire is for VCC (usually 5v but could be 3v3), one wire is for ground, one wire is for outputting the values of the potentiometers and the remaining three wires are for receiving binary input messages (from whatever you have outputting that, in my case Arduino).

This 4051 setup uses 3 inputs to receive binary. The binary that is sent will determine what analog potentiometer value the 4051 will distribute to us. The potentiometer value will be sent out the 4051s common I/O pin which is connected to Analog 0 pin on my Arduino. With the 4051 i get 8 potentiometers on only 6 wires. By rapidly telling the 4051 “I want to read pin number ###” in binary language and then reading the output from 4051 (Analog 0) i can store the value of the chosen pin to a variable in my Arduino code. By using arrays this becomes simple and smooth to operate into something useful. The only downside with the array is that the numbers of the array might not match with the specific sequencer/potentiometer order but that could be fixed by just roughly switching around the wires or fixing the array numbering.

 

 


Looking at the circuit board i can easily tell that the first two wires on the edge of the cable are VCC and GND (they usually are). Its obvious because both of them go to more than just one component.

Now the rest of the job is just to figure out what the other wires are. To do this its easy to check the 4051 IC datasheet to see how the pinout is ordered and then determine what wire i should connect to my Arduino.

After figuring this out i just run the code to see if the potentiometers are sending values correctly.
I took parts of this code from the guide intended for the Sparkfun 4051 breakout:

const int selectPins[3] = {2, 3, 4}; // This is the outputs going to the "select pins" of the 4051
// aka the pins that we will use to tell the 4051 which potentiometer we want to recieve a value from

const int aValPin = A0; // the analog in pin which will receive the values of the potentiometer (selected by the pins above)

void setup()
{
Serial.begin(115200); //For serial.print
// Make the select pins into outputs
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], HIGH);
}

///
pinMode(aValPin, INPUT); // Make the value recieving pin into an input

// Print the header:
Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7");
Serial.println("---\t---\t---\t---\t---\t---\t---\t---");
}
void selectMuxPin(byte pin)
{
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}
void loop()
{
//go through all 8 channels of the multiplexer
for (byte pin=0; pin<=7; pin++) //"Loop the following until we have read 8 potentiometers"
{
selectMuxPin(pin); // Select one at a time
int readValue = analogRead(aValPin); // read aVal pin to store the potentiometer value
Serial.print(String(readValue) + "\t");

}
Serial.println(); //After we have checked all the potentiometers print a New Line
delay(1000);
}

After testing the code i turned it into sending MIDI CC commands to the Volca samples different channels. The Volca sample behaves differently than other devices. On the volca sample every channel represents a sample number. So to control the speed (MIDI CC command 43) of every sample I use this code:

#include <MIDI.h>
const int selectPins[3] = {0, 1, 2}; // This is the outputs going to the "select pins" of the 4051 
// aka the pins that we will use to tell the 4051 which potentiometer we want to recieve a value from

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int aValPin = 3; // the analog in pin which will receive the values of the potentiometer (selected by the pins above)
uint8_t ccnumber;
uint8_t velocity;
int notetest;
int plusvalue = 0;


void setup() {
Serial.begin(115200); //For serial.print
// Make the select pins into outputs
for (int i=0; i<3; i++)
{
pinMode(selectPins[i], OUTPUT);
digitalWrite(selectPins[i], HIGH);
}

Serial1.begin(31250); //MIDI output serial port
MIDI.begin(); 

pinMode(aValPin, INPUT); // turn the 4051 input pin into an input

ccnumber=51; //a variable for what CC command to send so i //can easily modify it without changing every line of code

velocity=49; //set velocity value for the output
notetest=0;
plusvalue=0;

// Print the header:
Serial.println("Y0\tY1\tY2\tY3\tY4\tY5\tY6\tY7");
Serial.println("---\t---\t---\t---\t---\t---\t---\t---");
}

void selectMuxPin(byte pin)
{
for (int i=0; i<3; i++)
{
if (pin & (1<<i))
digitalWrite(selectPins[i], HIGH);
else
digitalWrite(selectPins[i], LOW);
}
}


void loop() 
{

//go through all 8 channels of the multiplexer 
for (byte pin=0; pin<=7; pin++) // "Loop the following until we have read 8 potentiometers"

{ 
selectMuxPin(pin); // Select one at a time 
int readValue = analogRead(aValPin); // read aVal pin to store the potentiometer value
readValue = map (readValue, 0, 1023, 0, 127);
// MIDI.sendControlChange(ccnumber, readValue, pin+1); 
// Serial.println(ccnumber);
// Serial.println(readValue);
// Serial.println(pin);
}

notetest = map (plusvalue, 0, 48, 0, 127);

MIDI.sendControlChange(43, notetest+43, 1); 
MIDI.sendNoteOn(1, 127, 1);

if (notetest >= 128)
{notetest=43;
}
plusvalue++;

Serial.println(); //After we have checked all the potentiometers print a New Line
Serial.println(plusvalue);
Serial.println(notetest);
delay(3000);
}

 

2 comments

  1. Analog Umeåit says:

    HACK THE PLANET!

    Askul att se dessa projekt. Det borde styras upp så du kan dumpa koden på något bra och smidigt ställe, så filerna är lättare än copy-paste från WordPress som säkert gör om vissa tecken mm. till skräptecken (typ bindestreck till talstreck och så).

    • Synthbror says:

      Vad roligt! Ja det är en bra ide, förstår inte varför det verkar så krångligt att embedda i wordpress dock. Ska kika på det! Ja en del projekt skulle nog passa skitbra på music hack! Om du vill ha mer detaljer kring något projekt till så är det bara att hojta!

Leave a Reply

Your email address will not be published. Required fields are marked *