‹ under the hood changes 2Ström ›

Arduino Live Coding

2013-05-17 17:54:25 livecoding

So here's some more in depth info on my performance at the live.code.festival / algorave in Karlsruhe.

Being fascinated since long by the sound of serial transmission, I got into trying to make music out of it in some way. By trial-and-error, I figured out that if I connect a small speaker to the TX line of an Arduino, I could upload programs that send serial data and listen to the sound of it.

It is all very basic: if I make the Arduino program send data with delays in between, it plays click rhythms. And programs with faster streams of data play tones. More elaborate combinations of delays and patterns of data produce chords, melodies and a variety of noises. So it works like some sort of one-bit music system that is nice and challenging to play with.

The programs I [live]code can look like this...

byte cnt= 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.write(cnt);
  delay(5);
  cnt++;
}

and the resulting sound is this... (raw and unfiltered)

and a more elaborate program...

byte cnt= 0;
void setup() {
  Serial.begin(9600);
}
void loop() {
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(random(4));
  }
  for(int i= 0; i<200; i++) {
    Serial.write(cnt++%5+10);
    delay(2);
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(random(4));
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(3);
  }
  for(int i= 0; i<100; i++) {
    Serial.write(cnt++%5+10);
    delay(4);
  }
  if(random(2)==0) {
    Serial.begin(random(10000));
  }
}

sounds like this...

And of course, the sound of the uploading (verification really) is great in itself. It typically sounds like this... (raw and unfiltered)

I think the uploading sound changes subtly depending on program length and I also guess it will change with different Arduino bootloaders and whatever baud rate they are using.

And you also have a bit of control over the timbre of the sounds. Certain 8bit numbers are more square-wave like than others e.g. 170 (0b10101010), and 85 (0b01010101) sound more 'clean' and 15 (0b00001111) and 240 (0b11110000) also have a more distinct pitch.

Different baud rates have a huge effect on the sound - mainly working as frequency transposition.

But the real fun starts when one connects five Arduinos to a mixer and start playing with volumes, panning and filters. By having five Arduinos connected to a USB hub while running five copies of the Arduino IDE software, I can write little programs on the fly that will address the different boards and play different sounds on the TX lines. (Listening to the RX line also works but then the upload process fails. It'll require extra circuitry to tap into this data without disrupting the uploading).

The reason I used five Arduinos is that that's all I could connect to my laptop (2x USB) with my 4-port USB hub. That in combination with the limitation of computer screen space. It is hard to have more than five Arduino IDE programs open and visible at the same time.

Anyway, as the voltage of the standard Arduino is 5V and really a bit too much for audio equipment, I bring this down a bit with a simple voltage divider. I'm using a 10K and a 1K resistor.

arduinoLivecoding schematic

Here are some pictures of the setup. I'm using the Arduino clone Red board from SparkFun.

arduinoLivecoding board photo

The complete setup (without mixer and laptop)...

arduinoLivecoding boards photo

One issue with the setup is that one can't trust the Arduino IDE to remember which serial port it was connected to. So every time I start the program I need to double-check that the five Arduino IDE programs are set to the right Arduino board. And as I like to know which board is connected to which mixer channel, I also need to check that and possibly reconnect the sound cables.

Live at the live.code.festival in Karlsruhe (Algorave night 20 Apr 2013). Five Arduino boards all with their serial port (TX line) connected to a mixer (with simple protective circuitry in between). So all sounds are generated from what the Arduino boards are programmed to transmit serially. Note that the sound is heavily distorted. Sorry.

‹ under the hood changes 2Ström ›