First draft of the installation

January 31, 2010 | Filed Under Blog, Installation Art | Leave a Comment 

Jonathan just completed the first draft of what we project the installation to look like (click on the picture to see a larger version):



digital compass and arduino – HMC6352 from Sparkfun.com

January 31, 2010 | Filed Under Blog, Installation Art | Leave a Comment 

I’ll clean this post up more later – I’m using it more as notes to myself right now.

I hooked up the HMC6352 digital compass from Sparkfun using a voltage divider in order to get it 3.3v from the 5v supply from the arduino.  I used my multimeter and tried a number of different resistors.  I came up with using the following:

5V
|
10K resistor
|
=========== about 3.3V output
|
10K resistor
5.6K resistor
5.6K resistor
|
GND

I used this great website to wire up the unit (SDA to arduino analog pin 4 and SCL to arduino analog pin 5).  I used the code posted on the site and it worked great (I posted it below). Next, I will include the code in my transmitter code and translate degrees to trigger the sculptures.

#include <Wire.h>
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
void setup()
{
// Shift the device's documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1;   // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
pinMode(ledPin, OUTPUT);      // Set the LED pin as output
Wire.begin();
}
void loop()
{
  // Flash the LED on pin 13 just to show that something is happening
  // Also serves as an indication that we're not "stuck" waiting for TWI data
  ledState = !ledState;
  if (ledState) {
    digitalWrite(ledPin,HIGH);
  }
  else
  {
    digitalWrite(ledPin,LOW);
  }
  // Send a "A" command to the HMC6352
  // This requests the current heading data
  Wire.beginTransmission(slaveAddress);
  Wire.send("A");              // The "Get Data" command
  Wire.endTransmission();
  delay(10);                   // The HMC6352 needs at least a 70us (microsecond) delay
  // after this command.  Using 10ms just makes it safe
  // Read the 2 heading bytes, MSB first
  // The resulting 16bit word is the compass heading in 10th's of a degree
  // For example: a heading of 1345 would be 134.5 degrees
  Wire.requestFrom(slaveAddress, 2);        // Request the 2 byte heading (MSB comes first)
  i = 0;
  while(Wire.available() && i < 2)
  {
    headingData[i] = Wire.receive();
    i++;
  }
  headingValue = headingData[0]*256 + headingData[1];  // Put the MSB and LSB together
  Serial.print("Current heading: ");
  Serial.print(int (headingValue / 10));     // The whole number part of the heading
  Serial.print(".");
  Serial.print(int (headingValue % 10));     // The fractional part of the heading
  Serial.println(" degrees");
  delay(500);
}


cheap wireless RF communication; arduino to arduino = switch to LED

January 24, 2010 | Filed Under Blog, Installation Art | 4 Comments 

A week ago, I got the cheap wireless rf transmitter / receiver pair (from sparkfun) to work very well using VirtualWire.h library (pdf).  I think I got it to transmitted from one arduino to another up to about 300 feet (according to what it looked like on Google Maps).

It is very simple to wire up. The switches attached to digital pin 9 and 10 have a 220ohm resister between the digital pin and ground – then one wire from the switch goes to the digital pin and the other goes to 5V. The receiver and transmitter are wired as follows. Someone said to connect the data pins together, but it works great as shown below (I think Tom Igoe explains that the data pins are different, the one I leave untouched can be used in different applications).

Here is the code I adapted for the transmitter (from the VirtualWire.h library examples). Make sure you add a greater than < and a less than > symbol around VirtualWire.h in the beginning of the code (the plugin I’m using to display code will not let me add them ???):

// transmitter.pde
 
#include VirtualWire.h  // http://www.open.com.au/mikem/arduino/VirtualWire-1.4.zip
 
int switchPin1 = 9; 	// switch connected to digital pin 2
int switchValue1; 	// a variable to keep track of when switch is pressed
int switchPin2 = 10; 	// switch connected to digital pin 2
int switchValue2; 	// a variable to keep track of when switch is pressed
 
void setup()
{
 
    pinMode(switchPin1, INPUT);        // sets the switchPin to be an input
    digitalWrite(switchPin1, HIGH);    // sets the default (unpressed) state of switchPin to HIGH
    pinMode(switchPin2, INPUT);        // sets the switchPin to be an input
    digitalWrite(switchPin2, HIGH);    // sets the default (unpressed) state of switchPin to HIGH 
 
    vw_setup(2000);	 // Bits per sec
}
 
void loop()
{
    ////// check switch1 //////
    const char *mymessage1 = "B";
       // check to see if the switch1 is pressed
       switchValue1 = digitalRead(switchPin1);
         if(switchValue1 == LOW) {
           mymessage1 = "Y";
          }
          else {
           mymessage1 = "N";
          }
 
    digitalWrite(13, true);  // turn on LED to show transmitting
    vw_send((uint8_t *)mymessage1, strlen(mymessage1)); // transmit message
    vw_wait_tx();  // Wait until the whole message is gone
    digitalWrite(13, false); //turn off LED to show tranmitting is done
 
    ////// check switch2 //////
    const char *mymessage2 = "C";
        // check to see if the switch2 is pressed
        switchValue2 = digitalRead(switchPin2);
          if(switchValue2 == LOW) {
            mymessage2 = "Z";
          }
          else {
            mymessage2 = "O";
          }
 
    digitalWrite(13, true);  // turn on LED to show transmitting
    vw_send((uint8_t *)mymessage2, strlen(mymessage2));  // transmit message
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);  // turn off LED to show transmitting is done
 
    // I still need to do some more research as to how often it can check the state
    // of the switch . . . how often can it transmitt? baud rate limits?
    delay(200);
}

Here is the code I adapted for the reciever (from the VirtualWire.h library examples). Make sure you add a greater than < and a less than > symbol around VirtualWire.h in the beginning of the code (the plugin I’m using to display code will not let me add them ???):

// receiver.pde
 
#include VirtualWire.h // http://www.open.com.au/mikem/arduino/VirtualWire-1.4.zip
 
char inString[32];
int inCount;
 
void setup()
{
 
  pinMode(9, OUTPUT);        // sets the LED pin to be an output
  pinMode(10, OUTPUT);        // sets the LED pin to be an output
 
    ////// serial code is commented out because this application does  //////
    ////// not require a computer - remove comment to send to computer //////
    //Serial.begin(9600);
    //Serial.println("setup");
 
    vw_setup(2000);	 // Bits per sec
 
    vw_rx_start();       // Start the receiver PLL running
}
 
void loop()
{
 
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    inCount = 0;
 
    if (vw_get_message(buf, &amp;buflen)) // Non-blocking
    {
      int i;
      digitalWrite(13, true); // turn on LED to show received good message
      // Message with a good checksum received, dump it.
      //Serial.print("Got: ");
      for (i = 0; i &lt; buflen; i++)
      {
        //Serial.print(buf[i]);
        //Serial.print(" ");
        inString[inCount] = buf[i];
        inCount++;
      }
        //Serial.println("");
 
        ////// if statements comparing incoming message //////
        if (strcmp(inString, "N") == 0){
          digitalWrite(10, true);
        }
 
        if (strcmp(inString, "Y") == 0){
          digitalWrite(10, false);
        }
 
        if (strcmp(inString, "O") == 0){
          digitalWrite(9, true);
        }
 
        if (strcmp(inString, "Z") == 0){
          digitalWrite(9, false);
        }
      digitalWrite(13, false); // turn off LED to show done
    }
}

It is easy to get the arduinos to react differently depending on what you put in the end of the reciever code. For example, one receiver arduino could have the following code, which would light an LED on pin10 if switch1 were depressed:

        ////// if statements comparing incoming message //////
        if (strcmp(inString, "N") == 0){
          digitalWrite(10, true);
        }
 
        if (strcmp(inString, "Y") == 0){
          digitalWrite(10, false);
        }
      digitalWrite(13, false); // turn off LED to show done
    }
}

The other receiver arduino could have the following code, which would light an LED on pin10 if switch2 were depressed:

        ////// if statements comparing incoming message //////
        if (strcmp(inString, "O") == 0){
          digitalWrite(10, true);
        }
 
        if (strcmp(inString, "Z") == 0){
          digitalWrite(10, false);
        }
      digitalWrite(13, false); // turn off LED to show done
    }
}

The following pix show me pressing switch1 and switch2 (I’m using arduinos on breadboards and a Duemilanove):



USB Keyboard Hack 4 Foot Pedals

January 24, 2010 | Filed Under Blog | 2 Comments 

I’m working out how to trigger things in Isadora for the interactive percussion and video piece I’m writing for Logan Dean.  I want something any computer will recognize without having to install Arduino drivers.  So, I ripped apart a USB keyboard to make foot pedals that will trigger single key commands (there are a number of Instructables on this = this one and this one, for example, online = for that reason, I am not writing good step-by-step instructions – this is more of a documentation for myself).

NOTE: What I just realized was that when you plug the USB into a computer it asks you to press “the key to the left of shift” etc. . . . so I’m working this out now.

So first I ripped apart the keyboard:

Below is the part that we’re after, when two of the contacts are connected, a key command is sent to the computer:

Below is the other side:

I took a picture of the two layers within the keyboard and raised the contrast to very high.  Then I filled in all the circuit wires with colors using the paint bucket tool in Photoshop.  Then, I figured out what combination produced what key commands and entered them on the chart below.

NOTES: Make a switchboard (matrix) like old telephone operators used so key commands can be changed OR use switches to enable changing between a set number of different key commands for different pedals.  How many pedals?  Have a shift pedal so it will double what pedals can do — maybe have this be a toggle pedal with an LED showing that shift is down . . . will this slow down the computer? I’m afraid to use caps lock because of no state indication on the pedal.



glass pot top

January 5, 2010 | Filed Under Blog | Leave a Comment 



waveform view

to download = click this link for the sample’s page at freesound.org



dslr shutter

January 4, 2010 | Filed Under Blog | Leave a Comment 



waveform view

to download = click this link for the sample’s page at freesound.org