Physical Computing, sensors, etc.

Polar G3CHR
    Polar G3CHR



    The Polar G3CHR is a wireless heart rate monitor. It is available from
    the OEM division of Polar. Please refer to this link for the manual.
    It is really easy to use. Connect J2 pin 1 to ground, J2 pin 2 to Vcc
    and J2 pin 3 to a led (no resistor necessary). First check to make
    sure it is working with the Polar Heart Rate Simulator. The G3CHR uses
    RF for communication, and the simulator basically sends a signal
    simulating a heart beat which cases the LED to blink.

    Before using the strap make sure the Heart Rate Simulator is off. Then
    strap the wireless unit to your torso. I had a few issues with getting
    the strap unit to work. The signal is apparently quite weak (with
    Polar's internal antenna in use), especially beneath clothes. Make sure
    you're close (within 2 feet) of the G3CHR. If it still doesn't work
    apply water to the conductive fabric on both sides (watch out, cold!),
    then try using it. The G3CHR is meant to be used during workouts, so
    your sweat would normally dampen the fabric.

    Kudos to DanO and Sonia for all the patient advice.

    -- Wed, 27 Feb 2008 22:56 -0500
Programming the ATMEGA168 on Mac OS X
    Programming the ATMEGA168 on Mac OS X

    Programming Platform: 2 GHz Intel Core 2 Duo Mac OS X 10.4.10
    Programmer: AVR MKII
    Chip: ATMEGA168

    1. Download and install AVR MacPack

    I use vi and the command line to program, but you could also
    2. install Xcode or Eclipse

    When it came to programming the ATMEGA, I had a problem with a several
    minute delay. One approach is to change the source and recompile.
    Rather than doing that, I used Arduino's avrdude.

    This was the command I was having trouble with - just erasing the chip:

    $ avrdude -p m168 -b 115200 -P usb -c avrispmkII -e

    1. Install Arduino
    2. cd /usr/local/AVRMacPack/bin/
    3. sudo mv avrdude avrdude.old
    4. sudo cp -p /Applications/arduino-0010/tools/avr/bin/avrdude .
    5. sudo ln -s /Applications/arduino-0010/tools/avr/etc /usr/local/etc
    6. sudo mv /usr/local/etc /usr/local/etc.old
    7. sudo ln -s /Applications/arduino-0010/tools/avr/etc /usr/local/etc

    Now programming should be no trouble...

    -- Fri, 22 Feb 2008 13:42 -0500
Bluetooth (BlueSMiRF)
    BlueSMiRF

    A few notes on Sparkfun's bluetooth beauty BlueSMiRF.

    An excellent little module. When configuring the device, it will appear
    as SPARKFUN-BT. The passkey is 'default'. Don't forget to set the baud
    rate. For details, see the datasheet.

    -- Wed, 12 Dec 2007 22:01 -0500
ID-12's RFID Reader
    Using ID-12's RFID reader



    I picked up the ID-12 RFID reader from Sparkfun. Here's the datasheet.

    Wiring the ID-12 up is straight forward.
    This page does a good job of detailing the process.
    Open the data sheet and wire things for ASCII. I added an LED behind a
    1K resistor to blink when a card was read. I also connected RESET to
    digital pin 2. I wanted to be able to detect whether a card was
    continually present. Normally when you put a RFID card on a reader, it
    is read once and that's that. I continually RESET the ID-12 to reread
    which card is present. Here's the code.


    /*
    * RFID Loop
    * by Alexander Reeder, Nov 16, 2007
    */

    #define RESETPIN 2
    #define RESETCOUNT 10
    #define RESETTIME 250

    char val = 0;
    unsigned int c = 0;
    int i = 0;

    unsigned int resetCounter = 0;
    unsigned int now = 0;

    void setup() {
        Serial.begin(9600); // connect to the serial port
        pinMode(RESETPIN, OUTPUT);    // sets the digital pin as output
        now = millis();
    }

    void loop () {

        digitalWrite(RESETPIN, HIGH);

        while (Serial.available() > 0) {
            val = Serial.read();
            Serial.print(val, BYTE);
        }

        if ((millis() - now) > RESETTIME) {
            digitalWrite(RESETPIN, LOW);
            resetCounter = 0;
            Serial.println("reset");
            now = millis();
            delay(100);    
        }
    }




    Regretfully the ID-12 cannot read multiple cards simultaneously. The
    Sparkfun RFID cards are large and bulky compared to other options. The
    reader isn't the fastest in the world... so I would recommend something
    else! The ID-12 is easy to use for those who are making their first
    foray into RFID.

    -- Mon, 26 Nov 2007 11:41 -0500
MIDI Light Dimmer
    Using the MediaMation's CL6 MIDI Light Dimmer



    Thanks to Andy Miller figuring out the MediaMation CL6 MIDI light dimmer
    wasn't too difficult. First you need to procure either: 1) a female
    MIDI connector, or 2) a MIDI cable. Don't pay attetion to how MIDI is
    suppose to work, but hack it according to Tom's page.



    Be careful of not mixing power (+5V) and data. While it won't hurt the
    CL6 is you make this mistake, nothing will happen - so if things aren't
    working as you expect, this should be one of the first things to check.
    If you need to know more about MIDI, check out this page.



    Once you have the cable made and wired into your Arduino, plug it into
    the dimmer. Having a few lights plugged into the dimmer would be good
    too. Next, program your arduino.


    // MIDI Light Dimmer Test Code
    // by Alexander Reeder, Oct. 26 2007

    #define LEDpin 13

    void setup() {
        Serial.begin(31250); // set MIDI baud rate
        blink(3);
    }

    void loop() {
        // slowly step a light up on grouping 1 from off -> on -> off
        noteOn(0x90,0,30);
        delay(1000);
        noteOn(0x90,0,55);
        delay(1000);
        noteOn(0x90,0,80);
        delay(1000);
        noteOn(0x90,0,127);
        delay(1000);
        noteOn(0x90,0,80);
        delay(1000);
        noteOn(0x90,0,55);
        delay(1000);
        noteOn(0x90,0,30);
        delay(1000);
        noteOn(0x90,0,0);
        delay(1000);
    }

    // data1 should be from 0-5, and tells the dimmer which light group
    // data2 should be from 0-127 and represents the brightness
    void noteOn(char cmd, char data1, char data2) {
        Serial.print(cmd, BYTE);
        Serial.print(data1, BYTE);
        Serial.print(data2, BYTE);
    }

    void blink(int howManyTimes) {
        int i;
        for (i=0; i< howManyTimes; i++) {
            digitalWrite(LEDpin, HIGH);
            delay(100);
            digitalWrite(LEDpin, LOW);
            delay(100);
        }
    }



    Keep in mind that MIDI serial communication happens at 31250 bps. This
    means you must use hardware serial, as software serial has a limit of
    9600 bps. FYI, you cannot use the Serial.available() class with
    software serial. Your arduino must use hardware serial at 31250 bps,
    and communicating to the CL6 uses your TX line. Keep this in mind when
    thinking of integrating the CL6 with processing or another piece of
    hardware. Finally, remember to send your data to the CL6 as bytes!

    -- Mon, 29 Oct 2007 15:09 -0400
RF Fun
    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