Friday, April 18, 2014

pan / tilt unit for pi

This can be done with different servos, etc, from scratch, but this is a nice unit to have as a starting point.

lifted from the following blog entry:

Using the Dagu Pan/Tilt Kit with the Raspberry Pi

The Pan/Tilt kit that we sell, developed by Dagu with the guys over at Let’s Make Robots, is a great way to mount mobile sensors on your robotic projects. In this tutorial we look at how you can control the Pan/Tilt kit with a Raspberry Pi and the Python programming language.

Required Materials and Equipment


In order to control the servos of the pan/tilt kit with the Pi, we need to provide the servos with power, and connect their signal lines to GPIO pins on the Pi. Nearly all RC servos have the same wiring layout, although the colours may vary slightly. On the pan/tilt servos, the red (middle) wire is Vcc, the brown wire is Ground and the orange wire is the signal wire.
Connect the servos to the Pi as shown in the circuit diagram below. To begin with, we’d recommend that you get the servos working before you fully assemble the Pan/Tilt kit, as this way you can work out where the centre points of the servos are.
Circuit Diagram
Circuit Diagram – Made using Fritzing
External Servo Power
External Servo Power – Diagram made using Fritzing
As the the servos in the Dagu pan/tilt kit don’t require much current, we can power them from the 5V line of the Pi. If you’d prefer to power them from another power supply, or if you’re using different servos that require more current, or a higher voltage, then you can modify the circuit, as shown in this image.

Understanding Servo Motors

Unlike standard DC electric motors, which turn continuously at a given speed, servo motors contain control circuitry which is constantly trying to drive the servo motor to a set angle. Most servo motors are given their target angle by sending a Pulse Width Modulated (PWM) signal along their signal wire. A PWM signal consists of a pulse that repeats at a fixed frequency (usually close to 50Hz for a servo motor), the width of the pulse determines the angle that that we want the servo to move to.
Most servos will be centred with a pulse width of approximately 1500μs, and then turn left or right with smaller or bigger pulse widths. The minimum and maximum allowable pulse widths vary from servo to servo but are usually close to 800μs and 2200μs respectively. You should avoid trying to move a servo beyond its minimum and maximum limits, as this can damage the servo.

Controlling the Pan/Tilt Kit with Python

Once you’ve assembled the circuit, you can control the servos using this Python script. This script requires the RPIO Python library, which can be installed with the following steps
sudo apt-get install python-dev python-pip
sudo pip install RPIO
To use the script run
sudo python
The script will then sit in a loop, waiting for one of 3 commands. A ‘p’ will move the pan servo, ‘t’ will move the tilt servo, and ‘e’ will run an exploration animation, scanning the pan/tilt head back and forth. You can specify either an angle in degrees, or a pulse width in μs for the ‘p’ and ‘t’ commands by putting a number straight after them (no space). The program treats any number less than 500 as an angle in degrees, and all other numbers and a pulse width. As an example
: p90 - Will move the pan servo to 90 degrees
: p2000 - Will set the pan servo's pulse width to 2000μs
: t50 - Will set the tilt servo to 50 degrees
: e - Will the start the exploration animation
The script is a bit too long to explain in detail, but the important bit occurs on lines 144 to 151
# Create ServoPWM instances to control the servos
panServoPWM = ServoPWM( PAN_PWM_PIN,
    minAnglePulseWidthPair=( 45.0, 1850 ),
    midAnglePulseWidthPair=( 90.0, 1400 ),
    maxAnglePulseWidthPair=( 135.0, 1000.0 ) )
tiltServoPWM = ServoPWM( TILT_PWM_PIN,
    minAnglePulseWidthPair=( 45.0, 1850 ),
    midAnglePulseWidthPair=( 90.0, 1500 ),
    maxAnglePulseWidthPair=( 180.0, 500.0 ) )
This allows you to specify 3 ( angle, pulse width ) pairs for each servo, that tell the script which pulse width corresponds to each angle. The script can then work out the pulse widths to use for other angles by using linear interpolation. The precise pulse widths will vary from servo to servo, so you should experiment with different pulse widths to get your servos turning accurately, and then adjust the ( angle, pulse width ) pairs accordingly.
Once you have your servo motors turning accurately, you can then finish assembling your pan/tilt kit. This approach takes much less time than hurriedly assembling the pan/tilt kit when you first get it, and then having to take it apart again to get it moving accurately, which was our initial approach. :)
In order to hold our pan/tilt kit steady as it moved, we mounted the complete circuit onto a bit of foamboard.
Assembled Circuit
Assembled Circuit

Taking Things Further

Pan/Tilt Kit with Camera
With the pan/tilt kit up and running, you can now mount sensors on it, and give them a much wider field of view than they would have if they were just mounted statically. The obvious sensor to mount for the Raspberry Pi is the camera, and we’ll hopefully have a look at using the camera with the pan/tilt kit in a future post.

Thursday, April 17, 2014

Two interesting bits to look at, omxplayer and fm transmission direct from clocks on Pi board

The Pi board can be set up to do FM broadcasts and an example is here:

Another article mentioned a media player that can be used when on the Pi in text mode, omxplayer

Also here is essentially an Arduino Uno which lives on the top of a Pi GPIO.

board purchase / support site is here:

£16.99, obviously from UK.

Friday, April 4, 2014

Raspberry pi i2c and spi bus notes

I ran across some notes about using i2c with the pi.  For my version, debian_version 7.0, Wheezy this page describes how to enable the access to the controller and install a simple program to access the ic chip

BC2708 it would appear.

This example is for a board which adapts arduino shields to the Pi, so you will get nowhere if not using a board with the chip attached.

1. Install i2c-tools on your Pi:
sudo apt-get install python-smbus
sudo apt-get install i2c-tools

2. If you have Raspbian, check /etc/modprobe.d/raspi-blacklist.conf and comment "blacklist i2c-bcm2708" by running sudo nano /etc/modprobe.d/raspi-blacklist.conf and adding a # (if its not there).
If you're running Wheezy you will need to
add the following lines to /etc/modules file

3. Run i2cdetect (You need to specify the i2c bus where the ADC is attached, there are different for Rev1 and Rev2). THE BRIDGE MUST BE ATTACHED TO YOUR RASPBERRY PI.
# For Raspberry Pi rev2
sudo i2cdetect -y 1

#For Raspberry Pi rev1
sudo i2cdetect -y 2