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



← Previous Page