The Giant Claw Game! – Pictures

The Cart

The cart will be used to move the claw around the XY table. The cart will also have a spindle on it to raise and lower the claw. The spindle is powered by a drill motor. I still have to figure out a way to run the power and data wires to the cart without the wires getting tangled up, while the cart is in motion.

Originality the cart was attached to the cables with springs. The idea was that the springs would add tension to the cables making it easier for the motor pulleys to grip the cables. What actually happened was the springs buffered the movement of the cables and the cart moved in jerks. I replaced the cable with a tensioning hook (I am not sure what they are actually called) and it became smoother and more responsive.

2013-05-22 21.31.56 2013-05-23 08.46.48 2013-05-20 16.26.54 2013-05-20 16.26.49 2013-05-20 16.26.58 2013-05-22 18.39.35

Pulleys

I cheap out on the pulleys at the start. I bought cheap home-depo ones that where basically a round cylinder with a pin thou the center. They worked but added lots of friction to the claw, making it harder for the drill motors to move the cart around. After struggling with these pulleys for a few days, I decided to use ball bearings and washers instead. The ball bearings cost a lot more but they worked great and dramatically reduced the amount of friction in the system.

2013-05-22 18.39.48    2013-05-22 18.39.32 2013-05-22 18.39.35 2013-05-22 18.39.40

Drill Motors/Motor Pulleys

The motor pulleys came from the junk yard and have several different levels that effect the speed and grip of the cables. I selected the largest diameter level as it would have the most surface area to pull the cables around, but it also has the side effect of moving the cables at a much faster rate then I would have liked.

I am planning on experimenting with the different pulley levels to see if I can reduce the speed while keeping the cable from slipping.

The drill motors are also really hard to mount without their plastic cases. I attempted to strap the motors in with wire straps but they keep coming lose under strain. I need to find a better way of mounting them.

2013-05-22 18.39.43 2013-05-20 18.36.52 2013-05-20 18.36.47 2013-05-20 18.36.45 2013-05-05 15.13.00

 

The Giant Claw Game! – Problems

The Giant claw game can be broken down in to a few parts. The Claw, The Joystick, The Gantry/Cube, The XY table, The Cart, Control system

The Claw 

2013-05-18 15.06.03The claw is working and it is in pretty good shape. The claw can open and closes and pick up toys. It uses a small gear motor attached to the top. The gear motor is kind of slow and takes about 20+ seconds to fully close. I am thinking about replacing this motor with one of the drills to speed it up.

I have attached limit switches to the claw so I can tell when it is fully opened and closed. This prevents the claw from crushing the stuff animals.

Bill of materials

  • 2 Cherry limit switches,
  • Terminal strip
  • Small geared motor
  • Motor shaft coupler
  • Wood

Claw limit switches  2013-05-18 15.05.50 2013-05-18 15.05.57

The Joystick 

2013-05-18 15.15.19The joystick is the simplest part of this system. It has 4 limit switches and a off the shelf  joystick that I picked up from John Jukes. All the wires lead back to a RS45 connector to make setup easier. I wanted to make this part strong in case the kids drop it and kick it around. The only thing left to do here is glue the box together.

Bill of materials

  • Wood
  • Arcade button
  • 5 Cherry limit switches,
  • 1 RS45 connector

Joy stick Joy stick wiring

The Gantry/Cube

The cube is pretty much a large wooden box made out of 2x3x8. I added trusses to the corners to make it more stable. I added the shelf to the top of the cube to allow the gantry system to ride on top of.

marqueeI would like to add a marquee banner to the top of the cube to make it look better. I am also planning on adding some fabric to the bottom so all the toys will gather in the center, making it easier for the kids to pick up a prize.

There is a lot I could do her to make it look better but I am running out of time and I may not get a chance before Breaker/Maker Faire.

Bill of materials

  • 16 2x3x8 wood beams.
  • 50+ 3″ screws
  • 4 appliance moving wheels
  • 12 pulleys
  • 45 feet of rope.

2013-05-05 20.19.25 2013-05-04 11.55.31 2013-05-12 18.46.37

The XY table

CoreXYThe XY table moves the claw around the cube. I decided to use the CoreXY (Cartesian Motion Platform) to do the actual movement. It works but there are many problems with it that I have not resolved yet.

2013-05-19 19.56.56The biggest problems I am currently having is that the cables that I am using are slipping in the motor’s pulleys. I tried using some sandpaper to rough up the pulleys to add more grip but they keep slipping.

2013-05-19 20.06.54

I thought about adding a idler pulley but I wanted to keep everything as simple as possible and I decided to add expansion springs to the cables to keep the tension on the motor pulleys. Its still slipping.

The problem also could be with the cables I am using. If the cables are too slick they will slide around in the pulleys, if the cable has too much give they will stretch under constant use. I had some parachute cord (paracord) around my house and decided to use it and this might be adding to my slipping.

Another idea is to wrap the cable around the pulley twice (540 degrees). This would ensure that there is tension on the pulley but the cable might get knotted up.

I have not resolved this problem yet and I am looking for a solution.

2013-05-19 19.57.03 2013-05-19 19.56.26 220px-Paracord-Commercial-Type-III-Coil

The Cart

I have not started this yet.

cartThe cart will ride along the center column being pulled across by the cables. The card will have its own pulley on it that will be used to raise and lower the claw. Here is a crude drawing of what I was thinking about doing.

There will be one large pulley that will rise and lower the main claw. this pulley will be at the bottom attached at the center to a dowel that is free rotating in the walls of the cart… kind of hard to explain.

Control system

I am using a relay H Bridge to control the motors. Each motor needs two relays and two pins on the Arduino. There are a total of 4 motors in this system (8 pins). One each for each of the axis X, Y, Z and one more to open and close the claw.

I also used a lot of limit switches to tell when the claw is in a certain state.

  • 4x for each axis on the gantry,
  • 4x for each directions in the joystick,
  • 1x for the fire button on the joystick,
  • 2x for the min and max of the claw’s teeth,
  • 1x for the pulley to know when the call is fully retracted in to the cart.

A total of 20 pins. An standard Arduino has 20 pins, just enough to control the claw. I am trying to make all the connections with RJ45 connectors for an easier set up.

The programming for the Ardunio is nice and easy and pretty much done already.

8 relays  cherry switch  2013-05-19 22.32.56

 

Still lots to do and not much time to do it.

Breaker Faire – May 25th 10am-5pm

Like to BREAK things? Visit the Vancouver Community Laboratory for your chance to smash a car! For just a few dollars, you can take part in a scrumptious pancake BREAK-fast, WRECK a car, have your mind BLOWN by local art / creations, and PLAY a giant claw game! Wreckage form the car will be used by local artists for materials, and all proceeds benefit the Vancouver Mini Maker Faire.

All ages. Entrance by donation.
Saturday, May 25, 10 am – 5 pm
1907 Triumph St.

Click here for information & updates via Facebook

More information at Vancouver Maker Faire

The Giant Claw Game! – Relay H-Bridge and Circuit Design

Over the week I worked on the Relay H Bridge,  software and circuit diagrams for this project. Only 1 more week till it needs to be done.

Relay H Bridge 

After finding out that my L298 H Bridge was not powerful enough to operate my gantry motors last week, I switched over to use a Relay H Bridge. The advantages of using a relay instead of the L298 is that the relay can take a lot more current but the switching frequency is much slower (~40 hz)

IN1 (IN3) IN2 (IN4) DIRECTION
1 0 Forward
0 1 Reverse
1 1 Motor stop
0 0 Motor stop

Relay H Bridge

Image source: http://nvhs.wordpress.com/project/catspberry/motor-controller/

Circuit Design

I don’t have much experience with circuit design but I think this makes sense. I built it with circuitlab.com and online circuit designer.

 big-claw-game circuit

 

Arduino Software

The code for the Arduino is pretty strait forward. Move the claw around until the fire button is pressed, then drop the claw and pick up a toy and bring it back to the start location. The source code for the The Giant Claw Game can be found on my GitHub account.

 

 

 

 

The Giant Claw Game! – The Controls System

Only two weeks left to get the Claw up and running ready for Breaker Faire the Maker Faire fund raiser party. I am starting to get worried that I might not get it done in time.

I have been having lots of problems this week with getting the motors working with the gantry system.

  • The motors are from different vendors and move at different rates.
  • The motors draw too much current for the motor shield to handle.
  • The motors are hard to mount on the cube.
  • The pulley for motors slips and I am unable to get them to move the cables.

3 drill motorsThe motors come from old power drills that I picked up at a local flea market (Binners market). You can pick up some pretty amazing things at this market when you look hard enough. I purchased 5 battery powered drills for $5 each, 4 of them worked.  The picture shows three of the motors taken apart with the supply voltage taped to the motors. Drill are great for finding cheap motors with a gear box and a chuck. A retail motor with a gear box would probably cost me in the range of ~$30 each. The problem with getting second hand motors is that I couldn’t get all of the same type of motor. Luckily, of the four working drills two of them have relativity similar gear ratios and power requirements. Even still the minor differences between these two motors will probably cause me problems after a few hours. I think I can resolve the difference by providing different voltage to each of the motors, its not ideal but it should work.

l298I purchased two L298 Dual H-Bridge Motor Driver from leeselectronic.com. They work great and are easy to interface with, but they have a 2 amp max current limit. After experimenting with the motors I have I found that they require 1.5 Amp to starting current and probably need around 6 Amps to move the gantry around properly. Way too much current for these motor shields.

Motor controller

After doing some more research and asking a few questions online I decided to build a relay version of a H Bridge instead. The advantage of using a relay is that it can take a lot more current +10 Amps but its switching frequency is much lower (~40 hz) and it costs quite a bit more ($5-10 per relay).

I designed this circuit in circuit lab (online social circuit building tool). I am planning on picking up the parts and building it tomorrow. Hopefully this will resolve the motor current problem I was having.

motor mount The next problem was how to mount the motors on to the cube. I wanted to use a hole saw and cut a circle in to a 2×4 and then attach the 2×4 to the cube. But I didn’t have a hole saw so I ended up using a jig saw and a drill. The results worked but didn’t look pretty. I might end up redoing this work if I can find a friend with a hole saw.

I also have to figure out a way of making pulleys for the motors that can pull the cabling and move the XY table. Normally I would have used a timing belt instead of cables. The rubber teeth inside the belt would have added the grip on the pulleys that I needed. But timing belts are really expensive. The two belts that I would have needed for this project would have easily cost me more then the entire project has so far. Still trying to figure this one out.

Still lots to do but things are coming along.

The Giant Claw Game! – The Gantry System

This week I have working on the gantry system. The gantry system is used to move the claw around inside the Cube.

Skycam I was originally planing on attaching the claw to 4 cables running to pulleys in each of the corners of the cube. The cables would be attached to four electric motors. Just like the sky cam that you can some time see at stadium.

2013-05-05 20.19.34I ended up not using the sky cam and going with a more traditional XY table. With a sky cam I would have had to have four matching electrical motors in each corner. To move the sky cam North/East/South/West you need to move all 4 motors in sequence making it more complex of a system.

CoreXYI decided to use the CoreXY system for the claw’s XY table. Its a brilliant simple system that uses cables with only two motors instead the normal 4 motors. The system does need 8 pulleys two work. Rotating both motors in the same direction results in horizontal motion. Rotating both motors in opposite directions results in vertical motion.

I added a shelf on the top north and south sides of the cube. The shelf will carry the X axis (blue)  up and down along the Y axis (red) giving the system its vertical motion. In the first picture you can see the wheels and the X axis bar.

Y axis  Top of the Cube Claw with a toy

I added the wheels to the X axis bar, installed the 8 pulleys and ran cabling thought the system. Using my fingers I pulled the cables back and forth to move the XY stage around. Everything worked!

Next I am going to add the motors to the gantry system and get everything moving around.

The Giant Claw Game! – The Claw, Prototype 3

I started working on the third version of the claw this week. In this version I have added a motor, extended the length of the prongs, and started on the electronics.

Direct drive with home made shaft coupler At first I tried using a direct drive electric motor that I found at VHS. I constructed my own shaft coupler out of sheet metal and hotglue. It worked but it had no guts. As soon as the smallest amount of force was applied to the claw it would stop moving.

Gear motorNext I upgraded to a small geared motor, 12v 36x gear, 100RPM motor.  This motor could easily crush a play pen ball in the claws. It had a ton of torque but it was slow. It took upwards of 30 secs or more to close the claw from its fully open state. I also found a local supplier of shaft couplers that made attaching the motor shaft to the screw much easier.

Claw's extended prongsI extended the length of the prongs to speed up the time it took to close the claw from an fully open state. I was able to reduce the time from 30 secs to around 22 secs. It took me many iterations to find the optional length for the base plates that I have. Still took long.

Limit switchesI changed focus and started working on the limit switches. These switches are used to tell when the claw is fully opened or fully closed. It took a while and a bunch of configurations before I found one that worked.  I added a terminal strip for cable management to try to keep things organized.

I also built the wooden frame “The cube”. I added trusses to the frame to reduce the wobble. Its a cube, not much to say about it.

The cube

I am planning on working on the XY table tomorrow. The XY table is used to move the claw around the cube in 2D space.

The Giant Claw Game! – The Claw, Prototype 2

claw prototype 2This is the second prototype of the claw. I really liked the claw design by Marc Cryan that I found on Instructables.com but I wanted it to have three prongs instead of two. I did this prototype out of cardboard using trial and error to get the right size for each part.

I tried doing the math to get the right ratios between each sections, but it was harder then I would have thought. I ended up taking the cardboard prototype apart and measuring each sections. Not the best way of doing it but it worked.

claw2This version is made out of wood and brass hinges. I cut it with a ban-saw as VHS’s laser was down for repairs  It can picks up balls most of the time on the first try and holds them even when swing the claw around. I think its going to work great.

Next I am going to attach a motor to the claw so that it can be automated.

Claw 3 Claw 4 2013-04-16 23.24.40 2013-04-16 23.22.40

Using a Raspberry PI with a webcam to make time lapse videos.

64807I have made a bunch of time lapse videos in the past with my Cannon S90 using the CHDK hacked firmware. These videos turn out great and I have very happy with the results. The problem is that I have to leave my expensive camera unattended for hours or days at a time and I am unable to use the camera while it is in use.

A few weeks ago I found a few cheap HD webcams (HP HD-3110 Autofocus 720p 30FPS Widescreen Webcam) on NCIX. These Webcams work with the Raspberry PI and consumes a less power then other webcams I have tested in the past.

I wrote up a little bash script that uses fswebcam to take a picture once every 10 secs and store it on the local disk (SD Card).

Instructions 

  1. Connect to your Raspberry PI via SSH terminal
  2. Update your Raspberry PI
    sudo apt-get update 
  3. Install fswebcam
    sudo apt-get install fswebcam
  4. Test fswebcam. This should take an image from the webcam and store it in your local directory.
    fswebcam -d /dev/video0 -l 10 test-fswebcam.jpeg
  5. Write a script for fswebcam and automate
    1. Open up a terminal text editor such as nano
      sudo nano timelapse.sh
    2. In the nano editor type the follow script
      #!/bin/bash
      fswebcam -d /dev/video0 -l 10 test-%Y-%m-%d--%H-%M-%S.jpeg
    3. Use [ctrl]+[x] to save and close this file.
  6. Change the scripts permissions to allow for execution
    chmod +x timelapse.sh
  7. Run the script
    ./timelapse.sh

The Giant Claw Game! – The Claw Research, Version 1

Now that I got my controller working and the stepper motors moving with a RAMPs board, I decided to get started on The Claw. I knew that I would have to go thought a bunch of iterations of the claw before getting one that I liked so I wanted to start early.

I knew I wanted a 3 pronged claw to make it easier to pick up the balloons. I need it to be as light as possible so that the motors could lift it. If it had to have some electronics in the claw its self then I wanted them to be as simple as possible.

I made a mistake here and rushed off and made it out of cardboard. I didn’t think this design thought fully and I just wanted to get something done in a night.

The first version was made out of cardboard and only had two prongs (grippers). I did this to make it simple (it was a prototype after all). It worked but not very well. I told myself that it was because it was made out of cardboard instead of wood. I quickly designed a three pronged version in inkscape, took it down to VHS and laser cut it.

Cardboard claw Wooden claw

Both of these where failures and I quickly abandoned them. Haste makes waste.

I slept on it and instead decided to do some researcher before I designed my next version.

  • 3 prong clawThe Claw by AntMan232 on instructables.com. – I like how this design attached the prongs (grippers) to the bottom plate. Its simple and it doesn’t require the use of ball bearings. I didn’t like how it uses springs to normally keep the prongs apart and a servo as a pulley to pull them together.
  • Motorized K’nex Claw by T86157 on instructables.com - I briefly considered making it out knex. They are light, I have a huge box of them and I could make many proto types in a single night. I decided against it as it doesn’t have that home made touch that I was looking for.
  • Robotic Claw – MKII from sparkfun.com - I also considered buying a claw. There are several different versions out there and it would have made my life a lot easier. But it just didn’t feel right for this project, I wanted to do it all from scratch.
  • Screw 2 prong claw CRANE GAME by marc.cryan on instructables.com - I really liked the overall simplicity of this one. It may look ugly as can be but its simple and works. It uses a motor attach to a metal screw with the end of the screw in a bolt. When the motor is activated the screw turns in to the bolt pulling up the platform. The video does a much better job of visualizing it then I do of describing it.

More research is needed… 52 days left !

Reporting the system stats of a Raspberry PI to COSM with python

COSM is a online data store of sensor data for the internet of things. You can use Cosm to store sensor data (light, temp, heat, etc…) from your internet enabled device (Arduino, Raspberry PI, etc) online and produce pretty graphs of the values as they change. Recently Chipkin Automation Systems (The company I work for) added COSM as one of the supported drivers on their CAS Gateway device.

This got me to thinking of how I could track system stats from my Raspberry PI with python and record the stats on COSM.

I have written about sending data to COSM with a Raspberry PI before in my Raspberry PI and the GPIO pins post.  Adafruit also has a great tutorial on this as well Send Raspberry Pi Data to COSM.

This code snippet will get the system stats (CPU, Ram, Disk Space) from the Raspberry PI, We can then send these values to COSM. I then added in the eeml class to talk to the COSM servers. I also added reading a light sensor that is connected to an Arduino talking pyfirmata.

Full source code can be found on my github account.

Light graph

 

 

 

Raspberry PI as a FM transmitter

pi_fm_gpio

A few weeks ago I found this tutorial on make magazine Turning the Raspberry Pi Into an FM Transmitter by Code Club pihack.

It uses the hardware on the raspberry pi that is actually meant to generate spread-spectrum clock signals on the GPIO pins to output FM Radio energy. This means that all you need to do to turn the Raspberry-Pi into a (ridiculously powerful) FM Transmitter is to plug in a wire as the antenna (as little as 20cm will do) into GPIO pin 4 and run the code posted below.

Instructions 

  1. SFTP the pifm.c and sound.wav files on to your Raspberry PI.
    • You will need to enable SHH to SFTP a file on your Raspberry PI
  2. From the SHH terminal window, compile the pifm.c for your distro of linux. By default gcc will produce a a.out file as the compiled program.
    gcc -lm -std=c99 pifm.c
  3. Run the output. You must run the application as an administrator (sudo) because this application uses direct memory management to access the GPIO pins.
    sudo ./a.out sound.wav

The Giant Claw Game! – Controller

Continuing from my last post on The Giant Claw Game! This week I build the controller for the Giant Claw using the laser cutter, a arcade joystick and a button.

messing wiring

The box was cut with VHS’s laser cutter, using a pattern that I created with this laser cutting box making tool. I purchased the joystick and button from a local arcade suppler John’s Jukes for $14.

The wiring was the hardest part of this part of the project, taking about an hour. 5 cherry switches with 3 connections each, for a total of 15 wires. I wanted to use a RJ45 connector to make set up easier.

 

 

The Giant Claw Game! – Vancouver Maker Faire 2013 project

mario-claw-gameThis year for the Vancouver Maker Faire I am planning on making a giant Claw Crane game.  Normally claw games are found in video arcades and shopping malls and are a glass box where players can control a crane with a joystick and attempt to pick up prizes from the playing area. They are also known as teddy picker, candy crane, claw machine, crane vending machine, arcade claw, grab machine, crane game, skill tester, or simply the claw.

As seen in Toy Story, The Claw. These games aren’t as populate as they use to be in north america anymore but have exploded in Asia and Japan. You can even play for lobsters Sub Marine Catcher

The claw machines are made up of a 2-4 prong claw, XY table, A controller, and a box for the play area.

Before I started on this project I looked to see if anyone else had done anything similar that I could lean from.

Claw-Game-Model-300x270

I found Mega Claw! created for the 2010 NY Maker Faire. Its the exact same idea that I was planning on doing, with a different approach to the XY table. They have written up a great article on their progress and a post mortem after the event. Very impressed project.

Their Mega claw uses a more traditional rail based XY table and the playing area is limited to the max size of the rails that they are using. My system is more like a skycam/skycrane and can be expanded to a very large playing area only limited by the size of the motors that you use for the winches.

Next I found a skycam project (featured on hackaday) created by Dan Royer from Marginally Clever and a fellow member of Vancouver Hackspace (VHS). His Skycam is based on two DrawBots working in tandem. I like his system a lot and since he is so close I plan on talking to him a lot more about his project.

I plan to spend this week working on the design and making a few prototype, probably out of Knex.

RaspberryPI – Find the MAC address and change the host name

Raspi-PGB001We have been running Raspbberry PI nights at VHS the last few weeks and they have been going really well.

We are running the Raspberry PIs headless (no keyboard or mouse, using SSH) because VHS only has one device capable of being used as a display (out projector) and asking people to bring in their monitors as well as their Raspberry PIs would be bothersome.

To run the Raspberry PI headless, we need to enable SSH and know the IP address of the Raspberry PI. Some distros like the Occidentalis come with SSH enabled by default. If your distro does not have SHH enabled you can follow these instructions to enable it Adafruits Raspberry PI Lesson 6 Using SSH

When people arrive they connect their Raspberry PIs to our network and DHCP an IP address from our router. The problem is that by default all the Raspberry PIs have the same hostname and its very hard to determine what Raspberry PI has what IP address.

If you know the MAC address of your Raspberry PI it makes it a lot easier to look up the MAC address in the router IP address tables. Or better yet change the Hostname of your Raspberry PI.

How to find the MAC address of your Raspberry PI/Linux Box

The MAC address is very useful for finding the IP address of your Raspberry PI if there are other Raspberry PIs on your network with the same Hostname. I would suggest writing this on your Raspberry PI case.

ifconfig -a | grep HWaddr

This will display a list of MAC address of your network devices currently installed on your system. Eth0′s MAC address should be prefixed with B8:27:EB.

eth0 Link encap:Ethernet HWaddr b8:27:eb:a1:b2:c3

In this example the MAC address is B8-27-EB-A1-B2-C3

How to change the Host Name of your Raspberry PI/Linux box 

A host name makes it easy to find the device on your network when you do not know the IP address of your Raspberry PI.

sudo nano /etc/hostname (and enter the desired name, “CTRL+X” then “Y” to quit) 
sudo nano /etc/hosts and replace raspberry with the hostname you chose above
sudo /etc/init.d/hostname.sh start (to enable the changes).

Instead of typing the IP address of your Rapsberry PI you can use the host name to connect to your device.

Space ship mobile

One of my good friends just had a child and I wanted to get them a hand made gift. I decided on making a mobile with VHS’s laser cutter.

The first version I designed while at VHS one night.

mobile 2013-02-20 00.39.05

I changed a few things in Version two. I added more rings, designed in holes for the strings  instead of doing it manually drilling them afterwards, I also painted the rings as well.

mobile_v22013-02-22 16.43.05

For the next version I think I am going to put the death star in the center and use starwars  icons.

Raspberry PI controlling an Arduino via the pyfirmata protocol

The Raspberry PI is good for a lot of things from computer clusters to home automation but its missing a few things such as a real time clock, terminal/barrel power connector, or  Analog pins.  The Arduino has analog pins that can be read by the USB virtual serial port from the Raspberry PI.

2013-02-10 21.31.34

In MagPI issue 7, has a great article on using the firmata protocol to communicate between   Arduino and the Raspberry PI.

Requirements

Install and setup 

  1. Enable SSH on the Raspberry PI
  2. Install Adafruit Learning System Raspberry Pi WebIDE
  3. Get the required packages:
    sudo apt-get install python-serial mercurial
  4. Install pyFirmata
    sudo apt-get install python-serial mercurial
    hg clone https://bitbucket.org/tino/pyfirmata
    cd pyfirmata
    sudo python setup.py install
    cd .. ; sudo rm -r pyfirmata

Source code 

Read analog pin 1

import pyfirmata

# Create a new board, specifying serial port
board = pyfirmata.Arduino('/dev/ttyACM0')

# start an iterator thread so that serial buffer doesn't overflow
it = pyfirmata.util.Iterator(board)
it.start()

# set up pins
pin0=board.get_pin('a:0:i')             # A0 Input      (LM35)
pin3=board.get_pin('d:3:p')             # D3 PWM Output (LED)

# IMPORTANT! discard first reads until A0 gets something valid
while pin0.read() is None:
    pass

while True : 
  print "PWM: " + str( pin0.read() ) 
	board.pass_time(1)                  # pause 1 second

board.exit() 

Raspberry PI and the GPIO pins

This week I have been playing with the Rapberry PIPython and the Python GPIO pins library.

Software

WebIDE

I started by formatting a SD Card with the Raspbian “wheezy” (2012-12-16) image from Raspberry PI’s website. I followed this tutorial on how to set up the Raspberry PI for the first time.

I then enabled SSH so I don’t have to attache a monitor, keyboard or mouse to the Raspberry PI. Since my main box is a Windows machine I downloaded and installed PuTTY to use as my SSH client.

Once I was connected to the RPI via SSH, I updated the OS and all of its packages to the latest versions, by running the following command.

sudo apt-get update

Note:  This command may take a long time to complete depending on how out of date your system is. 

Next I installed the Raspberry Pi WebIDE from adafruit.com. The Web IDE allows you to create Python programs from your webbrowser directly on the Raspberry PI. The WebIDE has a few nice features like a debugger and visualizer and auto version control via bitbucket.

I also installed the “easy_install“, “python-pip“ and “EEML – markup language” and other python packages that I wanted to use.

$ sudo easy_install -U distribute
$ sudo apt-get install python-pip
$ wget -O geekman-python-eeml.tar.gz https://github.com/geekman/python-eeml/tarball/master
$ tar zxvf geekman-python-eeml.tar.gz
$ cd geekman-python-eeml*
$ sudo python setup.py install

Hardware 

Home made Raspberry PI GPIO ribbon cableThe Raspberry PI has a 26pin mail connector that connects to its GPIO pins. These ribbon cables and breakout boards can be found on adafruit.com ($2.95) and Sparkfun ($2.95)

You can also make your own. Hardware lesson with Gert: make your own ribbon cable connector.

Vancouver Hackspace (VHS) just happen to have a bunch of the 26 pin press connector and I was able to make a few cables.

 Source code 

Since I am using bitbucket all my source code is public. I created a few learning scripts to understand how the GPIO pins work on the Raspberry PI. The first script I made was a simple blinking LED, just like the arduino blinking LED script. Next was to read the current state of a switch and print the results to the screen.

This image was tremendously helpful in figuring out what pins go whereRaspberry-Pi-GPIO-Layout-Revision-1-e1347664808358

Next I followed Send Raspberry Pi Data to COSM from adafruit.com. I changed the tutorial  to read a digital pin (as the Raspberry PI does not have any analog pins) that I connected to a magnetic read switch for my front door.

0

 

The GPIO pins on the Raspberry PI are pretty easy to use with the python libary. Its too bad there are no analog pins. I can add AtoD converters or interface the Raspberry PI with an Arduino to add some analog pins.

More to come.