SPRING SALE up to 20% OFF! (excludes trade customers)  •  FREE Standard Delivery for orders over £35 (ex VAT)
Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

Servo PWM Pi C Library

Servo PWM Pi C Library Installation and Usage

Created 29/07/2024 | Last Updated: 19/06/2025

YOU WILL NEED THIS BOARD

70 available
Order a Servo PWM Pi Photo of Servo PWM Pi

Servo PWM Pi

16 Channel 12-bit PWM and Servo Driver with I2C interface using PCA9685 for driving LEDs and RC servos

£7.59 ex VAT

View Product

C Library to use with Servo PWM Pi Raspberry Pi development  board.

The example C programs can be found in /ABElectronics_C_Libraries/ServoPi/demos

Downloading and Installing the library

To download to your Raspberry Pi type in the terminal:

git clone https://github.com/abelectronicsuk/ABElectronics_C_Libraries.git

Functions

servopi_init(uint8_t address, uint8_t use_oe_pin)

Initialise the Servo Pi - run before calling any other methods
Parameter: (uint8_t) address - I2C address
Parameter: (uint8_t) use_oe_pin - Enable the Output Enable pin on the GPIO port
Returns: (int) 0 = OK, 1 = GPIO enable failed, 2 = GPIO direction set failed


set_pwm_freq(double freq, uint8_t address)

Set the PWM frequency
Parameter: (double) freq - required frequency
Parameter: (uint8_t) address - I2C address
Returns: null


set_pwm(uint8_t channel, uint16_t on, uint16_t off, uint8_t address)

Set the output on single channels
Parameter: (uint8_t) channel - 1 to 16
Parameter: (uint16_t) on - period 0 to 4096
Parameter: (uint16_t) off - period 0 to 4096
Parameter: (uint8_t) address - I2C address
Returns: null


set_all_pwm(uint16_t on, uint16_t off, uint8_t address)

Set the output on all channels
Parameter: (uint16_t) on - period 0 to 4096
Parameter: (uint16_t) off - period 0 to 4096
Parameter: (uint8_t) address - I2C address
Returns: null


output_disable()

Disable the output via the OE pin
Returns: (int) 0 = OK, 1 = GPIO failed


output_enable()

Enable the output via the OE pin
Returns: (int) 0 = OK, 1 = GPIO failed


set_allcall_address(uint8_t allcalladdress, uint8_t address)

Set the I2C address for the All Call function
Parameter: (uint8_t) allcalladdress - New I2C All Call address
Parameter: (uint8_t) address - I2C address
Returns: null


enable_allcall_address(uint8_t address)

Enable the I2C address for the All Call function
Parameter: (uint8_t) address - I2C address
Returns: null


disable_allcall_address(uint8_t address)

Disable the I2C address for the All Call function
Parameter: (uint8_t) address - I2C address
Returns: null


Also useful for your Raspberry Pi project

Temperature & Sensing

1 Wire Pi Plus

Connect dozens of 1-Wire sensors - temperature, iButtons, EEPROMs - via a single GPIO pin. Stacks directly on the 40-pin header.

£9.59 ex VAT

Analogue I/O

ADC Pi

Read up to 8 analogue inputs - perfect for pairing with your temperature sensors or other analogue-output devices.

£14.39 ex VAT

All-in-one

Expander Pi

Combines ADC, DAC, 32 GPIO ports and a real-time clock on one board. The most versatile board for complex Raspberry Pi projects.

£15.99 ex VAT

Order these Boards

All boards are designed & manufactured in the UK with RoHS-compliant components.

Home

Shop

Learn

Forum

FAQ

Contact