Saturday, November 24, 2012

RasPi Robot Remote - i2c Software Setup

Assuming you've already got your Raspberry Pi wired to your Adafruit 16 Channel Servo Controller here's how you get them to talk to each other.

First I followed Adafruit's instructions I found here:
http://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi

There's another good site for configuring Pi for I2C communications here:

My RasPi is running Raspbian OS so here's my summary of the steps I took:
Connect the RasPi to the Servo Controller, then at a RasPi command line:
sudo apt-get install python-smbus
sudo apt-get install libi2c-dev
sudo modprobe i2c-dev
lsmod
sudo modprobe i2c-bcm2708
sudo i2cdetect –y 1 (this will show a device at address 40 if the servo controller is connected)

edit “/etc/modules” file and add the line i2c-bcm2708 and the line i2c-dev
sudo adduser pi i2c    

NOTE: after this you should not need to run i2c commands with sudo

After a sudo reboot running sudo i2cdetect –y 1 should still show device at addr 40 if all is OK

Install git if not already installed: sudo apt-get install git

make sure you are in the /home/pi folder then:
cd Adafruit-Raspberry-Pi-Python-Code

edit /home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver/Adafruit_I2C.py and change SMBus(0) in line 11 to SMBus(1) because the 2nd gen RasPi is on bus address 1.

To test your RasPi+ServoController+Servo do the following at a command line:
cd ../home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_PWM_Servo_Driver
sudo python Servo_Example.py

Your servo should start moving back and forth.  Press CTRL+C to stop the program.

NEXT UP... Setting up the web server

Friday, November 23, 2012

RasPi Robot Remote - Connecting the Servo Controller


Earlier this week my Raspberry Pi and Adafruit 16 Channel Servo Controller arrived and here's how I wired  them up:

First you need to figure out your power sources.  The RasPi, the servo controller and the servos can all run off of 5vdc. However servos can be very power hungry.  I've measured standard servos pulling upwards of 300ma under load.  That means if you had the full complement of 16 servos connected to a single controller you could be pulling upwards of (16x.300 =) 4.8 AMPS from the servo power supply.  Also because they are motors, servos can induce interference into the power supply they are connected to.  It is strongly suggested that you use a separate 5vdc power supply just for your servos.  This is why the servo controller has a separate power connector (the blue one with two screw terminals) to power the servos.  This connector doesn't power the servo controller, only the servos themselves.

You may be able to get by with running one servo off the RasPi's 5v line just for testing, but anything more than that and you could pop the fuse on the RasPi.  I strongly suggest using a separate 5vdc power supply for the servos.

For this robot project we are going to have at least three servo controllers connected to one Raspberry Pi.  In Adafruit's instructions they use the RasPi's 3.3v connection to power the servo controller.  This is fine for connecting one servo controller, however multiple controllers could draw too much current from the RasPi.    The datasheet for the PCA9685 chip shows the current draw for the controller itself is 10ma max.  The RaspPi's 3.3vdc power supply only has about 50ma available, however the RasPi's 5vdc output has over 200ma available so I connected my controllers to the 5vdc connection on the RasPi's GPIO connector.

Here's the link for Adafruit's instructions for hooking up he servo controller:
http://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/hooking-it-up
IMPORTANT POINTS:
- VCC is the supply voltage for the Controller (you can use the 3.3v or 5v line from the RasPi)
- V+ is the supply voltage for the Servos (you should NOT connect the RasPi to V+)
- GND is common between all three components (RasPi, Controller, Servo(s))
- Be VERY CAREFUL to plug your servo into the controller correctly with the BLACK wire to GND.

NEXT UP... Making the Raspberry Pi talk to the Servo Controller using i2C


Saturday, November 17, 2012

RasPi Robot Remote - Raspberry Pi Initial Setup

My Raspberry Pi Model B arrived and it is tiny.  You really don't get from the photos how small this computer is and to think it has more memory and is faster than a full blown PC from just a few years ago.

First-things-first.  I didn't purchase a pre-loaded SD card so I had to install the Linux image on an SD card myself.  This is not a difficult process and by doing it yourself you also learn how you can create your own backups of the SD card and save images for different uses.

I'm not going to re-invent the wheel.  I used these instructions to get my RasPi up and running:  http://www.engadget.com/2012/09/04/raspberry-pi-getting-started-guide-how-to/


NOTE: If installing the image on an SD card larger than 2GB you’ll want to use "expand_RootFS” in the Raspi-config page to increase the partition on the SD card to fill the SD card.

Once you're up and running at a command line you can start the Desktop GUI with: startx   
NOTE: This can be set as default in Raspi-config.

Then configure the WiFi adapter with WiFi Config icon on desktop.

Success!!!!

Don’t forget to use sudo halt to shutdown or sudo reset to reset.  
Don’t just disconnect power to your RasPi or you could corrupt the operating system.

More to come...

Wednesday, November 7, 2012

RasPi Robot Remote - i2C & Interfacing Servos

As mentioned before, my friend's astromech droid is going to have a large number of servos and actuators.  In fact many more than could be easily directly connected to the GPIO interface of the Raspberry Pi.  Another downside to using the GPIO interface directly is that it is not buffered.  Unless one is extremely careful when connecting components to the GPIO, the Raspberry Pi can be easily fried and Fried Pi in this case doesn't sound very appetizing.

Luckily the folks over at AdaFruit.com have an excellent solution with the Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface http://www.adafruit.com/products/815


This very small servo controller is based on a PWM LED driver, but it also works great as a servo controller or other output driver and can directly drive up to 16 devices.  The I2C interface means that only 3 wires are required to connect it to the RasPi and up to 62 (yes SIXTY-TWO) of these controllers can be chained together providing up to 992 outputs.  That should be about 20x what is needed for my friend's droid.

I'm ordering one of these to test with and I'll let you know the results when I get it.

More to come...

Thursday, October 25, 2012

RasPi Robot Remote - Javascript & Touch in iOS

Matt's articles on using Javascript with Touch on the iPhone (and iPad) have been very helpful.  You can find them here.  http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/

Sunday, October 21, 2012

RasPi Robot Remote - Apache/Python/CGI

Well I've ordered my Raspberry Pi Model B from MCM Electronics.  Until that arrives I figure I'll install Apache Web Server and Python on my Windows laptop and try some coding to see what I can come up with.  Both Apache & Python were selected because they run natively on the Raspberry Pi so I'm assuming any code I write on my laptop I can run on the RaspPi when it gets here.

The general concept is to use a USB WiFi adapter on the RasPi and configure it as an access point so the iPad can connect directly to it over WiFi.  The Apache Web Server on the RasPi will serve up a web page to the iPad.  Buttons on the web page will execute CGI scripts written in Python to control devices connected to the GPIO port of the RasPi.

More to come...

Friday, October 19, 2012

RasPi Robot Remote - Concept

Recently a friend of mine decided he was going to build a full scale Astromech Droid in the style of R2-D2.  Being an artist and not having much experience with electronics or robotics he asked me to help with the technical bits.

The first thing we looked into was how to control the robot. Perusing Astromech.net showed that most builders use multi-channel radio remote controls and then add on  custom multi-button controllers to control the dozens of lights, panels and other devices on your average Droid.  One of the problems with this is that an 18-channel radio alone can cost upwards of $3,000 so I started looking into alternatives.

I had recently read about the Raspberry Pi all-in-one computer for $35.  This small (around 2"x3") computer is a full-blown linux box (see this FAQ for details).  This means it can run a web server.  Also, my friend already owns an iPad.

So, the idea is to build a web-based, touch screen remote control using a Raspberry Pi and an iPad.

More to come...