Welcome

This documentation will guide you through the methods available in the Pan Tilt HAT python library.

Pan-Tilt HAT lets you mount and control one of our pan-tilt modules right on top of your Raspberry Pi. The HAT and its on-board microcontroller let you independently drive the two servos (pan and tilt), as well as driving up to 24 regular LED (with PWM control) or NeoPixel RGB (or RGBW) LEDs

At A Glance

class pantilthat.PanTilt(enable_servo1=True, enable_servo2=True, enable_lights=True, light_mode=1, servo1_min=800, servo1_max=2300, servo2_min=800, servo2_max=2300, address=21, i2c_bus=None)[source]
brightness(brightness)[source]
clear()[source]
light_mode(mode)[source]
pan(angle)
servo_enable(index, state)[source]
servo_one(angle)[source]
servo_pulse_max(index, value)[source]
servo_pulse_min(index, value)[source]
servo_two(angle)[source]
set_all(red, green, blue)[source]
set_pixel(index, red, green, blue)[source]
set_pixel_rgbw(index, red, green, blue, white)[source]
show()[source]
tilt(angle)

Set Brightness

pantilthat.brightness(brightness)

Set the brightness of the connected LED ring.

Parameters:brightness – Brightness from 0 to 255

Clear

pantilthat.clear()

Clear the buffer.

Set Light Mode

pantilthat.light_mode(mode)

Set the light mode for attached lights.

PanTiltHAT can drive either WS2812 pixels, or provide a PWM dimming signal for regular LEDs.

Pan

pantilthat.pan(angle)

Set position of servo 1 in degrees.

Parameters:angle – Angle in degrees from -90 to 90
pantilthat.servo_one(angle)

Set position of servo 1 in degrees.

Parameters:angle – Angle in degrees from -90 to 90

Tilt

pantilthat.tilt(angle)

Set position of servo 2 in degrees.

Parameters:angle – Angle in degrees from -90 to 90
pantilthat.servo_two(angle)

Set position of servo 2 in degrees.

Parameters:angle – Angle in degrees from -90 to 90

Servo Enable

pantilthat.servo_enable(index, state)

Enables/disables a servo.

Disabling a servo turns off the drive signal.

It’s good practise to do this if you don’t want the Pan/Tilt to point in a certain direction and instead want to save power.

Parameters:
  • index – Servo index: either 1 or 2
  • state – Servo state: True = on, False = off

Servo Pulse Min

pantilthat.servo_pulse_min(index, value)

Set the minimum high pulse for a servo in microseconds.

Parameters:value – Value in microseconds

Servo Pulse Max

pantilthat.servo_pulse_max(index, value)

Set the maximum high pulse for a servo in microseconds.

Parameters:value – Value in microseconds

Set All LEDs

pantilthat.set_all(red, green, blue)

Set all pixels in the buffer.

Parameters:
  • red – Amount of red, from 0 to 255
  • green – Amount of green, from 0 to 255
  • blue – Amount of blue, from 0 to 255

Set A LED

pantilthat.set_pixel(index, red, green, blue)

Set a single pixel in the buffer.

Parameters:
  • index – Index of pixel from 0 to 23
  • red – Amount of red, from 0 to 255
  • green – Amount of green, from 0 to 255
  • blue – Amount of blue, from 0 to 255

Set A LED (RGBW)

pantilthat.set_pixel_rgbw(index, red, green, blue, white)

Set a single pixel in the buffer for GRBW lighting stick.

Instead of driving 24 RGB pixels, you can drive 18 RGBW ones.

Parameters:
  • index – Index of pixel from 0 to 17
  • red – Amount of red, from 0 to 255
  • green – Amount of green, from 0 to 255
  • blue – Amount of blue, from 0 to 255
  • white – Amount of white, from 0 to 255

Show

pantilthat.show()

Display the buffer on the connected WS2812 strip.

Constants

  • WS2812 = 1 - used with pantilthat.light_mode to set WS2812 LEDs
  • PWM = 0 - used with pantilthat.light_mode to set PWM dimmed LEDs