background image

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

Содержание Qwiic GPIO

Страница 1: ...ander IC from Texas Instruments to add up to 8 digital inputs and outputs controlled via an I C interface The TCA9534U features three address select pins that can be set to configure eight unique addr...

Страница 2: ...e In this guide we ll go over everything you need to know about the Qwiic GPIO so you can add those extra I O pins to your circuit with ease Required Materials In order to follow along with this tutor...

Страница 3: ...re a few options for each of those cable types SparkFun Qwiic Shield for Thing Plus DEV 16790 SparkFun Qwiic Shield for Arduino DEV 14352 SparkFun Qwiic Adapter DEV 14495 SparkFun Qwiic Shield for Ard...

Страница 4: ...ok Up Wire Assortment Stranded 22 AWG PRT 11375 Qwiic Cable 200mm PRT 14428 Polarity An introduction to polarity in electronic components Discover what polarity is which parts have it and how to ident...

Страница 5: ...tion on this functionality refer to section 8 3 2 in the TCA9534 datasheet and Example 4 Interrupt in the Qwiic GPIO Arduino Library Three hardware pins A0 A1 and A2 are dedicated I C address select p...

Страница 6: ...CL GND and 3 3V on the Qwiic GPIO are broken out to a pair of Qwiic connectors as well as standard 0 1 spaced PTH pins for those who would prefer to solder to them The default I C address for the Qwii...

Страница 7: ...state is closed This holds the Interrupt pin HIGH so it can be driven LOW when an interrupt event is monitored by the TCA9534 Open the jumper if you have another pullup on the Interrupt pin Address Ju...

Страница 8: ...IO you will need to solder to them For a temporary connection for prototyping these IC Hooks are a great option to make that connection For users not familiar with through hole soldering take a look a...

Страница 9: ...ns 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 I C bus If you have...

Страница 10: ...ion 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 i...

Страница 11: ...PIO_OUT GPIO_OUT GPI O_OUT GPIO_OUT Along with the pin mode we also need to define the initial state of each GPIO bool gpioConfig NUM_GPIO HIGH LOW HIGH LOW HIGH LOW HIGH LOW With the GPIO port config...

Страница 12: ...d GPIO Port Example 2B demonstrates how to read the entire GPIO port on the TCA9534 The code sets up all eight GPIO pins just like Example 1B using a boolean but this time all pins are set as inputs W...

Страница 13: ...l print LOW break Serial println n delay 100 Example 3A Inversion Example 3A shows how to invert the signal polarity of an input on the Qwiic GPIO Polarity inversion only works on pins configured as a...

Страница 14: ...g processor interrupts on a microcontroller this tutorial will help you get started Example 4 demonstrates how to use the interrupt pin on the TCA9534 when any input pin registers a change The interru...

Страница 15: ...nstead with a different development board or single board computer like the Raspberry Pi read on to the next two sections where we ll detail how to use the Qwiic GPIO Python Package Qwiic GPIO Python...

Страница 16: ...allation To install make sure the setuptools package is installed on the system Direct installation at the command line use python for Python 2 python3 setup py install To build a package for use with...

Страница 17: ...or copy the code into a file then open save the example file if needed and execute the code in your preffered Python IDE Qwiic GPIO Example 1 This example sets up all eight I O pins as outputs and to...

Страница 18: ...IO mode_7 myGPIO GPIO_OUT myGPIO setMode while True myGPIO out_status_0 myGPIO GPIO_HI myGPIO out_status_1 myGPIO GPIO_HI myGPIO out_status_2 myGPIO GPIO_HI myGPIO out_status_3 myGPIO GPIO_HI myGPIO o...

Страница 19: ...shows how to read each I O pin when they are configured as inputs It first sets up all pins using the setMode function as we did in Example 1 The code then monitors and prints out the status of each...

Страница 20: ...e_5 myGPIO GPIO_IN myGPIO mode_6 myGPIO GPIO_IN myGPIO mode_7 myGPIO GPIO_IN myGPIO setMode while True myGPIO getGPIO This function updates each in_status_x variable print GPIO 0 end print myGPIO in_s...

Страница 21: ...f of them using the setInversion self function As we covered in the Arduino Examples section each I O pin set as an input defaults to an active HIGH input so inverting it switches it to an active LOW...

Страница 22: ...myGPIO GPIO_IN myGPIO setMode myGPIO inversion_0 myGPIO INVERT myGPIO inversion_1 myGPIO NO_INVERT myGPIO inversion_2 myGPIO INVERT myGPIO inversion_3 myGPIO NO_INVERT myGPIO inversion_4 myGPIO INVERT...

Страница 23: ...at wraps up this Hookup Guide For more information about the Qwiic GPIO take a look at the following links Schematic PDF Eagle Files ZIP Dimensional Drawing PNG TCA9534 Datasheet PDF Hardware GitHub R...

Отзывы: