Introduction to Physical Computing
RF Fun

For our midterm, part of the project is to build a wand which will serve
as an interface for manipulating a series of photos. The wand itself
needs to be wireless, so users don't feel restricted in their use of the
wand. We don't want people getting tangled up, or lassoing others up.
The accelerometer can take some punishment, so I'd like people to swing
with gusto.

For the project we are using Sparkfun's RF Link - 4800bps - 434MHz.
This RF link is also sold at the NYU Computer Store.

First of all, the KLP Walkthrough Tutorial was very helpful.
The first two RF link's I bought were bad, I don't know why. I don't
*think* I did anything to toast them. Tom was kind enough to lend me
his so I could continue working.

TX (transmitting) code-


byte counter;

void setup()
{
    // 4800 baud model, but use 2400
    Serial.begin(2400);
    counter = 0;
}

void loop()
{
    Serial.print(counter, BYTE);
    counter++;
    //delay(1);
}



RX (receiving) code-


int incomingByte = 0;

void setup()
{
    Serial.begin(2400);
}

void loop()
{
    if (Serial.available() > 0) {
        incomingByte = Serial.read();
        Serial.println(incomingByte, DEC);
    }
    //Serial.println("I am having fun");
}


A few lessons I learned-

1. Despite being good for up to 4800 bps, using 2400 bps with no delay
seemed to be the most reliable.

2. When loading code to the receiver module, make sure the wire to RX is
DISCONNECTED, otherwise the arduino gets confused (RX is shared with
USB, so the arduino can't differentiate between incoming RF data and the
computer data).

3. When printing out values to the computer, the serial to USB
conversion seems slower than the rate of incoming data, causing the RX
buffer to overflow... basically, all the incoming data wasn't being
printed, it looked like 0, 200, 240, 5, 10 - just bits and pieces. The
code below adds the values up to make sure the data being received is
consistent.

4. Range- 3-4 meters, by powering from the arduino and using an antenna.

RX code with consistency check-


int incomingByte = 0;
int c = 0;
int total=0;

void setup()
{
    Serial.begin(2400);
}

void loop()
{
    if (Serial.available() > 0) {
        incomingByte = Serial.read();
        Serial.println(incomingByte, DEC);
        c++;
        total += incomingByte;
        if (c == 256) {
            Serial.print(total, DEC);
            Serial.print(" ");
            Serial.println("loop");
            c = 0;
            total = 0;
        }
    }
    incomingByte = 0;
//Serial.println("I am having fun");
}


The next step was to battery power the wand. Just adding a battery (9V)
to the arduino didn't seem to work. The power LED came on, but no data
was being transmitted. After a bit of experimenting, I realized
plugging the USB cable in after the arduino boots jumpstarts data
transmittal. Why? Turns out with the Arduino NG (rev. c) you need to
keep RX from floating. Do this by adding a 10k resistor from RX to
ground. In my case, this didn't interfere with the reprogramming of the
device. Refer to this page for more info.



-- Mon, 15 Oct 2007 21-39 -0400

Copyright © 1996-2008 Alexander Reeder
All rights reserved unless otherwise noted