Tuesday, February 11, 2014

Robot Arm H25 Demo

Here is a video that I made that shows my Python library driving a robot arm via Bluetooth. The demo program is pretty short. Build instructions for the arm can be found here.


Saturday, January 25, 2014

I borrowed a Lego Mindstorms EV3 from someone so I could get to know it. The platform is quite hackable but I didn't want to modify the brick's file system because it isn't mine. Instead, I wrote a simple Python library for executing commands over Bluetooth: EV3

Sunday, September 25, 2011

RFID Garage Door Opener

    I spend a lot of time in and around my garage and encourage other nerds to do the same. I want to make sure that if someone is working on a project and I am not around that they can still access my garage. Giving people house keys is a bad idea because they are easily copied and give unlimited access to the entire house. RFID tags, however, are hard to copy, easy to revoke, and allow for time-based access. So I built a box to activate my garage door opener using an RFID reader.

    I started with a Parallax RFID reader from RadioShack. Then I added an Atmega 328p microcontroller, reed switch relay, DS1306 real time clock, LM386N-1 audio amplifier, speaker, and support circuitry to create an RFID control box.
    The smaller box contains only the RFID reader itself. It is pushed as close to the door as possible so tags can be read through the rubber trim surrounding the door. The following photo shows the metal race that the door travels along, the edge of the RFID reader box, the strip of rubber trim, and the box that I made using tape to delineate the area near the reader so that it can be located when the door is closed.
 The larger box contains the rest of the circuitry. I cut two breadboards to fit into the slots of a cheap project box from RadioShack and placed the noisy components on the bottom board and the sensitive ones on the top board.
    The bottom of the box has a DB-9 connector for RS-232 that allows for configuration via a separate computer. The microcontroller only has one UART so the DB-9 connector has to share it with the RFID reader. There is a small constant switch adjacent to the port to select between the two.
    The firmware is AVR-GCC C and I used Python to make a pygtk GUI for configuring tag information. Now I can grab an RFID tag out of the drawer and assign it a description (i.e. 'Rebecca's tag.') and a period of time for each day of the week (i.e. weekends between noon and 5pm) when it is valid.

    Contact me if you are doing something similar and have any questions or want a copy of the firmware (under the GPL). I didn't capture the schematic in Eagle but I did take photos of my notebook and adjusted the contrast until they are semi-legible.

Saturday, February 13, 2010

Connecting to the NXT via Bluetooth with Ubuntu

I recently decided to explore the possibility of controlling a NXT robot from a PC via Bluetooth. I have a super cheap Bluetooth USB dongle that I purchased for fewer than $5 from Fry's that I've never gotten to work under Windows XP with NXT-G, RobotC, or Bricx Command Center. However, Ubuntu (Karmic) finds the dongle automatically and connecting to the NXT is easy.

The first step is to make sure that your Bluetooth device is present:

$ hcitool dev
Devices:
    hci0    00:11:67:58:A7:7A

You can then ensure that your device is UP using:

$ hciconfig hci0
hci0:    Type: USB
    BD Address: 00:11:67:58:A7:7A ACL MTU: 678:8 SCO MTU: 48:10
    UP RUNNING PSCAN ISCAN
    RX bytes:4779 acl:74 sco:0 events:195 errors:0
    TX bytes:2263 acl:98 sco:0 commands:55 errors:0

To find the address of your NXT:

$ hcitool scan
Scanning ...
    00:16:53:01:53:38    NXT

The NXT exposes a serial port profile on channel 1. So to create a COM port connection to it (substitute your own address for mine):

$ rfcomm connect /dev/rfcomm0 00:16:53:01:53:38 1
Connected /dev/rfcomm0 to 00:16:53:01:53:38 on channel 1
Press CTRL-C for hangup

If your NXT hasn't been paired with your PC yet you should see a dialog requesting the NXT's PIN. The default is "1234". If the connection fails try again. If the connection worked you should see "*<>" in the top left of your NXT's LCD.

The specifics for talking to the NXT are well-documented in the "Bluetooth Developer KIt" that is available at http://mindstorms.lego.com/en-us/support/files/default.aspx.

The serial port configuration should be 9600baud, 1 stop bit, 8 bits per message, and no parity. Here is a sample Python script for reading the Firmware ID of your brick:

#! /usr/bin/python

import serial

# Configure and open the port.
port = serial.Serial()
port.setPort('/dev/rfcomm0')
port.setBaudrate(9600)
port.setStopbits(1)
port.setByteSize(8)
port.setTimeout(500)
port.setParity('N')
port.open()

# Send FW Version request.
port.write('\x02')
port.write('\x00')

port.write('\x01')
port.write('\x88')

# Response expected is [7,0][2,88,0,?,?,?,?]

result = port.read(9)
for c in result:
    print "%x" % ord(c)

port.close()

All of the packets sent and received via Bluetooth should start with a size packet that consists of two bytes. The first is the number of bytes in the command (NOT including the size packet, maximum of 64). The second is zero. So if we write the size packet (0x02,0x00) and then the firmware version command (0x01,0x88) we get back (0x07,0x00) for the size header, (0x02, 0x88, 0x00) for the response and status, and then four bytes for the firmware and protocol numbers.

$ ./HWID.py
7
0
2
88
0
7c
1
d3
1

If you've gotten this far you are ready to experiment with the rest of the commands in the Developer Kit. Have fun and remember to expect a 30-60mS latency between sending a command and receiving a response (if you are expecting one).

Monday, November 2, 2009

Custom NXT IR Receiver

After building our pumpkin motion detector we wanted to build a Halloween prop to control with it. We decided to use a Lego NXT because we didn't need the prop to be permanent and we wanted to prototype it in a hurry.

The plan was to hang a giant spider from a rope that would be suspended under the eaves of the house on the front porch. When an IR command is received (from a motion detector hidden in a pumpkin) the spider would rush out from behind a web-decorated tree and advance toward the sidewalk.

We created a NXT platform that rolls along a rope by hanging from a single tank track. Two motors were required for torque because it had to move a very large spider. The motors were geared up to increase speed because we wanted it to emerge suddenly.

To allow the NXT to receive IR commands I created a custom I2C slave with a 38kHz IR receiver on it. I also included two reed switches that are used to detect magnets. By attaching magnets to the ends of the rope the NXT can detect when it has reached the end of its travel. The total cost of the sensor was fewer than $15 (including the NXT cable and enclosure).

The sensor fits nicely in a small project box and is easy to attach to the NXT by building a cage around it. I attached the magnet sensors to the project box itself so they sat directly under the rope.

An IR receiver is rather handy to have for the NXT. I decided to use the RCA IR protocol because I have several remote controls around the house (including an original XBox DVD remote) that can now be used for NXT control. In this case I am using an IR transmitter that I also built to send commands automatically.

Because the sensor still has plenty of processing power to spare it is ready to be extended to suit whatever need may arise in the future. The source code (AVRStudio4 C) is available for free under the GPL by request.





Motion Activated IR Transmitter


This Halloween my girlfriend and I wanted to experiment with motion-activated decorations. We decided to make a device that is small enough to fit into a pumpkin and can perform the following functions: A) act as a decorative pumpkin light, B) contain a passive infrared (PIR) motion sensor, and C) use an infrared transmitter to control other props.

We chose to use a PIR motion sensor because they are cheap ($5-$10) and readily available (including most RadioShacks). We chose to use an IR transmitter because the components are cheap (<$5 for an IR LED and 38kHz receiver pair) and we didn't want to have wires strung around the yard. We used a really cheap strobe light from Target ($2) as the main housing. After removing all of the existing electronics we replaced the cheap LEDs in the reflector with one IR LED and mounted a 2"x2" breadboard inside on standoffs. We snaked an RGB LED out of the back of the housing on a harness composed of 22gauge solid wire so it was bendable and positionable. Then we put a 1/8" stereo jack on the back panel of the housing so the PIR sensor module would be removable.

The PIR sensor itself was bolted inside a small disposable tupperware container so it could be concealed anywhere within 6' of the main pumpkin itself (for example in a smaller adjacent pumpkin or just in the bushes). We used a regular 1/8" stereo cable for the harness because the PIR sensor only requires 3 wires.

I used a cheap ($1.40) AVR microcontroller to control everything. When the sensor is idle the LED flickers green and blue and behaves like a normal pumpkin light. When the motion sensor is tripped the pumpkin sends a command using the RCA protocol (the same as the original XBox DVD remote) and then flickers red for 3 minutes before resetting.

The code (AVRStudio4 C) compiles to less than 1KB and is available under the GPL by request.

Sunday, November 1, 2009

Newspaper Box Halloween Prop


My girlfriend designed this simple Lego NXT robot to startle people who came up to our doorstep. The bot uses an ultrasonic sensor (attached to the box and hidden in spider webs) to determine when someone has stepped in front of our newspaper box. It then turns on the light sensor's red LED for dramatic effect and then thrusts a large spider (attached to the bot by a chopstick) out towards the visitor. Approximately 2 out of 3 trick-or-treaters were caught off guard.

Here is a video of it in action: http://www.youtube.com/user/ph0015d4y#p/a/u/0/8ITSmziMPSs