UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

PCA9685 Class

Module: pca9685

This controller is also used on the Adafruit* Motor Shield v2.3 board to control up to 4 DC motors, 2 stepper motors, and 2 servo motors.
This module was tested with the Adafruit Motor Shield v2.3
pca9685.jpg

Methods

PCA9685

(
  • bus
  • address
  • raw
)
Number

PCA9685 constructor

Parameters:

  • bus Number

    I2C bus to use

  • address Number

    Address for this device

  • raw Boolean

    undefined

Returns:

Number:

writeByte

(
  • reg
  • byte
)
Boolean

Writes a byte value into a register

Parameters:

  • reg Number

    Register location to write into

  • byte Number

    Byte to write

Returns:

Boolean:

True if successful

writeWord

(
  • reg
  • word
)
Boolean

Writes a word value into a register. Note: the device must have the auto-increment bit set in the MODE1 register to work.

Parameters:

  • reg Number

    Register location to write into

  • word Number

    Word to write

Returns:

Boolean:

True if successful

readByte

(
  • reg
)
Number

Reads a byte value from a register

Parameters:

  • reg Number

    Register location to read from

Returns:

Number:

Value in a specified register

readWord

(
  • reg
)
Number

Reads a word value from a register. Note: the device must have the auto-increment bit set in the MODE1 register to work.

Parameters:

  • reg Number

    Register location to read from

Returns:

Number:

Value in a specified register

setModeSleep

(
  • sleep
)
Boolean

Puts the device in or out of the sleep mode. The device is always in the sleep mode upon power-up.

Parameters:

  • sleep Boolean

    True to put the device in the sleep mode, false to put out

Returns:

Boolean:

True if successful

ledFullOn

(
  • led
  • val
)
Boolean

Sets or clears the FULL ON bit for a given LED

Parameters:

  • led Number

    LED number; valid values are 0-15, PCA9685_ALL_LED

  • val Boolean

    True to set the bit, false to clear it

Returns:

Boolean:

True if successful

ledFullOff

(
  • led
  • val
)
Boolean

Sets or clears the FULL OFF bit for a given LED. If the FULL ON bit is also set, FULL OFF has precedence.

Parameters:

  • led Number

    LED number; valid values are 0-15, PCA9685_ALL_LED

  • val Boolean

    True to set the bit, false to clear it

Returns:

Boolean:

True if successful

ledOnTime

(
  • led
  • time
)
Boolean

Sets the 'LED on' time (0-4,095). See the PCA9685 datasheet for details.

Parameters:

  • led Number

    LED number; valid values are 0-15, PCA9685_ALL_LED

  • time Number

    12-bit value at which point the LED turns on

Returns:

Boolean:

True if successful

ledOffTime

(
  • led
  • time
)
Boolean

Sets the 'LED off' time (0-4,095). See the PCA9685 datasheet for details.

Parameters:

  • led Number

    LED number; valid values are 0-15, PCA9685_ALL_LED

  • time Number

    12-bit value at which point the LED turns off

Returns:

Boolean:

True if successful

setPrescale

(
  • prescale
)
Boolean

Sets the prescale value. See the PCA9685 datasheet for details. The prescale can only be set when the device is in the sleep mode.

Parameters:

  • prescale Number

    Prescale value

Returns:

Boolean:

True if successful

setPrescaleFromHz

(
  • hz
  • oscFreq
)
Boolean

Sets the prescale value based on a desired frequency in Hz. The prescale can only be set when the device is in the sleep mode.

Parameters:

  • hz Number

    Desired frequency in Hz

  • oscFreq Number

    Oscillator frequency; default is 25 MHz

Returns:

Boolean:

True if successful

enableRestart

(
  • enabled
)

Enables or disables the restart capability of the controller

Parameters:

  • enabled Boolean

    True to enable, false to disable It is enabled by default.

Properties

REG_MODE1

Enum PCA9685_REG_T

REG_MODE2

Enum PCA9685_REG_T

REG_I2C_SA1

Enum PCA9685_REG_T

REG_I2C_SA2

Enum PCA9685_REG_T

REG_I2C_SA3

Enum PCA9685_REG_T

REG_ALLCALL

Enum PCA9685_REG_T

REG_LED0_ON_L

Enum PCA9685_REG_T

REG_LED0_ON_H

Enum PCA9685_REG_T

REG_LED0_OFF_L

Enum PCA9685_REG_T

REG_LED0_OFF_H

Enum PCA9685_REG_T

REG_LED1_ON_L

Enum PCA9685_REG_T

REG_LED1_ON_H

Enum PCA9685_REG_T

REG_LED1_OFF_L

Enum PCA9685_REG_T

REG_LED1_OFF_H

Enum PCA9685_REG_T

REG_LED2_ON_L

Enum PCA9685_REG_T

REG_LED2_ON_H

Enum PCA9685_REG_T

REG_LED2_OFF_L

Enum PCA9685_REG_T

REG_LED2_OFF_H

Enum PCA9685_REG_T

REG_LED3_ON_L

Enum PCA9685_REG_T

REG_LED3_ON_H

Enum PCA9685_REG_T

REG_LED3_OFF_L

Enum PCA9685_REG_T

REG_LED3_OFF_H

Enum PCA9685_REG_T

REG_LED4_ON_L

Enum PCA9685_REG_T

REG_LED4_ON_H

Enum PCA9685_REG_T

REG_LED4_OFF_L

Enum PCA9685_REG_T

REG_LED4_OFF_H

Enum PCA9685_REG_T

REG_LED5_ON_L

Enum PCA9685_REG_T

REG_LED5_ON_H

Enum PCA9685_REG_T

REG_LED5_OFF_L

Enum PCA9685_REG_T

REG_LED5_OFF_H

Enum PCA9685_REG_T

REG_LED6_ON_L

Enum PCA9685_REG_T

REG_LED6_ON_H

Enum PCA9685_REG_T

REG_LED6_OFF_L

Enum PCA9685_REG_T

REG_LED6_OFF_H

Enum PCA9685_REG_T

REG_LED7_ON_L

Enum PCA9685_REG_T

REG_LED7_ON_H

Enum PCA9685_REG_T

REG_LED7_OFF_L

Enum PCA9685_REG_T

REG_LED7_OFF_H

Enum PCA9685_REG_T

REG_LED8_ON_L

Enum PCA9685_REG_T

REG_LED8_ON_H

Enum PCA9685_REG_T

REG_LED8_OFF_L

Enum PCA9685_REG_T

REG_LED8_OFF_H

Enum PCA9685_REG_T

REG_LED9_ON_L

Enum PCA9685_REG_T

REG_LED9_ON_H

Enum PCA9685_REG_T

REG_LED9_OFF_L

Enum PCA9685_REG_T

REG_LED9_OFF_H

Enum PCA9685_REG_T

REG_LED10_ON_L

Enum PCA9685_REG_T

REG_LED10_ON_H

Enum PCA9685_REG_T

REG_LED10_OFF_L

Enum PCA9685_REG_T

REG_LED10_OFF_H

Enum PCA9685_REG_T

REG_LED11_ON_L

Enum PCA9685_REG_T

REG_LED11_ON_H

Enum PCA9685_REG_T

REG_LED11_OFF_L

Enum PCA9685_REG_T

REG_LED11_OFF_H

Enum PCA9685_REG_T

REG_LED12_ON_L

Enum PCA9685_REG_T

REG_LED12_ON_H

Enum PCA9685_REG_T

REG_LED12_OFF_L

Enum PCA9685_REG_T

REG_LED12_OFF_H

Enum PCA9685_REG_T

REG_LED13_ON_L

Enum PCA9685_REG_T

REG_LED13_ON_H

Enum PCA9685_REG_T

REG_LED13_OFF_L

Enum PCA9685_REG_T

REG_LED13_OFF_H

Enum PCA9685_REG_T

REG_LED14_ON_L

Enum PCA9685_REG_T

REG_LED14_ON_H

Enum PCA9685_REG_T

REG_LED14_OFF_L

Enum PCA9685_REG_T

REG_LED14_OFF_H

Enum PCA9685_REG_T

REG_LED15_ON_L

Enum PCA9685_REG_T

REG_LED15_ON_H

Enum PCA9685_REG_T

REG_LED15_OFF_L

Enum PCA9685_REG_T

REG_LED15_OFF_H

Enum PCA9685_REG_T

REG_ALL_LED_ON_L

Enum PCA9685_REG_T

REG_ALL_LED_ON_H

Enum PCA9685_REG_T

REG_ALL_LED_OFF_L

Enum PCA9685_REG_T

REG_ALL_LED_OFF_H

Enum PCA9685_REG_T

REG_PRESCALE

Enum PCA9685_REG_T

REG_TESTMODE

Enum PCA9685_REG_T

MODE1_ALL_CALL

Enum PCA9685_MODE1_T

MODE1_SUB3

Enum PCA9685_MODE1_T

MODE1_SUB2

Enum PCA9685_MODE1_T

MODE1_SUB1

Enum PCA9685_MODE1_T

MODE1_SLEEP

Enum PCA9685_MODE1_T

MODE1_AI

Enum PCA9685_MODE1_T

MODE1_EXTCLK

Enum PCA9685_MODE1_T

MODE1_RESTART

Enum PCA9685_MODE1_T

MODE2_OUTNE0

Enum PCA9685_MODE2_T

MODE2_OUTNE

Enum PCA9685_MODE2_T

MODE2_OUTDRV

Enum PCA9685_MODE2_T

MODE2_OCH

Enum PCA9685_MODE2_T

MODE2_INVRT

Enum PCA9685_MODE2_T

MODE2_RESERVE0

Enum PCA9685_MODE2_T

MODE2_RESERVE1

Enum PCA9685_MODE2_T

MODE2_RESERVE2

Enum PCA9685_MODE2_T