Midi controller project for 08m2

I'm thinking of making a simple midi controller to send CC (control data) from 2 or 3 potentiometers, on the picaxe projects page I found this http://www.picaxe.com/Project-Gallery/Commande-MIDI/ and rather than try to re-invent the wheel thought that it might provide a good starting point, but the problem is the link on the page does not appear to lead to the actual code (just a lot of albeit useful information about all manner of things)

So does anyone have anything similar or know the download link for that project? I'm not interested at this stage in doing anything too complex, probably just a single channel and 2 or 3 preset CC assignements defined in the code.

I used the search function but did not find anything for the 08m2 which covers the bases of what I am after. (keyword Midi)
 

hippy

Ex-Staff (retired)
Should be a doddle.

Code:
HSerSetup B31250_8, %000
Do
  ReadAdc10 C.1, w1

  ' Convert %000000aaaaaaabbb to
  ' b1      %0aaaaaaa
  ' b0      %0bbb0000

  b1 = w1 / 8
  b0 = w1 * 8192 / 512

  HserOut 0,( $B0, $07, b1 ) ' Controller Change : Volume MSB
  HserOut 0,(      $27, b0 ) ' Controller Change : Volume LSB

  Pause 100
Loop
That might need tweaking depending on what equipment you are using, which controllers you are controlling, 7-bit or 14-bit data.
 
Thanks Hippy, I only need 0-127 range on the CC's (7 bit) as I am not using anything fancy like NRPN's or pitchbend, I'm going to convert an old expression footpedal initially, with just a 1/4" socket into the picaxe pin*, set at CC1 (modulation wheel) then perhaps eventually expand on the idea to add CC7 (volume) and CC11 (expression) using potentiometers, ideally I want it to be quite responsive (at least as far as is realistic) so thinking of running the 08m2 at 32mhz and using the disconnect command (if possible) and maybe some other tweaks so that it can be as expressive as possible.

Wondering if I use adc at 8 bit if there are any implications as I only need 0-127 (256 divide by 2 right?)

*The pedal I'm using has an output voltage range of 0-5v but I'm not sure if it is regulated, do you think it would be sufficient to use a couple of 5.1v zener diodes like this image http://i.stack.imgur.com/oKptw.png to protect the input pin of the picaxe?
 
Hmm, uploaded the code you posted and does not seem to be working - I am just using a midi interface connected to my ipad which is running midi monitor software, the midi interface is flashing at around 100ms intervals but the midi monitor is crashing out to quit as soon as the picaxe is connected.

I have the picaxe pin c.0 going via a 220r resistor to pin 5 of the din connector, ground to pin 2, and v+ via another 220r to pin 4, then for the pot I have pin 1 to ground, pin 2 to the picaxe pin C.1 and pin 3 of the pot to +v

To power the picaxe I am using 3xAA giving a voltage of 4.68v according to my multimeter, midi specifies 5v but I'd have thought 4.68v was close enough.
 

hippy

Ex-Staff (retired)
The output DIN seems wired correctly. The MIDI interface is opto-coupled so you are driving a LED, and 4.5V should be okay. If the interface is flashing I'd guess it was getting through.

You can try with something simpler to prove the monitor is working first ...

Code:
HSerSetup B31250_4, %000
Do
  HSerOut 0, ( $90, $3C, $7F ) : Pause 100 ; Note On - Middle C
  HSerOut 0, ( $80, $3C, $00 ) : Pause 400 ; Note Off
Loop
Edit : _4 for default 08M2, not _8 ! Could be the issue with earlier code also.
 
Thanks, I'll give that a try - in the meantime I decided to test the analog calibration and found that the pot I was using only covered half the range, so I swapped it out and now the readings are as expected, I also noticed that I had pin 4 and 5 mixed up and now the LED on the midi interface is not flashing, I think what had happened is the first time I had it correct, then when it wasn't working I dismantled the circuit and started again accidentally swapping the wires around.
 
Success! The note one worked, so I went back and changed the _8 to _4 on the other one and now it is working also, at least on the ipad midi monitor, I connected to a synth but no activity, I'm guessing that there is not enough current to light up the synth optoisolator possibly? I also tried it without the 220r resistor but still no activity yet, I'll try it with some other gear. Thanks Hippy
 

hippy

Ex-Staff (retired)
If it is okay to control the iPad it should control the synth. It might be that it's the synth is not set up to match, is expecting some other channel, hasn't got an instrument selected. Turn off then on, just in case it's now got volume set to zero :)

This should hopefully play a drum, work on anything which supports percussion, and might get through even if other channels don't ...

Code:
HSerSetup B31250_4, %000
Do
  HSerOut 0, ( $9F, 49, $7F ) : Pause 100 ; Note On - Snare
  HSerOut 0, ( $8F, 49, $00 ) : Pause 400 ; Note Off
Loop
Try a PAUSE 10000 ( 10 seconds ) at start. Turn all off, turn synth on, then PICAXE on. Sometimes things can get out of kilter. You can try adding an All Notes Off ( $B0 $7B $00 ) and/or Omni Mode On ( $B0 $7D $00 ).

Also try Program Change ( $C0 $xx ) which should change the instrument voice while playing manually.
 
Last edited:
Tried all that still not working, I also tried another synth but it does not work on that one either, on the ipad monitor it works fine though.

How can I change the midi channel in the code?
 

hippy

Ex-Staff (retired)
The MIDI channel is the least significant nibble in the first byte (command), so this should try Middle C on each channel ...

Code:
HSerSetup B31250_4, %000
Do
  For b0 = $0 To $F
    b1 = $90 | b0 : HSerOut 0, ( b1, $3C, $7F ) : Pause 100 ; Note On - Middle C
    b1 = $80 | b0 : HSerOut 0, ( b1, $3C, $00 ) : Pause 400 ; Note Off
  Next
Loop
 
Totally stumped on this one, I have tried a few different midi devices now including a hardware midi monitor which displays any midi data on any channel, and I have also removed the picaxe from the PCB and built it directly onto breadboard, I have also tried a few midi cables just to be sure, but no joy. It still works on the ipad midi monitor just fine, the ipad has a cheapo USB midi interface like the kind you can buy on ebay for around £5.

Any ideas?
 

hippy

Ex-Staff (retired)
It might be worth finding a 5V supply just in case that is the issue. Also double-check resistor values in case something is 220K rather than 220R etc. I wasted hours trying to get a LED to light via a 330K once, so it can happen :)

If the MIDI interface for the monitor has a 'thru' connector, you could try PICAXE to 'in' on that and 'thru' to synth. That might sort out any electrical difference.

Otherwise I would suggest setting up a keyboard to synth MIDI link, get that working when plonking a note. Connect the keyboard to the monitor, note what it sends, then program and check the PICAXE sends the same. With the keyboard again controlling the synth, unplugging that and plugging in the PICAXE should have it working.

If keyboard and PICAXE work with the monitor, that suggests the interfaces are compatible, wired correctly and the monitor is working as expected. If the keyboard controls the synth but the PICAXE doesn't, that suggests some subtle issue in the PICAXE output hardware.

Ideally build an optocoupler as per MIDI spec - or even just a 220R + visible LED - then check what the voltages and waveforms are with a scope.

This is exactly the same interface circuit as is shown in my official printed MIDI spec -

http://www.midi.org/techspecs/electrispec.php
 
Tried with 5v regulated supply, no difference, double checked resistors they are 220r, no midi thru to try that, verified note in monitor and should be working fine, double checked midi channels, the hardware midi monitor does not care about midi channel but see's no activity, I tried some other midi gear and none work, but ipad monitor still does, so I reckon it must be a hardware mismatch, looking at the schematic that you posted it appears the midi out has 2 logic gates (inverters?) in series after the UART - assuming they are inverters then I do not see why they are there as presumably the first will invert the signal, then the second will invert it back again? Or maybe I am misunderstanding? I have looked at a few other picaxe midi schematics and they just have the same set up as I am using, really weird!

I have the rev ed USB PCB scope, but not entirely sure how to proceed with regard to connecting and setting up, I have used it before for monitoring the picaxe outputs on another project, but I just used the 4 digital inputs on the scope - is that the way to proceed here or should I connect to 1 of the "proper" scope channels?
 
One other thing - I recently updated to the latest version of the editor v6.0.8.1, I don't suppose it is relevant but thought I'd mention it just in case it might be a bug.
 

hippy

Ex-Staff (retired)
I believe 6.0.8.2 was only to fix some Blockly bugs and I can't really see how PE6 would affect anything anyway, not if the monitor is showing the PICAXE MIDI as working.

My analysis of the double inverter in the MIDI circuit is it's just to cater for the second "A" inverter / drive being a transistor which inverts, so its input also needs inverting. A hardware UART or microcontroller output might need some buffering to be used as a drive. The PICAXE has enough current sink capability that it doesn't need additional buffering so can be wired direct to DIN pin 5 on the output. I have had a PICAXE direct drive a Yamaha keyboard and drum machine so I know it can work.

Using an 08M2 the default output of pin 0 is active as far as MIDI would be concerned so maybe this is causing the equipment to lock itself out ?

Perhaps add a long pause after the HSEROUT to give the receivers long enough to reset themselves.

You may also have to take care when downloading as the equipment will be receiving data which it may be misinterpreting. Perhaps try with an 18M2 or 20M2 where HSEROUT is on a separate pin to the download. Maybe add a 10K pull up on HSEROUT to keep it high until HEROUT has initialised and is driving the pin.

Perhaps post your code, circuit and photo just in case there is anything obvious.
 
Right, the plot thickens......

First here is the code I have been using:
#no_data
setfreq m32
HSerSetup B31250_32,%00
Do
HSerOut 0, ( 0xF8 ) ;clock
HSerOut 0, ( $80, 49, $00 ) : Pause 400 ; Note Off
HSerOut 0, ( $90, 49, $7F ) : Pause 100 ; Note On
HSerOut 0, ( $80, 49, $00 ) : Pause 400 ; Note Off
HSerOut 0, ( $B0, 1, $7F ) : Pause 100 ; CC1 127
HSerOut 0, ( $B0, 1, $00 ) : Pause 400 ; CC1 10
Loop
Now here is where it gets puzzling, on the 08m2 it works quite happily with the ipad midi monitor using the aforementioned el-cheapo USB midi adapter, over the weekend I have tried it with a whole bunch of other midi gear and it has not worked with anything, so then I thought I'd try using the el-cheapo with my laptop running midi-ox, and again it works as expected. So definitely the 08m2 is sending the midi data, but anything other than el-cheapo won't acknowledge any midi data at all.

Using the exact same setup I decide to try it with the 14m2, and not only does it work with el-cheapo but it also works with the other gear that the 08m2 had not. Any ideas why?
 

hippy

Ex-Staff (retired)
I can only think of two things. Either the baud rate is slightly out on the 08M2, close enough for the interface but not the synths, or there's something about the HSEROUT also being on the Download Serial Out pin which is upsetting the synths but not the interface. You could try that PAUSE suggested after the HSERSETUP.

The MIDI spec does call for 31250 baud +/-1% but I have never known any equipment which actually requires such a tight tolerance. Most use micros or UARTs which have an implicit +/-10% receive tolerance.

The only other possibility is perhaps some difference in timing of HSEROUT but I wouldn't have expected that to affect things to the extent that nothing works.

Without analysing the output of both, timing and voltages, it's going to be hard to say what it is.
 

hippy

Ex-Staff (retired)
One trick you could try on the 08M2 - Rather than take the DIN pin to +V, take it to a PICAXE output pin. Set that pin LOW at the start, set it HIGH after the HSERSETUP. That way no current can flow until the interface is initialised, for example on pin C.1 ...

Code:
#no_data
LOW C.1
setfreq m32
HSerSetup B31250_32,%00
HIGH C.1
Do
...
Loop
 
Yes it is very puzzling - especially since it does seem that some picaxe users have used the 08m2 for midi output, I wonder if they are doing something with the timing of HSEROUT perhaps? I tested with a number of hardware devices from different manufacturers but the 08m2 would only work with the USB adapter, yet the 14m2 so far has worked with everything.

I'll try to capture some screen shots using the PCB scope of the 08m2 and 14m2 and post them later (once I figure out how to hook it up!)
 
One trick you could try on the 08M2 - Rather than take the DIN pin to +V, take it to a PICAXE output pin. Set that pin LOW at the start, set it HIGH after the HSERSETUP. That way no current can flow until the interface is initialised, for example on pin C.1 ...

Code:
#no_data
LOW C.1
setfreq m32
HSerSetup B31250_32,%00
HIGH C.1
Do
...
Loop
Ok I'll give this a try.
 

hippy

Ex-Staff (retired)
The direct to 'ceramic blob' trick does work from DIN pin 4 with pin 2 as common 0V. It's not as robust / safe as an opto, won't work if the MIDI cable doesn't have 0V on pin 2 but does work.

As to the "correct schematic" circuit; there's something not right with that. I suspect they haven't shown the DIN pins crossed over.

It could be that an 08M2 is putting out slightly different voltages than the 14M2 which is affecting the opto on the synths but I wouldn't have expected that. The signal is active low and I would have thought both would have pulled the line equally close to 0V.
 
Well, you won't believe it - I tried your code in post#19 on the 08m2 and lo and behold using the pin rather than +V worked, so just for curiosity sake I swapped the wire back to +V and it still worked! Dumbfounded I edited the code and commented out the lo/hi pin initialise part, and just connected as before, re-uploaded and it still worked. What the hell?

Now to re-cap, it was only working with the USB, exact same setup (meaning taking the midi lead out of the USB and putting it into any other midi device) and nothing. Yet now it works with anything, including the USB.

Anyway, thanks for all your help trying to get to the bottom of this, I am utterly puzzled as to why it has started working now, it has been a long few days...

Now hopefully I can get started on the project proper:cool:
 
Top