Sunday, October 4, 2009

Homemade guitar looper with Arduino

Introduction

Here is how to produce pedalboard for electric guitar. The idea is to connect pedals to the Arduino, and to use them to control a software of sound processing in Pure Data. Here I show you the example of a looper, but one can be also made a rack of effects without problem.

A video of the looper in action is available here :


First of all, something you must understand: our pedals break up into two parts: the controls part and the sound part. The control part is composed of:
The sound part:
The pedalboard are thus used only to control a software of sound treatment.

Electronic part



Overall picture


As it there is seen, my pedalboard is composed of (from left to right):
The assembly is simple: first, get the jacks catch which correspond to the pedals. Then, connect them on a small circuit which one even manufactures oneself. The idea, it is that each switch will be crossed by a 5 volts supply, provided by Arduino. Then, depending on the pedal state, the power is on (or off). With the pedal of expression, it is only a potard, which will modulate the power supply sent by Arduino.

Each pedal must thus be connected to the alim 5V provided by Arduino on the one hand, and to the mass of the other. Just put a resistance between the pedal and the mass: it is about a resistance of pulling. And here, connect the pines digital (or analogical for the pedal of expression) of Arduino, knowing the tensoin there and thus knowing if the pedal were actuated.

Close-up on the circuit


A close-up to see the circuit, but which does not show large thing.

Electric diagram


Small diagram which shows that it is very simple.









Data-processing part



Code embedded on Arduino


Now that the assembly is made, we must write the short piece of code which one will embark on Arduino to manage all that.

Here also it is very simple: only the role of Arduino is to know the values of each switch (open/closed, 0/1) and of the potar (value between 0 and 1), and to send these data to the computer .

This code, one writes it with the kit of development provided with Arduino. For the communication between the chart and the ordi, one uses the lib Firmata, provided with the SDK.

Here is the code corresponding to the assembly.

/*
* Firmware for my guitar pedals.
* by elboulangero
* http://www.arduino.cc/playground/Projets/LooperPourGuitare
*/
#include "WProgram.h"
#include 

void setup();
void loop();

/* Choose the pin for the LED */
int ledPin = 13;
/* Previous digital values */
byte prev_digital_mask = B00000011;
/* Previous analog values */
int prev_analog_val[6] = { 0, 0, 0, 0, 0, 0 };



/* Global functions */
void setup() {
/* Declare LED as output */
pinMode(ledPin, OUTPUT);

/* Firmata init */
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
Firmata.begin();
}

void loop(){
int i;
byte mask = B00000011;

/* Digital pins ( only 4 pins are connected ) */
for ( i=2; i<6; prev_digital_mask =" mask;" i="0;" val =" analogRead("> 2 ) {
prev_analog_val[i] = val;
Firmata.sendAnalog(i, val);
}
}

/* Don't go too fast ( maybe this is useless ) */
delay(10);
}

Comments on this code


Thus of course, this code corresponds precisely to the assembly which I carried out. But it is very easy to adapt to any assembly of the same style.

The use of the variables '' prev_… '' makes it possible to send data only when one of the values changes. As long as one does not touch with any pedal, the chart doesn't send anything. That avoids flood on USB port, and to tire the chart unnecessarily.


Pure Data Part



Driver Pure Data


Well. All the part with Arduino is made. It is now necessary to make communicate our chart with Pure Data. For that, I used Pduino. It is a Pure Data object which is interfaced with Arduino. It requires to have used the lib Firmata on the embedded code.

Available at this address: http://at.or.at/hans/pd/objects.html
Once one manages to make communicate our Arduino with Pure Dated, one can start to program a small driver. It only handle simple tasks:
  • to establish the communication with Arduino.
  • to recalibrate what the expression pedal gives us to obtain a value between 0 and 1.
  • to make sure that the switches give well until one waits.
  • to send the values wanted thanks to send objects, so we can use them in others patches.
The Pure Data driver for the pedals is in the zip file (see following section), under the name arduino-driver-0-0-5.pd.

The looper


From there, one made all the part controls pedals. Remain the sound part. I will not extend too much on this part, which does not relate to really any more Arduino.

I only give the 2 Pure Data patches I made and use in the youtube movie :
The 3 Pure Data patches are there:
http://www.arduino.cc/playground/uploads/Projets/guitarlooper-pd-objects


Note: I am a very occasional user of Pure Data (the last time that I served myself it of it was y' is 2 years old well), then if y' has people who know well and throw an eye with my patches, it can make them odd. I just made a point of preventing. I used quite ugly tricks, but I did not know how to do them differently.

Conclusion


The interest of this is multiple:
  • the price: my pedals cost me about 100 euros by counting the carriage costs.
  • flexibility: so tomorrow I need to add an unspecified pedal, I just add it on my assembly and they is good. No need to buy a new whole pedalboard.
  • an infinity of applications: from the moment you're used to Pure Data, you can work your sound of guitar as you wants, and can control it as you want, since you choose what the pedals do. Thus the possibilities are enormous for people impassioned, and who have free time. 

Edit 2014

A new version of the source code is available on gitorious for those interested:
https://gitorious.org/elboulangero/looper



3 comments:

  1. I can't open your link to the pd patches... what application am I opening it with? are these suppose to be patches? What operating system are they intended for?

    ReplyDelete
  2. if i use new switches they have to be on/on or on/off type?also can i use a pot if i don't have an expr pedal?

    ReplyDelete
  3. Your Pd patches are quite logically structured. Do you know if they work in libpd?

    In your Arduino code there is no need for the delay(10) function call. Delay turns off interrupts in the MCU and basically bricks your Arduino until the delay() function returns. If you want to sample inputs less frequently you can keep a last_millis register and sample the input at a specified rate.

    ReplyDelete

About Me

french version here : http://www.arduino.cc/playground/Projets/LooperPourGuitare