0.1.2 TCA9555

This commit is contained in:
rob tillaart 2021-12-28 18:38:10 +01:00
parent 7be561e2bc
commit 091e1c673a
12 changed files with 89 additions and 54 deletions

View File

@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
- leonardo
- m4
- esp32
- esp8266
- mega2560

View File

@ -4,11 +4,14 @@ name: Arduino CI
on: [push, pull_request]
jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# - uses: Arduino-CI/action@latest
- uses: Arduino-CI/action@master
# Arduino-CI/action@v0.1.1
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021-2021 Rob Tillaart
Copyright (c) 2021-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,23 +1,30 @@
[![Arduino CI](https://github.com/RobTillaart/TCA9555/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![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)
[![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)
# TCA9555
Arduino library for TCA9555 16 channel I2C port expander
Arduino library for TCA9555 16 channel I2C port expander.
## Description
This experimental library gives easy control over the 16 pins of a TCA9555 chip.
This library gives easy control over the 16 pins of a TCA9555 chip.
The TCA9555 supports up to 400 kHz I2C.
#### from datasheet
#### TCA9535
from datasheet:
_The TCA9535 is identical to the TCA9555, except that the TCA9535 does not include the internal I/O
pull-up resistor, which requires pull-ups and pulldowns on unused I/O pins when configured as an
input and undriven. This reduces power consumption when the I/Os are held low._
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._
There is a TCA9535 class which is a (convenience) wrapper around the TCA9555 class.
This allows one to create TCA9535 objects.
@ -30,18 +37,18 @@ Check the datasheet for details
### Constructor
- **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
- **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.
- **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
- **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.
### 1 pin interface
- **bool pinMode(uint8_t pin, uint8_t mode)**
- **bool pinMode(uint8_t pin, uint8_t mode)** idem.
- **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.
@ -54,7 +61,8 @@ port = 0..1
mask = 0..255
- **bool pinMode8(uint8_t port, uint8_t mask)** set the mode of eight pins in one call.
- **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.
- **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.
- **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.
@ -62,18 +70,23 @@ mask = 0..255
### 16 pin interface
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).
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.
- **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.
- **bool setPolarity16(uint16_t mask)** inverts polarity of the 8 INPUT pins in one action. Returns true upon success.
- **bool setPolarity16(uint16_t mask)** inverts polarity of the 8 INPUT pins in one action.
Returns true upon success.
- **uint16_t getPolarity()** returns a mask of 16 bits with a 1 for every INPUT pin that is inverted.
### Error codes
- **int lastError()** Above functions set an error flag that can be read withthis function. Reading it will reset the flag to **TCA9555_OK**.
- **int lastError()** Above functions set an error flag that can be read with this function.
Reading it will reset the flag to **TCA9555_OK**.
| DESCRIPTION | VALUE |
|:---------------------|:-----:|
@ -85,18 +98,23 @@ Be aware that the 16 pins interface does two calls to the 8 pins interface. So i
| TCA9555_INVALID_READ | -100 |
## Future
#### Must
- test all functionality (initial version is written with no hardware around)
- add TCA9535 error codes
#### Could
- buy TCA9555 / TCA9535
- rethink class hierarchy?
## Operation
See examples
## Future
#### Must
- test all functionality (initial version is written with no hardware around)
- add TCA9535 error codes
#### Could
- buy TCA9555 / TCA9535
- rethink class hierarchy?
- investigate internal pull up etc.

View File

@ -1,7 +1,7 @@
//
// FILE: TCA9555.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library for I2C TCA9555 16 channel port expander
// DATE: 2021-06-09
// URL: https://github.com/RobTillaart/TCA9555
@ -9,6 +9,7 @@
// HISTORY:
// 0.1.0 2021-06-09 initial version
// 0.1.1 2021-06-10 add 16 bit interface
// 0.1.2 2021-12-28 update Arduino-CI, readme, license, minor edits
#include "TCA9555.h"
@ -252,8 +253,6 @@ uint8_t TCA9555::getPolarity8(uint8_t port)
//
// 16 PIN INTERFACE
//
bool TCA9555::pinMode16(uint16_t mask)
{
bool b = true;
@ -310,8 +309,7 @@ int TCA9555::lastError()
////////////////////////////////////////////////////
//
// PRIVATE
//
//
bool TCA9555::writeRegister(uint8_t reg, uint8_t value)
{
_wire->beginTransmission(_address);
@ -349,10 +347,12 @@ uint8_t TCA9555::readRegister(uint8_t reg)
/////////////////////////////////////////////////////////////////////////////
//
// TCA9535
//
//
TCA9535::TCA9535(uint8_t address, TwoWire *wire)
:TCA9555(address, wire)
{
}
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
//
// FILE: TCA9555.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.2
// PURPOSE: Arduino library for I2C TCA9555 16 channel port expander
// DATE: 2021-06-09
// URL: https://github.com/RobTillaart/TCA9555
@ -12,15 +12,15 @@
#include "Wire.h"
#define TCA9555_LIB_VERSION (F("0.1.1"))
#define TCA9555_LIB_VERSION (F("0.1.2"))
#define TCA9555_OK 0x00
#define TCA9555_PIN_ERROR 0x81
#define TCA9555_I2C_ERROR 0x82
#define TCA9555_VALUE_ERROR 0x83
#define TCA9555_PORT_ERROR 0x84
#define TCA9555_OK 0x00
#define TCA9555_PIN_ERROR 0x81
#define TCA9555_I2C_ERROR 0x82
#define TCA9555_VALUE_ERROR 0x83
#define TCA9555_PORT_ERROR 0x84
#define TCA9555_INVALID_READ -100
#define TCA9555_INVALID_READ -100
class TCA9555
@ -49,7 +49,7 @@ public:
// 8 PIN INTERFACE
// port = 0..1
// mask = bitpattern
// mask = bit pattern
bool pinMode8(uint8_t port, uint8_t mask);
bool write8(uint8_t port, uint8_t mask);
int read8(uint8_t port);
@ -61,8 +61,7 @@ public:
// wraps 2x 8 PIN call.
// opportunistic implementation of functions
// needs error checking in between calls
// mask = bitpattern
// mask = bit pattern
bool pinMode16(uint16_t mask);
bool write16(uint16_t mask);
uint16_t read16();
@ -85,7 +84,7 @@ protected:
/////////////////////////////////////////////////////////////////////////////
//
// TCA9535 class which is just a wrapper (for now)
//
//
class TCA9535 : public TCA9555
{
TCA9535(uint8_t address, TwoWire *wire = &Wire);
@ -93,3 +92,4 @@ class TCA9535 : public TCA9555
// -- END OF FILE --

View File

@ -11,6 +11,7 @@
TCA9555 TCA(0x27);
void setup()
{
Serial.begin(115200);
@ -30,9 +31,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -11,6 +11,7 @@
TCA9555 TCA(0x27);
void setup()
{
Serial.begin(115200);
@ -55,9 +56,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -47,9 +47,11 @@ void setup()
Serial.println();
}
void loop()
{
}
// -- END OF FILE --

View File

@ -15,8 +15,9 @@
"type": "git",
"url": "https://github.com/RobTillaart/TCA9555.git"
},
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "TCA9555.h"
}

View File

@ -1,5 +1,5 @@
name=TCA9555
version=0.1.1
version=0.1.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C TCA9555 16 channel port expander - 16 IO-lines

View File

@ -39,8 +39,10 @@
unittest_setup()
{
fprintf(stderr, "TCA9555_LIB_VERSION:\t%s\n", (char *) TCA9555_LIB_VERSION);
}
unittest_teardown()
{
}
@ -48,7 +50,6 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "TCA9555_LIB_VERSION:\t%s\n", TCA9555_LIB_VERSION);
TCA9555 TCA(0x22);
assertTrue(TCA.begin());