4 key midi keyboard with Basic Stamp

diy 4 button midi controller test

Here is the four button test layout, showing how simple the circuit itself really is.

So, I had this old Basic Stamp sitting here feeling unloved. I decided it would be fun to try to build a midi controller. My initial idea was a of using the jog wheels off some old VCR players as mini turntable style jog wheels, but before I get to that, I wanted to start small. I wanting to test the theory first, so I wired up the midi output to a DIN connector, and used sample code available HERE (also shows the wiring for the midi connection) to make the basic stamp output a single note over and over again, with a pause between.

With that working ok, next step was to connect some buttons to the controller, and program the buttons to output separate notes. The wiring was pretty basic, just the usual button set-up, with a pull up resistor on the input pins. The magic was mostly done in the code, which wasn’t too difficult. The code basically transmits a midi on command on each press, and a midi off command on the release of each button.

At this point, I have a 4 button midi controller. maybe useful for triggering samples or something. My next progress will be to try to get a rotary encoder to work with the setup.

I haven’t worked out a good way to host files other than photos yet, so I’ve included the code in the body of the blog below. Hopefully you’ll be able to copy and paste it if you’re interested.

' {$STAMP BS2}
' {$PBASIC 2.5}
'Mini Midi interface,
'Author Matt Ruth
'Date: 11/7/2010
'www.diydata.wordpress.com
'don't expect too many basic stamp projects from me, the plan is to put this controller to work, then leave it there.
'I only have one basic stamp, and anything I buy in future will likely be arduinos!
'future revisions:
'read the state of each button, and transmitt all states in one serial transmission, instead of individually.
' EG: $90, note1, velocity1, note2, velocity2, note3, velocity3 (http://peabody.sapp.org/class/dmp2/read/nv94_gettin_midi_with_it.pdf)
'also make the midi notes variables which are declared at the top of the program
'add data transmit led
'add jog wheels of course
'make unit as a midi foot switch trigger, getting to use more rugged switches

'following variables are used for midi output. Taken from website tutorial on midi output
outpin CON 15 ' output pin on which to send MIDI data
baudmode CON 12 ' baude mode for serout: (2500000/31250)-20 msec
 ' note that this value should be 12 for BS2. (60 otherwise)
 ' Serial rate for MIDI is 31,250 data bits/sec.
outpause CON 0 ' pause time in units of 0.4 millisec between bytes
 ' on the BS2, units are 1.0 millisec
INPUT 11'button one
INPUT 12'button two
INPUT 13'button three
INPUT 14'button four
butt_11_state VAR Bit
butt_12_state VAR Bit
butt_13_state VAR Bit
butt_14_state VAR Bit
butt_11_state = 0
butt_12_state = 0
butt_13_state = 0
butt_14_state = 0
main:

IF IN11 = 1 THEN GOSUB BUTTONone
IF IN11 = 0 THEN GOSUB BUTTONoneUP
IF IN12 = 1 THEN GOSUB BUTTONtwo
IF IN12 = 0 THEN GOSUB BUTTONtwoUP
IF IN13 = 1 THEN GOSUB BUTTONthree
IF IN13 = 0 THEN GOSUB BUTTONthreeUP
IF IN14 = 1 THEN GOSUB BUTTONfour
IF IN14 = 0 THEN GOSUB BUTTONfourUP
PAUSE(50)
GOTO main
BUTTONone:
IF (butt_11_state = 0) THEN GOSUB Onepressed
IF (butt_11_state = 1) THEN GOSUB Onestillpressed
RETURN
Onepressed:
 'send midi on note here
 SEROUT outpin, baudmode, outpause, [$90, 60, 127]
 DEBUG "1"
 butt_11_state = 1
 RETURN
Onestillpressed:
 'DEBUG ".", CR
 RETURN
BUTTONoneUP:
 IF butt_11_state = 1 THEN DEBUG ",":SEROUT outpin, baudmode, outpause, [$90, 60, 0] 'replace debug with midi off note
 butt_11_state = 0 'off note may need to be $80
 RETURN

BUTTONtwo:
IF (butt_12_state = 0) THEN GOSUB Twopressed
IF (butt_12_state = 1) THEN GOSUB Twostillpressed
RETURN
Twopressed:
 'send midi on note here
 SEROUT outpin, baudmode, outpause, [$90, 61, 127]
 DEBUG "2"
 butt_12_state = 1
 RETURN
Twostillpressed:
 'DEBUG ".", CR
 RETURN
BUTTONTwoUP:
 IF butt_12_state = 1 THEN DEBUG ",":SEROUT outpin, baudmode, outpause, [$90, 61, 0] 'replace debug with midi off note
 butt_12_state = 0 'off note may need to be $80
 RETURN
BUTTONThree:
IF (butt_13_state = 0) THEN GOSUB Threepressed
IF (butt_13_state = 1) THEN GOSUB Threestillpressed
RETURN
Threepressed:
 'send midi on note here
 SEROUT outpin, baudmode, outpause, [$90, 62, 127]
 DEBUG "3"
 butt_13_state = 1
 RETURN
Threestillpressed:
 ' DEBUG ".", CR
 RETURN
BUTTONThreeUP:
 IF butt_13_state = 1 THEN DEBUG ",":SEROUT outpin, baudmode, outpause, [$90, 62, 0] 'replace debug with midi off note
 butt_13_state = 0 'off note may need to be $80
 RETURN
BUTTONFour:
IF (butt_14_state = 0) THEN GOSUB Fourpressed
IF (butt_14_state = 1) THEN GOSUB Fourstillpressed
RETURN
Fourpressed:
 'send midi on note here
 SEROUT outpin, baudmode, outpause, [$90, 63, 127]
 DEBUG "4"
 butt_14_state = 1
 RETURN
Fourstillpressed:
 'DEBUG ".", CR
 RETURN
BUTTONFourUP:
 IF butt_14_state = 1 THEN DEBUG ",":SEROUT outpin, baudmode, outpause, [$90, 63, 0] 'replace debug with midi off note
 butt_14_state = 0 'off note may need to be $80
 RETURN
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s