GY-63_MS5611/libraries/TCA9555/README.md

121 lines
4.2 KiB
Markdown
Raw Normal View History

2021-06-11 04:31:59 -04:00
[![Arduino CI](https://github.com/RobTillaart/TCA9555/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-28 12:38:10 -05:00
[![Arduino-lint](https://github.com/RobTillaart/TCA9555/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TCA9555/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/TCA9555/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TCA9555/actions/workflows/jsoncheck.yml)
2021-06-11 04:31:59 -04:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TCA9555/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/TCA9555.svg?maxAge=3600)](https://github.com/RobTillaart/TCA9555/releases)
2021-12-28 12:38:10 -05:00
2021-06-11 04:31:59 -04:00
# TCA9555
2021-12-28 12:38:10 -05:00
Arduino library for TCA9555 16 channel I2C port expander.
2021-06-11 04:31:59 -04:00
## Description
2021-12-28 12:38:10 -05:00
This library gives easy control over the 16 pins of a TCA9555 chip.
2021-06-11 04:31:59 -04:00
The TCA9555 supports up to 400 kHz I2C.
2021-12-28 12:38:10 -05:00
#### TCA9535
from datasheet:
2021-06-11 04:31:59 -04:00
_The TCA9535 is identical to the TCA9555, except that the TCA9535 does not include the internal I/O
2021-12-28 12:38:10 -05:00
pull-up resistor, which requires pull-ups and pull-downs on unused I/O pins when configured as an
input and not driven. This reduces power consumption when the I/O is held low._
2021-06-11 04:31:59 -04:00
There is a TCA9535 class which is a (convenience) wrapper around the TCA9555 class.
This allows one to create TCA9535 objects.
## Interface
Check the datasheet for details
### Constructor
2021-12-28 12:38:10 -05:00
- **TCA9555(uint8_t address, TwoWire \*wire = &Wire)** constructor, with default Wire interface. Can be overruled with Wire0..WireN.
- **TCA9535(uint8_t address, TwoWire \*wire = &Wire)** idem.
2021-06-11 04:31:59 -04:00
2021-12-28 12:38:10 -05:00
- **bool begin()** for UNO, returns true if successful.
- **bool begin(uint8_t sda, uint8_t scl)** for ESP32, returns true if successful.
- **bool isConnected()** returns true if connected, false otherwise.
2021-06-11 04:31:59 -04:00
### 1 pin interface
2021-12-28 12:38:10 -05:00
- **bool pinMode(uint8_t pin, uint8_t mode)** idem.
2021-06-11 04:31:59 -04:00
- **bool digitalWrite(uint8_t pin, uint8_t value)** pin = 0..15, value = LOW(0) HIGH (!0), returns true if successful.
- **uint8_t digitalRead(uint8_t pin)** pin = 0..15, returns the value of the pin HIGH or LOW.
- **bool setPolarity(uint8_t pin, uint8_t value)** inverts polarity of an INPUT pin.
- **uint8_t getPolarity(uint8_t pin)** returns 1 if a pin is inverted.
### 8 pin interface
port = 0..1
mask = 0..255
- **bool pinMode8(uint8_t port, uint8_t mask)** set the mode of eight pins in one call.
2021-12-28 12:38:10 -05:00
- **bool write8(uint8_t port, uint8_t mask)** returns true if successful.
Especially useful if one needs to trigger multiple pins at the exact same time.
2021-06-11 04:31:59 -04:00
- **uint8_t read8(uint8_t port)** returns a bit pattern for pins 0..7 or pins 8..15.
- **bool setPolarity8(uint8_t port, uint8_t mask)** inverts polarity of the 8 INPUT pins in one action.
- **uint8_t getPolarity(uint8_t port)** returns a mask with a 1 for every INPUT pin that is inverted.
### 16 pin interface
2021-12-28 12:38:10 -05:00
Be aware that the 16 pins interface does two calls to the 8 pins interface.
So it is impossible to switch pins from the 2 groups of 8 at exactly the same time
without additional hardware.
2021-06-11 04:31:59 -04:00
- **bool pinMode16(uint16_t mask)** set the mode of sixteen pins in one call.
- **bool write16(uint16_t mask)** mask = 0x0000 .. 0xFFFF, returns true if successful.
- **uint16_t read16()** Returns a bit pattern for pins 0..15.
2021-12-28 12:38:10 -05:00
- **bool setPolarity16(uint16_t mask)** inverts polarity of the 8 INPUT pins in one action.
Returns true upon success.
2021-06-11 04:31:59 -04:00
- **uint16_t getPolarity()** returns a mask of 16 bits with a 1 for every INPUT pin that is inverted.
### Error codes
2021-12-28 12:38:10 -05:00
- **int lastError()** Above functions set an error flag that can be read with this function.
Reading it will reset the flag to **TCA9555_OK**.
2021-06-11 04:31:59 -04:00
| DESCRIPTION | VALUE |
|:---------------------|:-----:|
| TCA9555_OK | 0x00 |
| TCA9555_PIN_ERROR | 0x81 |
| TCA9555_I2C_ERROR | 0x82 |
| TCA9555_VALUE_ERROR | 0x83 |
| TCA9555_PORT_ERROR | 0x84 |
| TCA9555_INVALID_READ | -100 |
2021-12-28 12:38:10 -05:00
## Operation
See examples
2021-06-11 04:31:59 -04:00
## Future
2021-12-28 12:38:10 -05:00
2021-06-11 04:31:59 -04:00
#### Must
2021-12-28 12:38:10 -05:00
2021-06-11 04:31:59 -04:00
- test all functionality (initial version is written with no hardware around)
- add TCA9535 error codes
2021-12-28 12:38:10 -05:00
2021-06-11 04:31:59 -04:00
#### Could
2021-12-28 12:38:10 -05:00
2021-06-11 04:31:59 -04:00
- buy TCA9555 / TCA9535
- rethink class hierarchy?
2021-12-28 12:38:10 -05:00
- investigate internal pull up etc.
2021-06-11 04:31:59 -04:00