as3Glue - Physical Interaction in Flash

October 10, 2007 | arduino, code, flash, physical computing

I have just committed an alpha version of as3Glue to Google Code. as3Glue is an open source physical interaction libary for ActionScript 3. It enables communication between ActionScript 3 applications and Arduino boards. It can be used to monitor sensors such as rotary encoders and motion detectors, control actuators such as LEDs and motors, and to interface other electronics such as RFID readers from within Flash / Flex and Air applications.

Check it out here: as3Glue

Code Updates

May 24, 2007 | arduino, code, flash, physical computing, rfid

I’ve updated Arduino For Flash with Flash and Arduino code for the Parallax RFID reader and the Arduino Code for the Parallax RFID Reader with a new example that uses SoftwareSerial for RFID->Arduino communication. Enjoy…

Arduino Code for the Parallax RFID Reader

April 20, 2007 | arduino, code, rfid

Here’s some Arduino code that improves stability and fixes a couple of errors in the Arduino Playground code for the Parallax RFID reader. The second example uses SoftwareSerial which is handy if you don’t want to block the serial port (note that the wiring is slightly different).

// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Revised by Erik Sjodin <http://www.eriksjodin.net>

//Connect:
/*
* Arduino RX to RFID SOUT
* Arduino GND to RFID GND
* Arduino Digital pin 2 to RFID /ENABLE
* Arduino 5v to RFID VCC
*/

int  val = 0;
char code[10];
int bytesread = 0;

void setup() {
 Serial.begin(2400);    // RFID reader SOUT pin connected to Serial RX pin at 2400bps
 pinMode(2,OUTPUT);     // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
 digitalWrite(2, LOW);  // initialise the reader with a reset cycle
 delay(100);
 digitalWrite(2, HIGH);
 delay(100);
 digitalWrite(2, LOW);
 delay(100);
}

void loop() {
 digitalWrite(2, LOW);                  // activate reader
 if(Serial.available() > 0) {           // if data available from reader
   if((val = Serial.read()) == 10) {    // check for header
     bytesread = 0;
     while(bytesread<10) {              // read 10 digit code
       if( Serial.available() > 0) {
         val = Serial.read();
         if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
           break;                       // stop reading
         }
         code[bytesread] = val;         // add the digit
         bytesread++;                   // ready to read next digit
       }
     }
     digitalWrite(2, HIGH);
     if(bytesread == 10) {              // if 10 digit read is complete
       //Serial.begin(115200);            // transmit with 115200 bps
       Serial.println(code);            // print the TAG code
       //Serial.begin(2400);              // read with 2400 bps
     }
     Serial.flush();
     delay(500);                        // wait for 500 millisecond
   }
 }
}

#include <SoftwareSerial.h>

// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic
// Modified to use SoftwareSerial by Erik Sjodin <http://www.eriksjodin.net> 

//Connect:
/*
* Arduino pin 3 to RFID SOUT
* Arduino GND to RFID GND
* Arduino Digital pin 2 to RFID /ENABLE
* Arduino 5v to RFID VCC
*/

int  val = 0;
char code[10];
int bytesread = 0;
int rx=3;
int tx=4;

// set up a new serial port
SoftwareSerial rfidSerial =  SoftwareSerial(rx, tx);

void setup() {
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
  rfidSerial.begin(2400);    // RFID reader SOUT pin connected to Serial RX pin at 2400bps

  Serial.begin(115200);
  pinMode(2,OUTPUT);     // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
  digitalWrite(2, LOW);  // initialise the reader with a reset cycle
  delay(100);
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(2, LOW);
  delay(100);
} 

void loop() {
  digitalWrite(2, LOW);                  // activate reader
  if((val = rfidSerial.read()) == 10) {    // check for header
    bytesread = 0;
    while(bytesread<10) {              // read 10 digit code
      val = rfidSerial.read();
      if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
        break;                       // stop reading
      }
      code[bytesread] = val;         // add the digit
      bytesread++;                   // ready to read next digit
    }
    digitalWrite(2, HIGH);
    if(bytesread == 10) {            // if 10 digit read is complete
      Serial.println(code);          // print the TAG code
    }
    delay(500);                        // wait for 500 millisecond
  }
}

The Parallax RFID Reader

April 16, 2007 | arduino, hardware, rfid, sensors

Parallax RFID ReaderThe Parallax RFID reader is inexpensive and easy to hook up to an Arduino or Wiring board. It has four connectors which can be plugged right into a bread board and there is code for it available at the Arduino Playground. One thing that I really like about the reader is its small footprint. It is about the size of a playing card and just 2-7mm thick. The reading distance is dependent on the tags that are used, I got maximum distance of about six centimeters on the axis that is orthogonal to the reader and 2-3 cm on the parallel axis. A short reading distance can be a good or a bad thing depending on the application. If you like me want to identify a shoe with an embedded RFID tag when the wearer enters an area, then it’s a not so good thing. If you know of another inexpensive and easy to interface reader that has a greater reading distance I’d be very interested in hearing about it…

Update: I have posted some Arduino code that improves stability and fixes a couple of errors in the Arduino Playground code for the Parallax RFID reader.

Rotation Sensors

April 11, 2007 | arduino, hardware, sensors

Rotating pulse sensor Mechanical rotary shaft encoders such as the one pictured to the left are probably the cheapest way to measure rotation. This particular encoder, which costs about 2 euro, has 24 steps per revolution. The resolution is a bit of the low side for many applications but it can be increased with gears or wheels. Shaft encoders only measure relative rotation. In other words you can’t know at which position the sensor is when you first read it, but you can keep track of how much and in which direction it has turned since you started to read it.

Rotary encoders are not only cheap, they are also simple to hook up to Arduino or Wiring boards. To put it short you monitor a pin on the encoder and when it changes state you check the state of another pin to determine in which direction the encoder was turned. Paul Badger has posted some nice Arduino code for rotary encoders on the Arduino playground.

Alternatives to mechanical encoders are optical rotary encoders and 360 degree potentiometers. These encoders often have significantly higher resolution than the mechanical ones and some (such as potentiometers) can be used to measure absolute rotation. The downside is that they are more expensive (usually around 50 euro or more). A budget alternative is to go trash hunting for an old printer with a motor that has an optical encoder that you can reuse (check out this Make video). Not all printers have these motors though, I’ve trashed three so far without any luck…

Arduino For Flash

March 25, 2007 | arduino, code, flash, physical computing

I’ve just released Arduino for Flash, an ActionScript 3.0 package that makes it easy to control Arduino boards with the Firmata 1.0 firmware from Flash.