Tag Archives: gadget

Looks Like Chaos

We had an art festival this month, and my students encouraged me to submit a piece. The theme was “Inside my Mind”, so I thought about how I could represent the near-incomprehensibility emergent nature of human thought.

2014-01-26 15.27.32

I decided to build an electronic device that would carry a nearly-random signal to a computer display. The screen displayed coloured lines that, if looked at individually, would appear to be changing colour randomly. However, if you sit back and take in the whole screen, patterns — both recurring and transient — begin to emerge. In the still image above, the monitor on the left is displaying the output (along with a pesky dialogue box in the middle of the screen).

To build this, I used an Arduino that was programmed to output a signal via a VGA cable. The Arduino’s 16 MHz clock speed isn’t fast enough to output a signal pixel-by-pixel, but by counting cycles (the “nop”s in the code below) I was able to get close enough that the signal could be interpreted and displayed by a monitor.

The code is below. I enjoyed this project, and learned a lot about timing in microcontrollers, but wouldn’t recommend it to anyone else, as much of the time is spent fine-tuning the timings.

#include <avr/io.h>
#define VSYNC_LOW    PORTD &= ~_BV(6)
#define VSYNC_HIGH   PORTD |= _BV(6)
#define HSYNC_LOW    PORTD &= ~_BV(7)
#define HSYNC_HIGH   PORTD |= _BV(7)
void setup() {
}
void loop() {
int i = 0;
cli();
DDRB = 0xFF;
DDRD = 0xFF;
byte noise = B00001100;
//Loop Over-And-Over Again
  while(1){
      // Vertical Data
      i=0;
      while(i < 600){
            //2.2uS Back Porch
          byte noise = byte(micros());
          noise &= B00011100;
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
          __asm__(“nop\n\t”);
            //20uS Color Data
          PORTB ^= noise;
          delayMicroseconds(19);
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
          __asm__(“nop\n\t””nop\n\t”);
          PORTB ^= B00000000;
            //1uS Front Porch
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
            //3.2uS Horizontal Sync
          HSYNC_HIGH;
          delayMicroseconds(3);
          __asm__(“nop\n\t””nop\n\t”);
          HSYNC_LOW;
          i++;
      }
      // Vertical Porch
      while(i < 1){
          delayMicroseconds(2);
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
            //20uS Color Data
          delayMicroseconds(20);// 20uS
            //1uS Front Porch
          delayMicroseconds(1); // 1uS
            //HSYNC for 3.2uS
          HSYNC_HIGH;
          delayMicroseconds(3);
          __asm__(“nop\n\t””nop\n\t”);
          HSYNC_LOW;
          i++;
      }
      // Vertical Sync
      i=0;
      VSYNC_HIGH;
      while(i<4){
            //2.2uS Back Porch
          delayMicroseconds(2);
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
            //20 uS Of Color Data
          delayMicroseconds(20);// 20uS
            //1uS Front Porch
          delayMicroseconds(1); // 1uS
            //HSYNC for 3.2uS
          HSYNC_HIGH;
          delayMicroseconds(3);
          __asm__(“nop\n\t””nop\n\t”);
          HSYNC_LOW;
          i++;
      }
      VSYNC_LOW;
      i=0;
      while(i < 22){
            //2.2uS Back Porch
          delayMicroseconds(2);
          __asm__(“nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t””nop\n\t”);
            //20uS Color Data
          delayMicroseconds(20);// 20uS
            //1uS Front Porch
          delayMicroseconds(1); // 1uS
            //HSYNC for 3.2uS
          HSYNC_HIGH;
          delayMicroseconds(3);
          __asm__(“nop\n\t””nop\n\t”);
          HSYNC_LOW;
          i++;
      }
  }
}

Gadget: Infinite Monkey

The Infinite Monkey Theorem [IMT] states that a sufficiently-large number of monkeys, randomly hitting keys on typewriters, will eventually reproduce the works of Shakespeare. It’s an “order hidden in chaos” claim as old as history. Let’s ignore the problems with using monkeys (ie: intelligence, low output, boredom, etc).

Mathematically, the IMT relies on the monkeys providing a random string of characters. The likelihood of a given string corresponding to a known text (ie: Shakespeare) is very, very small — but not infinitesimal. Thus, if you wait long enough, the probability will grow until you can be reasonably confident a certain string will be produced (however, after no amount of time can you be 100% sure — just as after no number of coin flips can you be completely sure you’ve gotten at least one tail).

What I find interesting, and overlooked by most people who hear about the IMT, is how quickly the numbers grow. To bring these issues to light, I used an Arduino and an 8×8 LED matrix to simulate a monkey. 5 times per second, a letter is randomly chosen and drawn. If the string of letters matches the string “TOBEORNOTTOBE” (“to be or not to be”, the display pauses and green LEDs at the bottom of the display indicate the number of letters in the string that match.

2014-01-03 10.47.57

In the above image, the letter T has just appeared, and the single green LED signals that there is a one-letter match. You’d need to wait an one hour (on average) in order to see the string “TOB”, and about a day (on average) to see “TOBE”.

The 19-character string, “TOBEORNOTTOBE” will come along on average once every 10 000 million million years, or a million times longer than the age of the universe.

The full text of Hamlet will take a bit longer.