2-Axis Pan-Tilt Camera Module Assembly and Configuration Guide

From Waveshare Wiki
Jump to: navigation, search

Servo Calibration

After completing the assembly of the product, refrain from powering it immediately. Before configuring the Raspberry Pi environment, begin by setting the IDs and the middle position for the servos. Connect your computer to the USB interface of the robot's universal driver board using a USB cable (ensure it's the left-side USB port) before powering up. This prevents unexpected servo movements before setting the middle position.

Ensure the power switch is in the OFF position. Then, use the provided 12V 5A power supply to connect to the power interface of the product, noting the crucial steps highlighted in red above. Next, turn on the power switch to power up the product. As the Raspberry Pi does not have an SD card or system installed at this point, the slave gimbal functions (excluding camera-related functionalities) can operate independently from the host device.

Upon startup, the OLED screen displays the following information:

  • The first line indicates the IP address of the slave device. If the Raspberry Pi has a system installed, it shows the Raspberry Pi's IP address. If not, it displays the slave device's IP address, usually 192.168.4.1.
  • The second line shows the gimbal's voltage and WIFI signal strength.
  • The third line provides the yaw angle information of the gimbal.
  • The fourth line indicates the current WIFI: Pan-Tilt_Camera.

After booting up, connect your smartphone or computer to the WIFI: Pan-Tilt_Camera network using the password 12345678. Once connected, open the Google Chrome browser and enter 192.168.4.1 in the address bar to access the lower-level device's web-based gimbal control interface. Now, you can proceed with setting the servo IDs and the middle position.

ID Setting

The initial IDs for both the pan and tilt servos are 1, but the ID for the pan servo should be set to 2.

  1. During product assembly, the pan and tilt servos are not connected. If they are connected, please disconnect the tilt servo to ensure that you set the servo ID only for the pan servo.
  2. In the "FEEDBACK INFORMATION" module's input box, enter the command to set the servo ID in JSON format:
{"T":54,"old":1,"new":2}

You can also directly click on the INPUT button of the BUS_SERVO_ID_SET command below, which will automatically input the servo ID setting command in JSON format into the input box. Click "SEND" to confirm and successfully set the ID.
2-Axis Pan-Tilt Camera Module Assembly01.png

Middle Position Setting

Connect the pan servo and tilt servo together. Before setting the middle position, ensure both servos' torque locks are turned off. In the "FEEDBACK INFORMATION" module's input box, enter the JSON-formatted command to toggle the torque locks:

{"T":55,"id":1,"status":0}
  • id: means the servo ID, 1 is the tilt servo, and 2 is the pan servo.
  • status: means the torque lock status, 0 is to turn off the torque lock and 1 is to turn on the servo lock.

First, turn off the torque lock of the tilt servo, allowing manual rotation while keeping the pan servo locked. Then, turn off the torque lock of the pan servo, enabling manual rotation for both servos. This process will also verify if the pan servo ID setting was successful. Once both servo torque locks are turned off, as shown in the diagram, manually adjust the angles of both servos to align the camera parallelly towards the front.
2-Axis Pan-Tilt Camera Module Assembly02.jpg
After adjusting the angle of two servos, you can input the command for setting the middle position of the servo in JSON format:

{"T":58,"id":1}
  • "id" here refers to the servo's ID: 1 for the tilt servo and 2 for the pan servo.

After setting the middle position, use the directional buttons (up, down, left, right) to control the gimbal's movement to different angles. Then, press the "MIDDLE" button to check if both servos rotate to the preset middle position. If the gimbal doesn't function correctly, recalibrate the servos by following all the calibration steps again. If it operates properly, confirming that the servo IDs and center positions are set correctly, power off the device. Now, you can proceed with configuring the Raspberry Pi environment.

Raspberry Pi Environment Configuration Tutorial

The Raspberry Pi Foundation has developed a graphical SD card writing tool called the Raspberry Pi Imager, which is compatible with operating systems such as Windows, Mac OS, and Ubuntu.
This tool automatically downloads images and installs them onto an SD card. It can also be used to install images of other systems onto an SD card. Click on the Raspberry Pi Imager official website link to download the latest version of the Raspberry Pi Imager and install it.
Device Preparation

  1. SD card reader
  2. SD card (at least 8GB)

Program Image

  • First, use the SD card reader to connect the SD card to the PC, open Raspberry Pi Imager, click on "CHOOSE DEVICE", and select the Raspberry Pi device.

Pan-Tilt Camera WRITEIMAGE01.png

  • Select the corresponding Raspberry Pi. The device we used this time was Raspberry Pi 4B, so we selected "Raspberry Pi 4".

Pan-Tilt Camera WRITEIMAGE02.png

  • Then, click on "CHOOSE OS" to select the operating system to be programmed.

Pan-Tilt Camera WRITEIMAGE03.png

  • The Raspberry Pi demo we provide is based on the latest system of the Raspberry Pi, so you need to select Bookworm (64-bit).

Pan-Tilt Camera WRITEIMAGE04.png

  • Then, click on "CHOOSE STORAGE" to select the SD card to program the system.

Pan-Tilt Camera WRITEIMAGE05.png
Pan-Tilt Camera WRITEIMAGE06.png

  • Once all the above options are selected, click "NEXT". A custom settings dialog box will pop up, select "EDIT SETTINGS" to configure the username and WiFi settings.

Pan-Tilt Camera WRITEIMAGE07.png

  • First of all, set the username and WiFi in the "GENERAL" column, and check the boxes as shown in the picture below. Among them, the Username, password, and WiFi hotspot name and password need to be changed to your own, and the WIFI country is CN.

Pan-Tilt Camera WRITEIMAGE08.png

  • Next, enable SSH service in "SERVICES", then you can use SSH connection to control your Raspberry Pi system remotely. After setting up, click save, it will pop up that the data on the SD card will be deleted, select "Yes".

Pan-Tilt Camera WRITEIMAGE09.png
Pan-Tilt Camera WRITEIMAGE010.png
Start to program the image, and wait for a while to finish burning, the Raspberry Pi Imager will automatically pop up the SD card, remove the SD card, and insert it into the Raspberry Pi. Turn on the main power switch and power on the Raspberry Pi.

Demo Download

The Raspberry Pi will automatically connect to the hotspot set above to get the Raspberry Pi IP address. Type cmd in the Start menu bar to open a command prompt and use SSH to connect to the Raspberry Pi remotely, input:

ssh hostname@IP address

Enter, type yes, and then enter the password you set earlier. It is a normal phenomenon that there is no change on the screen when you input the password, after you finish inputting the password, you can access the Raspberry Pi by pressing the Enter key. As shown in the following picture:
Pan-Tilt Camera Module dOWN01.png
Download the zip file of the product's demos for the Raspberry Pi from the Waveshare, and enter the following command in the Raspberry Pi to download it:

wget https://files.waveshare.com/wiki/2-Axis-Pan-Tilt-Camera-Module/Pt_rpi.zip

Once downloaded, extract the Pt_rpi.zip:

unzip Pt_rpi.zip

Pan-Tilt Camera Module dOWN02.png

Software Installation

Unzip it and install the software, first go to the pt_rpi directory:

cd pt_rpi

Enter the following two commands to add executable permissions to the setup.sh and autorun.sh files:

sudo chmod +x setup.sh
sudo chmod +x autorun.sh

Pan-Tilt Camera Module dOWN03.png
Execute ./setup.sh -i to install the script file for the software installation, input:

sudo ./setup.sh -i

The installation may take a while, and then "Setup completed" is shown on the window.
Pan-Tilt Camera Module dOWN04.png
Execute the . /autorun.sh file and then finally type "sudo reboot" to reboot to make the installation changes take effect.

. /autorun.sh
sudo reboot

Pan-Tilt Camera Module dOWN05.png
After reboot, all the installation and environment configuration of the gimbal ends here, next refer to the product use tutorial to understand the use of this product.