Advanced Functions - sparkfun Qwiic GPIO Hook-Up Manual

Table of Contents

Advertisement

bool digitalWrite(bool *gpioOutStatus);
.
LOW
bool digitalRead(uint8_t gpioNumber);
selected GPIO pin.
uint8_t digitalReadPort(bool *gpioInStatus);
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);
bool writeBit(uint8_t regAddr, uint8_t bitAddr, bool bitToWrite);
selected register.
uint8_t readRegister(uint8_t addr);
bool writeRegister(uint8_t addr, uint8_t val);
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
.
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
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
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
pin mode to avoid confusion. After we've set up GPIO 0 as an output, the code toggles it HIGH and LOW using
every second and prints out the GPIO status via serial.
digitalWrite();
- Standard Digital Read function. Returns the status of the
- Read a specific register.
Serial
or
instead of the standard Arduino setup of
GPIO_IN
GPIO_IN = true
- Write to the entire port set up using a
- Read the status of the entire port set up using a
- Read a specific bit in a selected register.
- Write to a specific register.
pinMode();
calls. Simply update that definition with whichever serial
2
and
GPIO_OUT = false
to either
bool
- Write to a specific bit in a
,
and
invertPin();
and
OUTPUT
INPUT_PULLUP
are defined in the library to set the
or
HIGH
.
bool

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Qwiic GPIO and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents