API Reference

qwiic_button

Python module for the Qwiic Button.

This python package is a port of the exisiting [SparkFun Qwiic Button Arduino Library](https://github.com/sparkfun/SparkFun_Qwiic_Button_Arduino_Library)

This package can be used in conjunction with the overall [SparkFun Qwiic Python Package](https://github.com/sparkfun/Qwiic_Py)

New to qwiic? Take a look at the entire [SparkFun Qwiic Ecosystem](https://www.sparkfun.com/qwiic).

class qwiic_button.QwiicButton(address=None, i2c_driver=None)[source]
Parameters
  • address – The I2C address to use for the device. If not provided, the default address is used.

  • i2c_driver – An existing i2c driver object. If not provided a driver object is created.

Returns

The GPIO device object.

Return type

Object

LED_config(brightness, cycle_time, off_time, granularity=1)[source]

Write brightness, cycle_time, off_time, and granularity parameters to their respective registers: LED_BRIGHTNESS, LED_PULSE_CYCLE_TIME, LED_PULSE_OFF_TIME, LED_PULSE_GRANULARITY

Parameters
  • brightness – between 0 (led off) and 255 (max brightness)

  • cycle_time – total pulse cycle in in milliseconds Range 0 to 0xFFFF

  • off_time – off time between pulses in milliseconds Range 0 to 0xFFFF

  • granularity – the amount of steps it takes to get to led brightness If not provided, granularity defaults to 1

Returns

Nothing

Return type

Void

LED_off()[source]

Write zero’s to all the LED registers: LED_BRIGHTNESS, LED_PULSE_CYCLE_TIME, LED_PULSE_OFF_TIME, and LED_PULSE_GRANULARITY defaults to zero.

Returns

Nothing

Return type

void

LED_on(brightness)[source]

Set LED on without pulse

Parameters

brightness – between 0 (led off) and 255 (max brightness)

Returns

Nothing

Return type

Void

available()[source]

Return the event_available bit of the BUTTON_STATUS register

Returns

event_available bit

Rtye

bool

begin()[source]

Initialize the operation of the Qwiic Button Run is_connected() and check the ID in the ID register

Returns

Returns true if the intialization was successful, otherwise False.

Return type

bool

clear_event_bits()[source]

Clear the is_pressed, has_been_clicked, and event_available bits of the BUTTON_STATUS register

Returns

Nothing

Return type

Void

disable_clicked_interrupt()[source]

Clear the clicked_enable bit of the INTERRUPT_CONFIG register

Returns

Nothing

Return type

Void

disable_pressed_interrupt()[source]

Clear the pressed_enable bit of the INTERRUPT_CONFIG register

Returns

Nothing

Return type

Void

enable_clicked_interrupt()[source]

Set the clicked_enable bit of the INTERRUPT_CONFIG register

Returns

Nothing

Return type

Void

enable_pressed_interrupt()[source]

Set pressed_enable bit of the INTERRUPT_CONFIG register to a 1

Returns

Nothing

Return type

Void

get_I2C_address()[source]

Returns the current I2C address of the Qwiic Button

Returns

current I2C address

Return type

int

get_debounce_time()[source]

Returns the value in the BUTTON_DEBOUNCE_TIME register

Returns

debounce time in milliseconds

Return type

int

get_firmware_version()[source]

Read the register and get the major and minor firmware version number.

Returns

16 bytes version number

Return type

int

has_button_been_clicked()[source]

Returns the value of the has_been_clicked status bit of the BUTTON_STATUS register

Returns

has_been_clicked bit

Return type

bool

is_button_pressed()[source]

Returns the value of the is_pressed status bit of the BUTTON_STATUS register

Returns

is_pressed bit

Return type

bool

is_clicked_queue_empty()[source]

Reads the is_empty bit of the CLICKED_QUEUE_STATUS register

Returns

clicked_is_empty

Return type

bool

is_clicked_queue_full()[source]

Reads the is_full bit of the CLICKED_QUEUE_STATUS register

Returns

clicked_is_full

Return type

bool

is_connected()[source]

Determine if a Qwiic Button device is connected to the system.

Returns

True if the device is connected, otherwise False.

Return type

bool

is_pressed_queue_empty()[source]

Returns the is_empty bit of the PRESSED_QUEUE_STATUS register

Returns

pressed_is_empty

Return type

bool

is_pressed_queue_full()[source]

Returns the is_full bit of the PRESSED_QUEUE_STATUS register

Returns

pressed_is_full

Return type

bool

pop_clicked_queue()[source]

Returns contents of CLICKED_QUEUE_BACK register and writes a 1 to popRequest bit of CLICKED_QUEUE_STATUS register.

Returns

CLICKED_QUEUE_BACK

Return type

int

pop_pressed_queue()[source]

Returns contents of PRESSED_QUEUE_BACK register and writes a 1 to popRequest bit of PRESSED_QUEUE_STATUS register.

Returns

PRESSED_QUEUE_BACK

Return type

int

reset_interrupt_config()[source]

Enable pressed and clicked interrupts and clear the event_available bit of BUTTON_STATUS register

Returns

Nothing

Return type

Void

set_I2C_address(new_address)[source]

Change the I2C address of the Qwiic Button

Parameters

new_address – the new I2C address to set the Qwiic Button to The function itself checks if the entered parameter is a valid I2C address

Returns

True if the change was successful, false otherwise.

Return type

bool

set_debounce_time(time)[source]

Write two bytes into the BUTTON_DEBOUNCE_TIME register

Parameters

time – the time in milliseconds to set debounce time to The max debounce time is 0xFFFF milliseconds, but the function checks if the entered parameter is valid

Returns

Nothing

Return type

void

time_since_first_click()[source]

Returns the four bytes of CLICKED_QUEUE_BACK register. Time in milliseconds

Returns

CLICKED_QUEUE_BACK

Return type

int

time_since_first_press()[source]

Returns the four bytes of PRESSED_QUEUE_BACK. Time in milliseconds

Returns

PRESSED_QUEUE_BACK

Return type

int

time_since_last_click()[source]

Returns the four bytes of CLICKED_QUEUE_FRONT register. Time in milliseconds

Returns

CLICKED_QUEUE_FRONT

Return type

int

time_since_last_press()[source]

Returns the four bytes of PRESSED_QUEUE_FRONT. Time in milliseconds.

Returns

PRESSED_QUEUE_FRONT

Return type

int

class qwiic_button.QwiicButton(address=None, i2c_driver=None)[source]
Parameters
  • address – The I2C address to use for the device. If not provided, the default address is used.

  • i2c_driver – An existing i2c driver object. If not provided a driver object is created.

Returns

The GPIO device object.

Return type

Object