‹ audioSerial FSK ›


2014-10-19 23:31 electronics, supercollider

clean-up: #55

Another way (compared to FSK in my previous blog entry) of sending data via audio is to directly generate the serial bit stream using SuperCollider.

To test and learn about these things I first wrote and uploaded a very simple program to an Arduino board. The program just transmitted the bytes 128, 10, 20, 30, 40 and 50.

//Arduino testcode
void setup() {
void loop() {

Then I connected the Arduino serial TX pin (pin1) to the audio line-in of my laptop (via a 1K + 10K voltage divider) and recorded the sound of the serial transmission.

I then analysed the sound by hand and wrote a little program in SuperCollider that could generate similar waveforms.

o= {|chr| [1]++(1-chr.asBinaryDigits.reverse)++[0]};
SynthDef(\serialAudio, {|amp= -0.5|  //for sending out serial via audio
  var data= Control.names([\data]).kr(Array.fill(60, 0));  //max 6 bytes
  var src= Duty.ar(1/9600, 0, Dseq(data), 2);  //baudrate
  OffsetOut.ar(1, src*amp);
Synth(\serialAudio, [\data, [128, 10, 20, 30, 40, 50].collect{|c| o.value(c)}.flat, \amp, -0.5]);

This screenshot show the signal recorded from the Arduino in the first channel, and the SuperCollider generated one in the second.

After all this, I could reverse the process, generate any serial data and send it back to the Arduino RX pin (pin0). A small amplifier circuit in between helped to get a more stable communication going.

This serial-to-audio technique was used to control the 24 LEDs (6 PWM channels) in our Reflect installation i.e. SuperCollider is running on an iPod Touch and sends out serial audio to an ATmega168 microcontroller.

Here is another example that can fade a single led by sending serial commands over audio. Includes schematics for an amplifier circuit plus SuperCollider and Pure Data example code.

And for a more advanced (actually using a much better technique) example see /f0blog/arduino-programming-via-soundcard/.

‹ audioSerial FSK ›