My First Circuit Bending

Last week-end I have bought five noise-making plastic toys at a yard sale in Paris; I then ordered knobs and switches from ebay and from a local electronic store. What for? For the purpose of circuit bending of course!

Noisy toys found in a yard sale
Noisy toys found in a yard sale

First failure

Out of the four toys, one was already non working when trying with new batteries. Once opened, there was nothing visibly wrong, every wire connected. Whatever what we do with it, only noise comes out from the two speakers.

The mini keyboard, already broken before any circuit bending
The mini keyboard, already broken before any circuit bending

Second failure

I searched how to start the art of circuit bending (I have been taught electronics in the academic fashion in engineering school, but I suspected circuit bending was somewhat different: usually in a lab, you do your best to avoid short circuits, at all costs!

The toy I killed by mistake
The toy I killed by mistake

I therefore read (but too quickly) the introduction by Reed Ghazala before opening the second toy. Then I started to short circuit each pin to each other while triggering the noises. After a few minutes, I believed I had found an interesting connection (as the sound was getting slightly strange) but immediately after, no more noise. I killed the toy.

Now I understand that having the sound slightly strange is precisely what we need to avoid. It was written in the guide…

Third try

Looking further I discovered additional advices (use only the body resistance to start connecting pins together, use a voltmeter to mark every high tension on the circuit to avoid them later).

The little music box, before anything happened
The little music box, before anything happened

Then it was quick since the circuit is so simple. I added a mini Jack output and checked it with headphones. I also added a switch on the output in order to interrupt the sound, and another (UPDATE) on the batteries wires to be able to shut down very quickly, just in case…

The inside with additional switches and Jack output
The inside with additional switches and Jack output

With only 4 resistors on the circuit it was easy to bypass them with my body resistance, and R2 is obviously controlling the pitch. So happy, this is really that simple. R2 is 100K?, so now I must test bypassing it with a potentiometer to find out the right value range to use. As it is all SMC (surface mount component) there will be some sport.

UPDATE I removed the 100K? SMC resistor that controls the pitch and replaced it with a 470K? potentiometer plus a serial 10k? resistor plus a serial switch to pause the playback (playback goes on where it was when switching back on, since the pause switch actually stops the clock to the chip).

The most difficult part was actually to put everything into the small box, without breaking anything.

It is a very simple circuit bending since only the pitch is controlled here.

Here is a demo video on Vimeo:


Scratching with a circuit bent jukebox toy from cyrille martraire on Vimeo.

Read More

Knobs pagination in Arduino

Here is an example of how to use the same knobs (e-g. 6 knobs easy to connect to the 6 Arduino analog inputs) several times to adjust several parameters spread over several “pages”.

This enables to “multiplex” the same knobs many times, in a safely fashion thanks to the protection mecanism:  after changing the active page, every knob is in protected mode (turning the knob does not change the value of the parameter) not to force a sudden jump of value. On turning a knob, the LED lights on when the knob’s value matches the stored value, and then the knob becomes fully active (at least till the next page switch).

This mecanism is inspired and similar to that of the microKorg synth edit knobs. As they say about it in Wikipedia:

“In the Edit mode, however, every knob makes the LED panel display the current value associated with the knob position. To change the current value of a given parameter, the user must pass through the original value before being able to modify anything. When one that original value, the Original Value LED will light on, and the value displayed on the LED panel will stop flashing. This avoids the user from passing from a small to a high value immediately, so there’s no big margin in the change of the parameters (a useful function for live performances).”
The microKorg Edit panel, with 5 knobs and 22 pages = 120 parameters to control
The microKorg Edit panel, with 5 knobs and 22 pages = 120 parameters to control

In Arduino

Console output printing the 4 pages of 6 parameters and the currently active page
Console output printing the 4 pages of 6 parameters and the currently active page

To do this in Arduino is not very difficult.We first need a 2-dimension array to store the value of each parameter:

// the permanent storage of every value for every page, used by the actual application code
int pageValues[PAGE_NB][KNOB_NB];

We also need an array to store the state of each knob: whether it is PROTECTED or ACTIVE, and yet another array to keep track of the value of each knob in the previous loop, in order to detect when a knob is being turned:

// last read knob values
int knobsValues[KNOB_NB];
// knobs state (protected, enable...)
int knobsStates[KNOB_NB];

Then we begin to read the digital switches to select the current active page. In case the selected page has changed, every knob has its state set to PROTECTED. We then read the analog value for each knob, detect changes, find out when the knob value is in sync with the stored value for the parameter to light the LED and set its state to ACTIVE.

Only when the state is set to ACTIVE we copy the current value of the knob to the actual parameter stored for the current page.

In my experiment I have 4 digital buttons connected to digital inputs 8 to 11, and 6 knobs (pots) connected to the 6 analog inputs:

The Arduino board, the 4 page buttons and the 5 + 1 knobs and fader
The Arduino board, the 4 page buttons, the 5 + 1 knobs and fader and the LED

Here is the full code below:

/*
 * Handles a pagination mecanism, each page can use the same knobs;
 * Digital switches select the current active page.
 *
 * This enables to "multiplex" the same knobs many times, safely thanks to the protection mecanism.
 *
 * After changing the active page, every knob is protected, not to force a jump in value.
 * On turning a knob the LED lights up when the knob's value matches the stored value, and then
 * the knob becomes active till next page switch.
 *
 * This mecanism is inspired and similar to that of the microKorg synth edit knobs.
 *
 * Copyleft cyrille martraire cyrille.martraire.com
 */ 

//---------- USER INPUT AND PAGINATION -----------
#define PAGE_NB 4
#define KNOB_NB 6
#define FIRST_PAGE_BUTTON 8

#define PROTECTED -1
#define ACTIVE 1

#define SYNC_LED 12

// the permanent storage of every value for every page, used by the actual music code
int pageValues[PAGE_NB][KNOB_NB];

// last read knob values
int knobsValues[KNOB_NB];
// knobs state (protected, enable...)
int knobsStates[KNOB_NB];
// current (temp) value just read
int value = 0;
// the current page id of values being edited
int currentPage = 0;
// signals the page change
boolean pageChange = false;
//temp variable to detect when the knob's value matches the stored value
boolean inSync = false;

void setup() {
  pinMode(13, OUTPUT);

  Serial.begin(19200);

  setupPagination();
}

void setupPagination(){
  pinMode(SYNC_LED, OUTPUT);
  for(int i=0; i < KNOB_NB; i++){
    knobsValues[i] = analogRead(i);
    knobsStates[i] = ACTIVE;
  }
}

// read knobs and digital switches and handle pagination
void poolInputWithPagination(){
  // read page selection buttons
  for(int i = FIRST_PAGE_BUTTON;i < FIRST_PAGE_BUTTON + PAGE_NB; i++){
     value = digitalRead(i);
     if(value == LOW){
         pageChange = true;
         currentPage = i - FIRST_PAGE_BUTTON;
     }
  }
  // if page has changed then protect knobs (unfrequent)
  if(pageChange){
    pageChange = false;
    digitalWrite(SYNC_LED, LOW);
    for(int i=0; i < KNOB_NB; i++){
      knobsStates[i] = PROTECTED;
    }
  }
  // read knobs values, show sync with the LED, enable knob when it matches the stored value
  for(int i = 0;i < KNOB_NB; i++){
     value = analogRead(i);
     inSync = abs(value - pageValues[currentPage][i]) < 20;

     // enable knob when it matches the stored value
     if(inSync){
        knobsStates[i] = ACTIVE;
     }

     // if knob is moving, show if it's active or not
     if(abs(value - knobsValues[i]) > 5){
          // if knob is active, blink LED
          if(knobsStates[i] == ACTIVE){
            digitalWrite(SYNC_LED, HIGH);
          } else {
            digitalWrite(SYNC_LED, LOW);
          }
     }
     knobsValues[i] = value;

     // if enabled then miror the real time knob value
     if(knobsStates[i] == ACTIVE){
        pageValues[currentPage][i] = value;
     }
  }
}

void loop() {
  poolInputWithPagination();
  printAll();
  delay(100);
}

void printAll(){
     Serial.println("");
     Serial.print("page ");
     Serial.print(currentPage);

     //Serial.println("");
     //printArray(knobsValues, 6);
     //Serial.println("");
     //printArray(knobsStates, 6);

     for(int i = 0; i < 4; i++){
       Serial.println("");
       printArray(pageValues[i], 6);
     }
}

void printArray(int *array, int len){
  for(int i = 0;i< len;i++){
       Serial.print(" ");
       Serial.print(array[i]);
  }
}

Read More

Rhythmic clock machine

The rotating mirror and the 4 laser beams
The rotating mirror and the 4 laser beams

I finally received ten retroreflectors, the experiments started in Playing with laser beams to create very simple rhythms”, we can now move on.

Once again, the rotating mirror is reflecting the four parallel laser beams so that they sweep a 180 degrees area, where some retroreflectors are positioned to hit the beams trajectories.

Every time a beam hits a reflector then it should trigger a sound on a MIDI synth (here it is my little microkorg playing the sounds).

Generative music (a.k.a mangled rhythm)

However in the first try I forgot to set a short loop perid (the period was set to 100ms). Given the velocity of the laser beam when it hits the reflectors there is very little time to catch the signal on the sensors, and with a measure every 100ms the Arduino is missing most hits.

This means we got a simple and regular theoretical rhythm that is mangled by the input sampling process, and this fuzzyness actually creates “interesting” generative music, as in the video:


Generative music installation with laser beams and low-frequency sensors sampling from cyrille martraire on Vimeo.

Note that it is not totally random… (actually it is not random at all, just the result of different frequencies that sometime are in sync and most times are not).

Laser beams on the wall
Laser beams on the wall

Regular rhythm at last

With a shorter Arduino loop period (10ms) it becomes reliable: every (almost) hit triggers a note, as illustrated in the next video where we can hear a steady rhythmic pattern.

The Arduino code is quite simple: for each of the 4 sensors, read analog value, compare to threshold, debounce (not to send multiple notes for the actual same hit), then send MIDI note.

Arduino code for the rhythmic clock project

Laser beams generate regular rhythm at least from cyrille martraire on Vimeo.

Any feedback welcome…

Read More

Playing with laser beams to create very simple rhythms

Just like many arts, music arousal is considered to follow the well-known Wundt curve that defines the balance between attractiveness and boredom. Too much repetition is boring, not enough repetition is confusing and considered just noise.

What for?

Let us assert that idea to music, to generate rhythms. A very simple application of the Wundt curve principle is to consider one given rhythmic pattern (e-g. , “x.x.xx..”) then to build up a more elaborate polyrhythm by combining various repetitions of it, although each copy must be distorted a bit to make the combination more complex hence more attractive. In other word, given a rhythmic seed, make it grow a rhythmic tree.

The transforms to apply to the rhythmic patterns can be linear:

  • Reverse (“..xx.x.x”)
  • Roll (“x.x.xx..”)
  • Scale 2:1 (“x…x…x.x…..”) or 1:2 (“xxx.”)

or non-linear:

  • Truncate (“xx..”)
  • Switch timbre (not really a transform, just to put somewhere)

In practice

To put that into practice I have been trying simple Java programs long ago, but it was too slow a process, and since I did not build a genetic algorithm around it was driven at random.

To make it more fun to investigate, we have started a small project of building an instrument to program rhythms on using laser beams and small reflectors. Each reflector triggers a sound (on a MIDI controlled MPC500) when hit by a laser beam (you need the sound on to listen to the Clap sound being triggered):

Playing with the beams to create very simple rythms from cyrille martraire on Vimeo.

The Arduino board
The Arduino board

Then by having several reflectors linked to each other to make patterns, we expect to be able to program rhythms by moving reflectors sets in the playground, using its geometry to derive the transformations to apply to the patterns.

EDIT: here is another video after some progress:

Playing with dual beams for kick and clap beat from cyrille martraire on Vimeo.

Read More