API's for Pan & Tilt


For Pan and/or Tilt movement, following API's are provided by Pi-Pan library:

 

do_tilt(y)

Tilt the Pi-Pan head to 'y' position.

Parameters:

    y: the tilt position of Pi-Pan ranging from 80 to 220, where

  • 80 = looking down
  • 220 = looking up
  • 150 = straight ahead (neutral position)

 

do_pan(x)

Pan the Pi-Pan head to 'x' position.

Parameters:

    x: the Pan position of Pi-Pan ranging from 50 to 250, where,

  • 50 = looking left
  • 250 = looking right
  • 150 = straight ahead (neutral position)

 

neutral_pan(x)

Bring the Pi-Pan head to neutral Pan position (straight ahead).

 

neutral_tilt(x)

Bring the Pi-Pan head to neutral tilt position (straight ahead).

 

Advanced Servo Movement API's


Pi-Pan Servo Controller board can control upto 6 servos. The servo pins are marked with S0 to S5. Depending on your product configuration, some pin headers may not be populated. If you need to extend the board functionality, solder standard (0.1 inch pitch) header pins on the board.

 

pwm(pin, position)

Parameters:

  •     pin: pin number for the desired servo. Provide the pin where the servo is attached (S0 to S5)
  •     position: desired destination position for the servo attached to this pin. Range of values: 50 to 250

 

API for Pi-Light

Pi-Light can be turned on (or off) with any combination of three basic colors (Red, Green and Blue).
Turning it on with all three colors in equal intensity will get you White light.
To turn off, set all color values to zero.

 

createPiLight(red,green,blue)

Parameters:

  •     red: Integer value for Red color (0-255)
  •     green: Integer value for Green color (0-255)
  •     blue: Integer value for Blue color (0-255)

 

Sample Program For Pi-Pan


Program below moves the Pi-Pan head up/down in a while loop.

 

import time
import os, sys
import pipan

p = pipan.PiPan()
x = 150

while 1:
    # move head down
    while x < 180:
        p.do_tilt (int(x))
        time.sleep(0.1)
        x += 2

    # move head up
    while x > 90:
        p.do_tilt (int(x))
        time.sleep(0.1)
        x -= 2

 

Sample program for Pi-Light


Program below turns Pi-Light on with White color, and then changes to basic colors at 1 second intervals, and then switches off.

 

import time
import os, sys
import pilight

pl = pilight.PILIGHT()

pl.createPiLight(255,255,255)
time.sleep(1)

pl.createPiLight(255, 0, 0)
time.sleep(1)

pl.createPiLight(0, 255, 0)
time.sleep(1)

pl.createPiLight(0, 0, 255)
time.sleep(1)

pl.createPiLight(255,255,255)
time.sleep(1)

pl.createPiLight(0, 0, 0)

 

How to take pictures with Pi-Camera


There are several API's and programs to take pictures using Pi Camera.
To take picture with Pi-Pan 'raspistill' program is used, as follows:

 

# take the picture and save as test.jpg in /var/tmp folder.
subprocess.call(["raspistill", "-o", "/var/tmp/test.jpg", "-rot", "180"])


For more info on taking pictures with Pi Camera Module, visit Matt's page at:
http://www.raspberrypi-spy.co.uk/2013/05/taking-hi-res-photos-with-the-pi-camera-module/