Homebrew midi-cv box

midiDAC and double bass pitch and amplitude tracker.

Homebrew midiDAC with integrated double bass pitch and amplitude tracker.

After having built a x0xb0x this summer which I fitted with Brian Castro’s x0xio back panel mod I decided a good project to make would be to make a midi-cv converter box. Although the x0x comes with it’s own midi in, the firmware is a bit tempremental and I was getting a lot of skipped notes and no control over slides when programming midi sequences for the x0x in Ableton. After having played for more time than I care to admit to with the x0x I’ve come to the conclusion that although the internal sequencer rocks, especially when using the SokkOS firmware (funky pattern randomise not to mention the other extra features) the midi response is a bit naff.

This formed half the motivation for building a midi-cv box, the other came from my practice as a double bass player. The double bass being fretless lends itself to slides just like the 303, with my new pitch CV in could I take the pitch and amplitude of double bass and use it as a control signal for my x0x ? More on this side of the project later. The brief I set myself for the midi-cv side was simply that it should supply at least 5 cv outs with a resolution high enough to allow for some interesting tuning options later on. I also wanted proper midi in although I knew while I was programming the firmware I’d probably just send the midi byte code over USB .

midiDAC with integrated double bass pitch and amplitude tracker.

midiDAC close up, the lid contains the inputs and outputs for the pitch tracker

Having looked around the Arduino forums I found a lot of people using the PWM outputs on the Arduino and just running them through a low pass RC filter to get a smooth variable DC voltage out. This has the benefit of being quick to make but the downside of non-linearity across the domain of the duty cycly and the range of voltage out and the small portamento this approach will neccessarily come with. Having decided against using the PWM out and having recently been introduced to the analog devices catalogue by an a electronics friend I decided to get hold of one of their AD5668 DAC chips and dive into the world of surface mount chips and SPI. I’m not claiming to be the first to hook up a DAC chip to the Arduino as there’s a fair amount of evidence people have taken the same approach when building their own cv boxes but the approach worked and I’m pretty pleased with the results.

The AD5668 and an adaptor to make soldering wires on to a 5mm chip slightly easier, came to about twenty quid from Farnell. The rest of the box materialised over a period of about two weeks as I made nightly visits to my long suffering local Maplin (I swear they hate me in there, there’s only so many times you can roll in at ten to eight and ask for an opto-isolator and a bag load of assorted components).

Under the hood of the midiDAC

Under the hood of the midiDAC

Although optoisolators aren’t technically neccessary for midi input I’m a bit of a stickler for standards and seeming as I’d never used one before I figured I might as well. This Arduino forum post came in handy for the midi in part of the circuitry and the midi byte parsing, I particularly enjoyed the mspaint circuit diagram. As you can see the box is packed pretty tight and the eight outputs which are on switched mini-jacks and quarter inch jacks barely fitted in the enclosure. The pitch and amplitude tracker I built for my double bass is on a circuit board blu-tacked to the inside of the lid so you can’t see it in this photo but I’ll cover that in another post.

The most time consuming part was reading the AD5668 datasheet forwards, backwards and in random access until I’d squeezed all the functionality I wanted out of it. It uses a 32 bit address space with 4 bit padding at either end, 8 bits for commands and 16 for resolution on the output which swings between 0 and 5v. There’s a fair bit of left and right shifting in the arduino source code as well as some bit masking which is kind of funky if you’re into powers of two.

There already exists a fair wealth of material (e.g. here, here and here) on how to get the Arduino to deal with midi byte code so after having successfuly hooked up the Arduino to the DAC chip (SPI really isn’t that hard given the Arduino’s built in shiftOut method, reading this helped) I just started hacking apart kuk’s midi parsing code for my own purposes. I’ve put the source code here so you can get a head start on making your own if you’re interested in using the AD5668 or just seeing a project that makes broader use of the midi specification. There’s a fair amount of code dedicated to getting pitch and amplitude data from the double bass which you’ll have to scroll past.

Having documented the insides of my midiDAC I’ll leave you with two videos showing its implementation with my x0xb0x. I cooked up a little random scale generator in Max to play on 16th notes and synched the whole thing up to my drum machine via Ableton and Rewire (Max 5’s new transport still doesn’t accept MTC as a clock source, hence Ableton and Rewire joining the party). Enjoy.

43 Responses to “Homebrew midi-cv box”

  1. crx

    Check the trackbacks, some website on business c.v.s (cicurriculum vitae) just linked me, plus one for webbots but minus 2000 points for the semantic web.

  2. crx

    yo Niall, yeah I’ve given up on the office, I have a room full of equipment here at home and only come into meet peeps occasionally and steal things (like oscilloscopes). Nice blog you got going there.

  3. crx

    I’ll be posting more info and perhaps a circuit diagram when I finish the pitch tracking side of the box. It’s currently 80% there I’m just porting a lot of js from Max into C, adding the functionality to the micro controller / hardware rather than doing the pitch data signal processing on the computer and sending it back.

    Thanks for your interest.

  4. howdragonsdisappear

    Congratulations for this nice project adn this nice blog.
    I have a lot of interest on this, i wanna make one interface to expand the control of my modular synth with the arduino board.
    It would be really great if you can post more info i following this very nearly.
    I have a question, i ‘m telling if it really necessary to use AD ? why you haven’t use the 6pwm out of the arduino board ? (sorry if it’s a silly question, i just begin to discover the capacities of the arduino board !!)
    have a nice day

  5. crx

    Hi, some people have been having success driving their modulars from the filtered output of the PWM outs of the Arduino check http://cliplead.blogspot.com/2009/01/blog-post_18.html for example. My problems with this approach are the lack of linearity, lower ten bit resolution and slight portamento an RC filter will add. The DA chip is cheap for what it does but you could use another one at 12 bit if you wanted it even cheaper, I’m guessing the address space would be similar. As for more info I’ll try and find time to write another howto but it’s really simple. You just wire a couple (check the source code) of the outputs of the Arduino to the DA and the outputs of the DA to jacks. I bypassed the power supply to the DA with some caps (like the datasheet advised) but that was the only fancy thing I did. It’s really pretty simple, the only pain was writing the Arduino code but now that’s done and posted you won’t have to! Let me know how you get on if you give it a go.

  6. howdragonsdisappear

    I have ordered the arduino board, i think i’ll made some try with the pwm output and if i’m not really happy with i’ll go for DA.
    Effectivily it doesn’t seems to be so hard with all the thing already made with arduino.
    i’ll give some news about that (and maybe ask you some more questions)

  7. ag

    first of all great project!!!
    i’ve been trying to replicate your howto but been hitting some walls and i was hoping you could help me a bit,
    i have everything on a breadboard, all connections appear to be as described in source code, caps on vdd, but no voltage change on any output.
    i changed the loop code so that instead of midi input it would just make a linear output ramp:
    ad5668 outC is connected to analog0
    void loop() {
    for(unsigned int i=0;i<65535;i+=100){
    unsigned int voltage = i;
    write_dac(WRITE_UPDATE_N, 3, voltage);
    Serial.print(” | analog:”);

    any other writedac function i have to call before writing to the outputs?
    i also tried to tied ldac, sync and clr to ground but no luck either
    this must be a simple thing but i’m just scratching my head here for being so close…
    hope you can help!
    all the very best

  8. ag

    great work!
    i wonder if you could help me in my final steps to replicate it!
    i’m almost there, i have everything wired up with info from dac datasheet and the pins mentioned in your code, but i get no output from the DAC!
    this is my loop function, all the rest of the code i left it pretty much the same:

    void loop() {
    for(long i=65535;i>0;i-=10){
    int inVar=analogRead(ENVELOPE);
    unsigned int voltage = 65535*velocity/127.0;
    write_dac(WRITE_UPDATE_N, 3, voltage);
    Serial.print(” | ANALOG IN:”);

    am i missing anything here? any function i need to call before write_update_n?
    any other clue?
    thanks in advance

  9. ag

    i was just being very stupid!
    it’s perfectly working now!!
    thanks a lot!!

  10. crx

    Hi ag, sorry I didn’t get back to you I’ve had blog fatigue! Just checked out your site, some nice stuff you got going on there, a lot of nice stuff. Glad the AD5668 worked out for you.

  11. ag

    hello again,
    i’ve been wrapping your code and creating a proper library for it, send me an email i’ll share it with you if you’re interested!

  12. dl6kbg

    Hi i just finished my AD5668 based Interface one hour ago. At the end it was a wrong Midi to Serial driver. The Interface i think worked for a week but with no voltage output. A short video is here later i will post a detailed guide what helped me. have fun: http://www.youtube.com/user/OliverGoldenstein#p/a/u/0/CqTFRQ2S8oo

    by the way: the ad5668 you can order as a free sample. i got two of them from Analog in one week.

  13. crx

    Great work! I didn’t know I could get the free samples, mine was a birthday present from my girlfriend. Geeks eh?

  14. dl6kbg


    Robin there is one error left at my patch i think. in max for live i choose midiin –> serial b 38400 but this works only, when the patcher window is open. this patch runs on my mac, where i do have no serial to midi driver. so the midi to serial runs in max. maybe you can post your patch or a screenshot about your midi to serial conversion. thanks a lot

  15. charlie hobbs

    I too am having trouble with this and hopethat someone is kind enough to share a schematic or at least a verbal description of what connects to what. Ive been trying a with few different lower res (and lower priced) DACs. Are all of the necessary connections described in the code? i think that I may be missing something with just the sketch and data sheets to go by. Also, does the DAC out go directly to a audio jack, or through some kind of filter or buffer first?

  16. charlie hobbs

    OK, here is what I have:

    ARDUINO AD5668
    MIDI>> pin 0 RX
    (via pin 3 >>> pin 15 DIN
    opto) pin 4 >>> pin 16 SCLK
    pin 5 >>> pin 2 SYNC
    pin 6 >>> pin 1 LDAC
    pin 7 >>> pin 9 CLR
    pin 8>>pwrLED pin 3 VDD >>> +5v
    pin 9>>RXLED pin 5 GND >>> Ground
    pins 4,5,6,7,10,11,12,13 >>> out
    pin8 VREF (not needed?)

    This is what is still not clear:
    Envelope-0 Analog in on Arduino to test DAC >>>>conected to what?
    ZEROIN 2 Zero crossing interupt (is this a pin declaration?)
    GATE 0
    CV 1
    ACC 2
    SLD 3
    FILT 4

    Does anyone with a little more expertise care to help fill in the pieces?

  17. charlie hobbs

    OK, here is what I have:

    MIDI>>..pin 0 RX……………………………….
    (via….pin 3…….>>>…pin 15 DIN……………..
    ..opto).pin 4…….>>>…pin 16 SCLK…………….
    ……..pin 5…….>>>…pin 2 SYNC……………..
    ……..pin 6…….>>>…pin 1 LDAC……………..
    ……..pin 7…….>>>…pin 9 CLR………………
    ……..pin 8>>pwrLED…..pin 3 VDD…>>> +5v……..
    ……..pin 9>>RXLED……pin 5 GND…>>> Ground…..
    …………………….pins 4-7,& 10-13 >>> out….
    …………………….pin8 VREF (not needed?)….

    This is what is still not clear:
    Envelope-0 Analog in on Arduino to test DAC >>>>conected to what?
    ZEROIN 2 Zero crossing interupt (is this a pin declaration?)
    GATE 0
    CV 1
    ACC 2
    SLD 3
    FILT 4

    Does anyone with a little more expertise care to help fill in the pieces?

  18. crx


    Awesome work. Well done in getting it working, I can’t remember what I connected my Vref in too. As for max4live bugs I haven’t started dev work updating my patches for m4l yet as it hasn’t fitted around PhD/hardware dev work recently. Expect examples and help over the coming month(s).

    @charlie hobbs

    Check the OP or docs for info, I dunno if I’m going to schematic this up on the web. Right now it just works for me and I haven’t got time to take the unit apart and check my veroboard. This may change in the future pending funding opportunities…


    Cheers for the interest. See above.

  19. charbot

    Hi everyone, Cool project, but Im stuck. I have everything wired as described in the code and data sheet, but Im getting no output from the dac. I changed the baud rate to 31250, and have the caps on the power like the data sheet recommends. I left the v ref pin #8 unconnected. Anything else (simple,stupid or otherwise) that I might be missing? Also, would someone post a brief description of functions for the dac output pins? For example, does VoutA (pin #4)supply CV and VoutB(pin#13) is GATE…etc? thanks in advance.

  20. charbot

    So, I think my problem is with “Zeroin pin#2” (zero crossing interupt).
    Im not sure what to connect it to. Does this go to the DAC?
    The rest of the connections are obvious but I am also uncertain what to do with:”ENVELOPE 0 //Analog in on Arduino to test DAC”… Should I just connect any DAC out pin to analog in #0? Sorry for being dense and asking so many question. Any help would be greatly appreciated

  21. charbot

    OK. I got it… it seems a little quirky though. I needed to connect vref to +5v to get it going but after a few minutes I can disconnect the vref and it still works but only if the mod wheel is in the middle to high position..(shrug?) I have found that the decoupling caps on V+ arent necessary, and I guess are used for more accuracy. Stranger still, the circuit still seems to be fully operational even when I disconnect +5v from the DAC entirely. I guess Its getting power through SPI.
    If anyone else is wondering, envelope and zeroin functions are for the bass pitch and amplitude tracker and arent used for the Midi2CV.

    Robin, are all of the DAC outs used? Currently I am only getting output on VoutA=Gate and VoutB=CV. Im using a microkorg and a Sequential Prophet 600, not a TB303 so I guess Ill need to alter the Midi controller commands, right?

  22. dl6kbg

    Hi Robin !

    I managed to add the midi-clock and start stop code so that i can sync/reset my analog clock sequencer and divider. i am not a programmer, so it was more a trial and error process for me. but it works. before i post something about it i would post it to you, so that you may have an eye on it.

    Please contact my via e-mail.

    Good luck with your PhD Exams.

    Oliver, Dresden, Germany

  23. Jon M

    Hi guys,

    Just bumped in to this thread in the search of MIDI to 16bit for a synth project.

    Just realised before I posted that this post is a couple years old now, but not sure if anyone else has covered this..

    The 5668 seems quite expensive!
    I have been using the 5206 which only has 6 outs but seems a lot cheaper.
    I’ve only skipped through the datasheets to check them against each other, but both are 16bit..

    The 5668 seems to currently cost around £18-25 in the UK.
    Whereas you can pick up a 5206 for as little as £3..

    Surely for the sake of price and changing the code a little would it be worth either adding a few extra channels/knocking a few outs on the second?
    In theory you could run an additional 42 or so outputs for the same price of one 5668 as long as you channeled the addresses in such a way..

    Or am I missing something here altogether..?

  24. John Rising

    Hey, friend! Working now with my first diy modular synth and want to use your great project for connecting it with other midi stuff. I’m not a programmer, did not work with Arduino and DACs before… Only analog simple cirquits. So, what you say about circuit diagram, cannot find any at your page. If you upload it, many people will be very happy and greateful))

  25. oberling

    If someone (like me) happens to have the TI DAC8568 instead – wich seems to be nearly identical to the AD5668 – just replace every B1111 with B0000 in the code. This seems to be the major difference in programming it: the first Bit of the Prefix Bits has to be 0 for this (TI DAC8568) chip.

    Thanks for sharing the code 🙂

    kind regards

  26. Sylvain


    Hi…. I know it’s quit old post but I wanted to start a arduino to CV gate project and found your box… Problem is I’m good stuff making but quit poor conceptor….
    I didn’t found the schematic of your interface in all the links… Do you think u still have it somewhere?
    Thx a lot

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>