SparkFun Qwiic GPIO Hookup Guide

Pages
Contributors: El Duderino, Englandsaurus
Favorited Favorite 2

Qwiic GPIO Arduino Library

Note: This library assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

The SparkFun Qwiic GPIO Arduino Library helps to make interfacing between the TCA9534 and your Arduino microcontroller simple. In this section we'll list all of the functions available in the library as well as brief descriptions about what they do.

Library Functions

We've outlined all the functions in the Arduino library below along with some quick descriptions of what they do. The examples cover nearly all of the functions so you may want to refer to those for help with writing your own code using them.

Device Setup & Settings

  • bool begin(TwoWire &wirePort, uint8_t address); - Initialize the TCA9534 on the I2C bus. If you have set the TCA9534 to an alternate I2C address using the ADR jumpers, enter that here.
  • bool pinMode(uint8_t gpioNumber, bool mode); - Sets the mode of the selected GPIO pin on the TCA9534. For example, pinMode(0, GPIO_OUT); sets pin 0 as an output. All I/O's default to Inputs on power up.
  • bool pinMode(bool *gpioPinMode); - An alternative to the above function to set the entire port as an input or output. This accepts a bool defined in your setup to set all eight GPIO pins at once. Refer to Example1B - Write_GPIO_Port for more information on using this function.
  • bool invertPin(uint8_t gpioNumber, bool inversionMode); - Invert the polarity of the selected GPIO pin on the TCA9534.
  • bool invertPin(bool *inversionMode); - Invert the polarity of the entire port of the TCA9534. Refer to Example 3B - Inversion_Port for a demonstration of how to set up and use this function.

GPIO Reading and Writing

  • bool digitalWrite(uint8_t gpioNumber, bool value); - Your basic Digital Write function. Write to the selected GPIO pin either HIGH or LOW.
  • bool digitalWrite(bool *gpioOutStatus); - Write to the entire port set up using a bool to either HIGH or LOW.
  • bool digitalRead(uint8_t gpioNumber); - Standard Digital Read function. Returns the status of the selected GPIO pin.
  • uint8_t digitalReadPort(bool *gpioInStatus); - Read the status of the entire port set up using a bool. Returns status of all selected pins on the port. Take a look at Example2B - Read_GPIO_Port for reference.

Advanced Functions

These functions are intended for experienced users to write and read specific bits and registers.

  • bool readBit(uint8_t regAddr, uint8_t bitAddr); - Read a specific bit in a selected register.
  • bool writeBit(uint8_t regAddr, uint8_t bitAddr, bool bitToWrite); - Write to a specific bit in a selected register.
  • uint8_t readRegister(uint8_t addr); - Read a specific register.
  • bool writeRegister(uint8_t addr, uint8_t val); - Write to a specific register.

Next up we'll cover the examples included with the Qwiic GPIO Arduino library to see these functions in action along with explaining a bit more on how to set up the port options for pinMode();, invertPin(); and digitalWrite();.