Waveshare Pan-Tilt HAT User manual

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 1/ 17
Pan-Tilt HAT
User Manual
OVERVIEW
This is a 2-DOF pan-tilt kit designed for Raspberry Pi. With onboard PCA9685 PWM
chip and TSL2581 ambient light sensor, it allows the Pi to control camera movement
and sense light intensity through I2C interface.
SPECIFICATION
Operating voltage:
3.3V/5V
PWM driver:
PCA9685
Working voltage:
3.3V
Interface:
I2C
Dimension:
56.6X65(mm)

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 2/ 17
CONTENT
Overview........................................................................................................................................................1
Specification ........................................................................................................................................1
Hardware.......................................................................................................................................................3
Controller..............................................................................................................................................3
Communication protocol................................................................................................................3
I2C Write data.............................................................................................................................3
I2C read data...............................................................................................................................4
I2C adress.....................................................................................................................................4
How to use ...................................................................................................................................................5
Download examples .........................................................................................................................5
Examples ...............................................................................................................................................6
Download examples to Raspberry Pi .................................................................................6
Install libraries.............................................................................................................................6
Assembly ......................................................................................................................................8
Servo and Light sensor.........................................................................................................10
Camera .......................................................................................................................................10
Web_Control ............................................................................................................................12
Expected result........................................................................................................................16
FAQ...............................................................................................................................................................17

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 3/ 17
HARDWARE
CONTROLLER
The PWN driver is PCA9685, an I2C-bus controlled 26-channel LED controller, 12-bit
resolution PWM output. Pan-Tilt HAT integrate TSL2581 on board. TSL2581 is a light
sensor, can be used to detect light and work with camera. TSL2581 use I2C interface as
well.
COMMUNICATION PROTOCOL
I2C-bus has one data line(SDA) and one clock line(SCL). When communicating, three
kinds of signals are product: Start signal, Stop signal and Answer signal.
Start signal: SCL is High, SDA changes from High to Low, start to transmit data
Stop signal: SCL is High, SDA changes from Low to High, stop transmitting
Answer signal: The receiver will answer a Low plus to sender after receiving 8-Bit data
as ACK.
I2C WRITE DATA

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 4/ 17
When working, Raspberry Pi (hereafter named as Master) will first send a Start signal,
then send a byte to TSL2581 (hereafter named as Slaver), whose first 7bits are address
of Slaver and 1 bit write bit. Slave response with Answer signal every time it receives
any data. Master send command register address to Slaver, then data of command
register. Stop signals is sent to slave to stop communicating.
I2C READ DATA
When working, Master will first send a Start signal, then send a byte to Slaver, whose
first 7bits are address of Slaver and 1 bit write bit. Slave response with Answer signal
every time it receives any data. Master send command register address to Slave. After
that, Mater will send a Start signal again, and then send a byte (7bits address and 1bit
read bit) to Slaver. Slaver response and send data of the register to Master, master
answer as well. Stop signals will be sent to stop communicating.
I2C ADRESS
I2C address of PCA9685:
I2C address of TSL2581:
PCA9685 Datasheet Page 7

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 5/ 17
Note: The default I2C address pins are set as A5=A4=A3=A2=A1=0, address is 0x40.
I2C address pins are set as Float and its I2C address is 0x39 by default. If you use the
module with other development board, please add R/W bit to Low bit
HOW TO USE
This part shows you how to use the module based on demo codes provided on wiki
DOWNLOAD EXAMPLES
Search with key word “Pan-Tilt HAT”on Waveshare Wiki, open the wiki page and
download examples:
Uncompressing the 7z, you can get files as below:
Servo Driver: Examples which test servos (BCM2835, WiringPi and Python)
Light Sensor: Ambient light sensing examples (BCM2835, WiringPi and Python)
test: test codes, used before assembling
web_Python: Remote control example
TSL2581 Datasheet Page 13

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 6/ 17
EXAMPLES
DOWNLOAD EXAMPLES TO RASPBERRY PI
You can download the demo code from wiki, uncompressing and copy to Raspberry
Pi, or directly clone it from github:
Open terminal of Raspberry Pi and download it:
git clone https://github.com/waveshare/Pan-Tilt-HAT
Change it execute permission and enter the folder:
sudo chmod 777 -R Pan-Tilt_HAT
cd Pan-Tilt_HAT
INSTALL LIBRARIES
To run the examples, you need to install related libraries first (wiringPi, bcm2835 and
python), otherwise, examples cannot work properly.
BCM2835 libraries:
http://www.airspayce.com/mikem/bcm2835/
Download the library from bcm2835 libraries and install:
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.58.tar.gz
sudo tar zxvf bcm2835-1.xx.tar.gz
cd bcm2835-1.xx
sudo ./configure
make

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 7/ 17
sudo make check
sudo make install
Note: The xx is the version number you download, for example, if the version you
download is bcm2835-1.52. then the command you should execute is sudo tar zxvf
bcm2835-1.52.tar.gz
wiringPi libraries:
sudo apt-get install git
sudo git clone git://git.drogon.net/wiringPi
cd wiringPi
sudo ./build
Python libraries:
sudo apt-get install python-pip
sudo pip install RPi.GPIO
sudo pip install spidev
sudo apt-get install python-imaging
sudo apt-get install python-smbus
Enable I2C interface:
sudo raspi-config

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 8/ 17
ASSEMBLY
Note: Before you assemble servos to Pan-Tilt HAT, please test the servo with test
codes to avoid of servo stuck when rotate
1. Connect servos to Pan-Tilt HAT
Brown wire
GND
Red wire
5V
Yellow wire
S1/S0
You should connect the Pan servo (close to HAT board) to S1, and connect Tilt
servo (close to camera) to S0. Please adjust the angle of the servo when assembling by
using the test codes, avoiding of damaging.

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 9/ 17
2. test code
3. Run the test code
sudo make
sudo ./main
4. After running, both servos will rotate to 0-degree place (The starting place). Then
power off and assemble the servo as assemble guide. (Do not rotate the servo
when assembling)
Assemble guide: https://www.waveshare.com/img/devkit/accBoard/Pan-Tilt-
HAT/Pan-Tilt-HAT-assemble.jpg
A: Tilt servo
B: Pan servo
The starting status of servos are as image above, and the direction of arrow are the
rotate direction of servo.

Pan-Tilt HAT User Manual
Version: V1.0.0; Date: 2019.03.16 10 / 17
SERVO AND LIGHT SENSOR
To run the Servo Driver and Light Sensor examples. Please enter the folder and using
following commands to execute programs:
BCM2835 examples:
cd bcm2835
sudo ./main
wiringPi examples:
cd wiringpi
sudo ./main
Python examples:
sudo python main.py
Note: If it prompt that files is not exist when running bcm2835 or wiringpi codes,
please first execute command make and try again.
CAMERA
To use camera, you need to fist do settings
1. Connect Camera to Raspberry Pi
2. Enable Camera
sudo raspi-config
Table of contents
Popular Camera Accessories manuals by other brands

Viltrox
Viltrox EF-NEX Mount instructions

Calumet
Calumet 7100 Series CK7114 operating instructions

Ropox
Ropox 4Single Series User manual and installation instructions

Cambo
Cambo Wide DS Digital Series Main operating instructions

Samsung
Samsung SHG-120 Specification sheet

Ryobi
Ryobi BPL-1820 Owner's operating manual











