Main Content

Pan Tilt Hat

Control pan and tilt motions using PCA9685-based PWM driver

Since R2022a

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

  • Raspberry Pi Pan Tilt Hat icon

Libraries:
Simulink Support Package for Raspberry Pi Hardware / Basic

Description

Use the Pan Tilt Hat block to control the pan and tilt motions of hardware using the PCA-9685-based PWM I2C driver. This block accepts pan and tilt angles in the range –90 to 90 degrees. The PCA9685 driver controls the movement of the pan and tilt hardware module in two degree of freedom (DoF), namely along the horizontal and vertical axes, respectively.

Activate, Load, and Verify PCA9685 Kernel Module

Follow these steps to activate and load the PCA9685 kernel module on your Raspberry Pi® hardware and then use the Pan Tilt Hat block in your Simulink® model.

  1. Open Raspberry Pi terminal.

  2. Open the /boot/config.txt file in a text editor.

  3. To activate the PCA9685 kernel module, add this code to the /boot/config.txt file.

    dtoverlay=i2c-pwm-pca9685a

  4. Save and close the /boot/config.txt file.

  5. Reboot your Raspberry Pi.

  6. To load the PCA9685 kernel module on your Raspberry Pi, execute this code in the Raspberry Pi terminal.

    sudo modprobe pwm-pca9685

  7. To verify whether you have successfully loaded the PCA9685 module on your Raspberry Pi hardware, execute this code in the Raspberry Pi terminal.

    i2cdetect -y <i2c bus number>

    For example,

    i2cdetect -y 1

    Observe that the PCA9685 kernel module reserves an I2C address 0x40 for the pan tilt hardware, indicated by UU.PCA9685 Kernel Module in use on I2C bus

Ports

Input

expand all

Pan angle that the block receives from the pan and tilt hardware module.

Data Types: double

Tilt angle that the block receives from the pan and tilt hardware module.

Data Types: double

Parameters

expand all

Select the operating mode of the pan and tilt hardware module.

  • Pan and tilt — Pan and tilt hardware moves along horizontal and vertical axes.

  • Pan — Pan and tilt hardware moves along horizontal axis.

  • Tilt — Pan and tilt hardware moves along vertical axis.

Select the PWM frequency of the pan and tilt servo motors.

Enter the time interval at which the block receives the pan and tilt angles from the pan and tilt hardware module.

Pan Servo

Enter the PCA9685 PWM channel to drive the pan servo motor.

Enter the minimum and maximum PWM pulse duration that the PCA9685 driver sends to the pan servo motor.

Tilt Servo

Enter the PCA9685 PWM channel to drive the tilt servo motor.

Enter the minimum and maximum PWM pulse duration that the PCA9685 driver sends to the tilt servo motor.

Version History

Introduced in R2022a