Tuesday, 16 March 2010

Hand-cranked MIDI sequencer from a baked bean can

One empty baked bean tin, some lego and a stack of little magnets... stick magnets on the tin and slide them about to 'program' the sequencer, then grab hold of the 'transport control' and crank away.... The breadboard contains 5 hall-effect switches and a PIC16F688 to generate MIDI note on/off information. This is piped to Reason in the first half of the clip and to a Dave Smith Mopho synth in the second half.
I reckon with a baked bean tin about 16ft in diameter and about 25,000 magnets you could dump your sequencer software.. and you'd be getting some good aerobic exercise to boot :o)



Here is the schematic (if you make one, note that hall effect switches need the magnet to be the right way round.. if it does not trigger, flip the magnet over)


And the code (SourceBoost C... NOTE: you'll need programmer hardware like PICKit2 to burn the program to the PIC chip)
// HALL SENSOR TO MIDI NOTES

// J.Hotchkiss Mar2010

#include <system.h>

#include <memory.h>



// PIC CONFIG

#pragma DATA _CONFIG, _MCLRE_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT

#pragma CLOCK_FREQ 8000000



#define P_SENSE1 porta.5

#define P_SENSE2 portc.2

#define P_SENSE3 portc.1

#define P_SENSE4 portc.0

#define P_SENSE5 porta.2



typedef unsigned char byte;



// INITIALISE SERIAL PORT FOR MIDI

void init_usart()

{

pir1.1 = 1; //TXIF transmit enable

pie1.1 = 0; //TXIE no interrupts



baudctl.4 = 0; // synchronous bit polarity

baudctl.3 = 1; // enable 16 bit brg

baudctl.1 = 0; // wake up enable off

baudctl.0 = 0; // disable auto baud detect



txsta.6 = 0; // 8 bit transmission

txsta.5 = 1; // transmit enable

txsta.4 = 0; // async mode

txsta.2 = 0; // high baudrate BRGH



rcsta.7 = 1; // serial port enable

rcsta.6 = 0; // 8 bit operation

rcsta.4 = 0; // enable receiver



spbrgh = 0; // brg high byte

spbrg = 15; // brg low byte (31250)

}



////////////////////////////////////////////////////////////

// SEND A MIDI BYTE

void send(unsigned char c)

{

txreg = c;

while(!txsta.1);

}



////////////////////////////////////////////////////////////

// CONTINUOUS CONTROLLER MESSAGE

void sendController(byte channel, byte controller, byte value)

{

send(0xb0 | channel);

send(controller&0x7f);

send(value&0x7f);

}



////////////////////////////////////////////////////////////

// NOTE MESSAGE

void startNote(byte channel, byte note, byte value)

{

send(0x90 | channel);

send(note&0x7f);

send(value&0x7f);

}



void main()

{

// osc control / 8MHz / internal

osccon = 0b01110001;



// timer0... configure source and prescaler

option_reg = 0b10000011;

cmcon0 = 7;



porta=0;

wpua=0;

portc=0;



// configure io

trisa = 0b00100100;

trisc = 0b00001111;

ansel = 0b00000000;



// initialise MIDI comms

init_usart();



// Set up the MIDI notes for each sensor

byte note[5] = {60,62,64,65,66};

// byte note[5] = {36,37,38,39,40}; // For Reason REDRUM

byte sense[5] = {0};

for(;;)

{

if(P_SENSE1 != sense[0])

{

startNote(0, note[0], P_SENSE1? 0:127);

sense[0] = P_SENSE1;

}

if(P_SENSE2 != sense[1])

{

startNote(0, note[1], P_SENSE2? 0:127);

sense[1] = P_SENSE2;

}

if(P_SENSE3 != sense[2])

{

startNote(0, note[2], P_SENSE3? 0:127);

sense[2] = P_SENSE3;

}

if(P_SENSE4 != sense[3])

{

startNote(0, note[3], P_SENSE4? 0:127);

sense[3] = P_SENSE4;

}

if(P_SENSE5 != sense[4])

{

startNote(0, note[4], P_SENSE5? 0:127);

sense[4] = P_SENSE5;

}

}

}

8 comments:

  1. Beautiful machine! Thanks for posting it!

    ReplyDelete
  2. Can you tell us about the synth you used? Great sound...

    ReplyDelete
  3. There are 2 synths being used.. first was Propellerheads Reason running on a PC (used for drum part in first half of video). Synth used in the second part (electronic noises) is a Dave Smith Mopho analog mono synth module which I think I also put through a delay effect from Line 6 Gearbox / TonePort UX2

    ReplyDelete
  4. Hey, really like your stuff. Have you worked with Arduino and a synth to generate midi signals? Would like to recreate your hand crank synth with LEGO and photo resistors rather than magnets. Not sure if it would work.

    ReplyDelete
  5. Hi yes - heres some Arduino code showing how to send MIDI notes
    https://sites.google.com/site/skriyl/Home/midi-stylophone
    good luck with the project - photo cells should work fine I think

    ReplyDelete
  6. Can't seem to find those hall effect sensors. Wondering if something like these: http://www.taydaelectronics.com/a1302-continuous-time-ratiometric-linear-hall-effect-sensor-ic.html would work?

    ReplyDelete
    Replies
    1. Look on eBay for A3144 hall effect switch. The item you found is "ratiometric" (analog output) but you need a simple switch (on/off) for this project. A3144 is what I used and cheap, plenty on eBay.. good luck

      Delete