background image

With the Qwiic GPIO Python Package installed, we can start working with the examples included with it. In this
section we'll go over each example and highlight pertinent bits of code. To run the examples, download 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 toggles them on and off each second. Note you need to
define the mode of each pin as well as call 

setMode

 to write the configuration to the Qwiic GPIO. Copy the code

below and execute it in your chosen Python IDE.

Содержание 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...

Отзывы: