Pd and Arduino (or whatever you call it.)

I never blog! But I've been integrating AVR's with Pd for a few years now, and It's time to share my technique, such as it is.

I use the AVR as a sensor interface, and as a controller for music. It's mostly reading values from the "digital" pins, which are generally hooked up to a button or switch, and reading voltages from "analog" pins, which are hooked up to a knob or slider or other form of voltage divider. There's a sketch in the .zip below called SimpleSend.pde, which does this, and another called Send_median3.pde that does the same but with a fancy median filter for eliminating outliers.

The next step is to send this info to the serial port and read it in Pd. There is an external, [comport] (included with extended), which is made for reading serial in Pd, but the trick is to convert the bytes coming in to numbers and symbols that are useful in Pd. I've used tof's [ascii2pd] abstraction in my patches, and it works great and is very flexible and useful and all that, but on one of my machines it wouldn't work because it depends on [coll] (from cyclone) which wouldn't create on that machine. I built an abstraction that is not very flexible, but has no dependencies. It's included in the .zip below, and is called SimpleReceive.pd. Another patch using [ascii2pd] is in there too, it's called SimplerReceive.pd.

If you want to build a controller, this should get you on your way. Of course, there is also the topic of sending from Pd to the AVR, and some other tools like firmata, and some interesting hardware hacks that we are thinking of for a future dorkbot workshop!

http://dorkbotpdx.org/files/SimpleSend.zip


AttachmentSize
SimpleSend.zip134.17 KB

Comments

MIDI?

While using strait up serial might be more flexible, sometimes [especially just for sending digital (on/off) messages], MIDI provides all you need, without the hassle of setting up your own protocol. The nice thing about MIDI is that you can hook your stuff into other MIDI supporting applications without translation. Though, MIDI does incur more overhead and a fixed baud rate as compared to serial.

It does require special hardware if you want to do the normal MIDI, but you could also do MIDI over USB if you're using the Benito or Teensy or just one of the AVR chips with USB [with the LUFA library].

Maybe someone could make an application for the Benito/Teensy that would let you translate the Dorkboard/Arduino's serial into MIDI over USB? [maybe someone has already done this?]. If only the Arudino used those new USB-AVR chip, maybe they will soon?


or even OSC!

When I first started doing this, I would send messages with osc addresses (like /buttons/two/0) over serial, and found out that printing to serial is the slowest thing in the loop. So I switched to using a single letter plus a value, and that's pretty quick. I reckon midi messages are pretty small too.


I've been thinking about

I've been thinking about writing this exact little piece of software (converting *duino serial into MIDI with a Benito) for a little project I'm working on.. so if it doesn't exist now, it will soon!