background image

Having trouble seeing the detail in this mess of jumper wires? Click on the photo for a larger view!

With the Qwiic GPIO circuit assembled and connected to your microcontroller it's time to get some code uploaded
and start controlling the extra I/O pins via I C!

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 I C bus. If you have

set the TCA9534 to an alternate I C 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

.

2

2

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...

Отзывы: