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();
.
Arduino Examples
The Qwiic GPIO Arduino Library has three examples split into single pin and port variants to demonstrate how to
set up control the TCA9534 along with a fourth example demonstrating how to use the external interrupt capability.
In this section we will go over those examples and highlight a few things to take note of when setting up your Qwiic
GPIO in code.
Note:
If you are using the SparkFun Qwiic Micro - SAMD21 Development Board as shown in the Hardware
Assembly section you'll need to add this quick define due to how the SAMD architecture handles ports:
#define Serial SerialUSB
This definition helps a ton when working with chip architectures that have multiple serial ports you need to
call specifically instead of using a general
Serial
calls. Simply update that definition with whichever serial
port you want to use for serial prints via USB.
Example 1A: Write GPIO
A basic digital write example. Open Example 1A in Arduino by navigating to
File > Examples > SparkFun Qwiic
GPIO Arduino Library > Example1a-Write_GPIO
. This example sets up GPIO 0 as an output and toggles it
HIGH and LOW. The code starts up by initializing the Qwiic GPIO on the I C bus on the default address and sets
GPIO0 as an output:
myGPIO.pinMode(0, GPIO_OUT); //Use GPIO_OUT and GPIO_IN instead of OUTPUT and INPUT_PULLUP
Take note to use
GPIO_OUT
or
GPIO_IN
instead of the standard Arduino setup of
OUTPUT
and
INPUT_PULLUP
when setting the GPIO pin as an input or output. We use these alternates because the TCA9534's I/O pins default
as an
INPUT
(pin mode = True) so
GPIO_IN = true
and
GPIO_OUT = false
are defined in the library to set the
pin mode to avoid confusion. After we've set up GPIO 0 as an output, the code toggles it HIGH and LOW using
digitalWrite();
every second and prints out the GPIO status via serial.
2