mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.8 PCF8574
This commit is contained in:
parent
0c634c511d
commit
08d061c88d
@ -6,7 +6,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: arduino/arduino-lint-action@v1
|
- uses: arduino/arduino-lint-action@v1
|
||||||
with:
|
with:
|
||||||
library-manager: update
|
library-manager: update
|
||||||
|
@ -8,7 +8,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: 2.6
|
ruby-version: 2.6
|
||||||
|
@ -10,7 +10,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: json-syntax-check
|
- name: json-syntax-check
|
||||||
uses: limitusus/json-syntax-check@v1
|
uses: limitusus/json-syntax-check@v1
|
||||||
with:
|
with:
|
||||||
|
@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.3.8] - 2023-02-04
|
||||||
|
- update readme.md
|
||||||
|
- update GitHub actions
|
||||||
|
- update license 2023
|
||||||
|
|
||||||
|
|
||||||
## [0.3.7] - 2022-11-16
|
## [0.3.7] - 2022-11-16
|
||||||
- fix #40 - add interrupt section to readme.md
|
- fix #40 - add interrupt section to readme.md
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2013-2022 Rob Tillaart
|
Copyright (c) 2013-2023 Rob Tillaart
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
// FILE: PCF8574.cpp
|
// FILE: PCF8574.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// DATE: 02-febr-2013
|
// DATE: 02-febr-2013
|
||||||
// VERSION: 0.3.7
|
// VERSION: 0.3.8
|
||||||
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||||
// URL: https://github.com/RobTillaart/PCF8574
|
// URL: https://github.com/RobTillaart/PCF8574
|
||||||
// http://forum.arduino.cc/index.php?topic=184800
|
// http://forum.arduino.cc/index.php?topic=184800
|
||||||
//
|
|
||||||
// HISTORY: See CHANGELOG.md
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "PCF8574.h"
|
#include "PCF8574.h"
|
||||||
|
|
||||||
@ -186,7 +184,7 @@ void PCF8574::rotateLeft(const uint8_t n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PCF8574::reverse() // quite fast: 14 shifts, 3 or, 3 assignment.
|
void PCF8574::reverse() // quite fast: 4 and, 14 shifts, 3 or, 3 assignment.
|
||||||
{
|
{
|
||||||
uint8_t x = _dataOut;
|
uint8_t x = _dataOut;
|
||||||
x = (((x & 0xAA) >> 1) | ((x & 0x55) << 1));
|
x = (((x & 0xAA) >> 1) | ((x & 0x55) << 1));
|
||||||
@ -240,6 +238,5 @@ void PCF8574::selectN(const uint8_t pin)
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -3,18 +3,17 @@
|
|||||||
// FILE: PCF8574.h
|
// FILE: PCF8574.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// DATE: 02-febr-2013
|
// DATE: 02-febr-2013
|
||||||
// VERSION: 0.3.7
|
// VERSION: 0.3.8
|
||||||
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
// PURPOSE: Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||||
// URL: https://github.com/RobTillaart/PCF8574
|
// URL: https://github.com/RobTillaart/PCF8574
|
||||||
// http://forum.arduino.cc/index.php?topic=184800
|
// http://forum.arduino.cc/index.php?topic=184800
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
|
||||||
|
|
||||||
#define PCF8574_LIB_VERSION (F("0.3.7"))
|
#define PCF8574_LIB_VERSION (F("0.3.8"))
|
||||||
|
|
||||||
#ifndef PCF8574_INITIAL_VALUE
|
#ifndef PCF8574_INITIAL_VALUE
|
||||||
#define PCF8574_INITIAL_VALUE 0xFF
|
#define PCF8574_INITIAL_VALUE 0xFF
|
||||||
@ -63,7 +62,8 @@ public:
|
|||||||
|
|
||||||
// rotate, shift, toggle, reverse expect all lines are output
|
// rotate, shift, toggle, reverse expect all lines are output
|
||||||
void toggle(const uint8_t pin);
|
void toggle(const uint8_t pin);
|
||||||
void toggleMask(const uint8_t mask = 0xFF); // default 0xFF ==> invertAll()
|
// default 0xFF ==> invertAll()
|
||||||
|
void toggleMask(const uint8_t mask = 0xFF);
|
||||||
void shiftRight(const uint8_t n = 1);
|
void shiftRight(const uint8_t n = 1);
|
||||||
void shiftLeft(const uint8_t n = 1);
|
void shiftLeft(const uint8_t n = 1);
|
||||||
void rotateRight(const uint8_t n = 1);
|
void rotateRight(const uint8_t n = 1);
|
||||||
|
@ -18,10 +18,11 @@ Related to the PCF8575 16 channel IO expander library https://github.com/RobTil
|
|||||||
This library gives easy control over the 8 pins of a PCF8574 and PCF8574A chip.
|
This library gives easy control over the 8 pins of a PCF8574 and PCF8574A chip.
|
||||||
These chips are identical in behaviour although there are two distinct address ranges.
|
These chips are identical in behaviour although there are two distinct address ranges.
|
||||||
|
|
||||||
| TYPE | ADDRESS-RANGE | notes |
|
| type | address-range | notes |
|
||||||
|:---------|:-------------:|:------------------------:|
|
|:-----------|:---------------:|:-------------------------:|
|
||||||
|PCF8574 | 0x20 to 0x27 | same range as PCF8575 !! |
|
| PCF8574 | 0x20 to 0x27 | same range as PCF8575 ! |
|
||||||
|PCF8574A | 0x38 to 0x3F | |
|
| PCF8574A | 0x38 to 0x3F |
|
||||||
|
|
||||||
|
|
||||||
So you can connect up to 16 PCF8574 on one I2C bus, giving access
|
So you can connect up to 16 PCF8574 on one I2C bus, giving access
|
||||||
to 16 x 8 = 128 IO lines. To maximize IO lines combine 8 x PCF8575 + 8 x PCF8574A giving
|
to 16 x 8 = 128 IO lines. To maximize IO lines combine 8 x PCF8575 + 8 x PCF8574A giving
|
||||||
@ -34,15 +35,33 @@ Furthermore some additional functions are implemented that are playful and usefu
|
|||||||
|
|
||||||
#### Interrupts
|
#### Interrupts
|
||||||
|
|
||||||
The PCF8574 has an interrupt output line (INT) to notice a MCU that one of the input lines has changed.
|
The PCF8574 has an interrupt output line (INT) to notify an MCU that one of the input lines has changed.
|
||||||
This can be used to prevent active polling of the PCF8574, which can be more efficient.
|
This can be used to prevent active polling of the PCF8574, which can be more efficient.
|
||||||
The library does not support this internally.
|
|
||||||
|
The library cannot handle the PCF8574 interrupts as it has no code for it.
|
||||||
|
The user should catch the interrupt in his own code and can use the library to see which line has changed.
|
||||||
|
|
||||||
There are two examples to show how interrupts can be used:
|
There are two examples to show how interrupts can be used:
|
||||||
- PCF8574_interrupt.ino
|
- PCF8574_interrupt.ino
|
||||||
- PCF8574_rotaryEncoder.ino
|
- PCF8574_rotaryEncoder.ino
|
||||||
|
|
||||||
|
|
||||||
|
#### Related
|
||||||
|
|
||||||
|
16 bit port expanders
|
||||||
|
|
||||||
|
- https://github.com/RobTillaart/MCP23017_RT
|
||||||
|
- https://github.com/RobTillaart/MCP23S17
|
||||||
|
- https://github.com/RobTillaart/PCF8575
|
||||||
|
|
||||||
|
|
||||||
|
8 bit port expanders
|
||||||
|
|
||||||
|
- https://github.com/RobTillaart/MCP23008
|
||||||
|
- https://github.com/RobTillaart/MCP23S08
|
||||||
|
- https://github.com/RobTillaart/PCF8574
|
||||||
|
|
||||||
|
|
||||||
## I2C Clock
|
## I2C Clock
|
||||||
|
|
||||||
Tested on UNO with **PCF8574_performance** showed that the PCF8574 still works at 500 KHz and failed at 600 KHz.
|
Tested on UNO with **PCF8574_performance** showed that the PCF8574 still works at 500 KHz and failed at 600 KHz.
|
||||||
@ -50,7 +69,7 @@ These values are outside the specs of the datasheet so they are not recommended.
|
|||||||
However when performance is needed you can try to overclock the chip.
|
However when performance is needed you can try to overclock the chip.
|
||||||
|
|
||||||
| clock speed | Read | Write | Notes |
|
| clock speed | Read | Write | Notes |
|
||||||
|:-----------:|:------:|:-------:|:------------------|
|
|:-----------:|:------:|:-------:|:--------------------|
|
||||||
| 100000 | 236 | 240 | spec datasheet |
|
| 100000 | 236 | 240 | spec datasheet |
|
||||||
| 200000 | 132 | 140 |
|
| 200000 | 132 | 140 |
|
||||||
| 300000 | 104 | 108 |
|
| 300000 | 104 | 108 |
|
||||||
@ -61,6 +80,10 @@ However when performance is needed you can try to overclock the chip.
|
|||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "PCF8574.h"
|
||||||
|
```
|
||||||
|
|
||||||
**PCF8574_INITIAL_VALUE** is a define that can be set compile time or before
|
**PCF8574_INITIAL_VALUE** is a define that can be set compile time or before
|
||||||
the include of "pcf8574.h" to overrule the default value used with the **begin()** call.
|
the include of "pcf8574.h" to overrule the default value used with the **begin()** call.
|
||||||
|
|
||||||
@ -143,7 +166,7 @@ This can typical be used to implement a VU meter.
|
|||||||
## Error codes
|
## Error codes
|
||||||
|
|
||||||
| name | value | description |
|
| name | value | description |
|
||||||
|:-------------------|:-----:|:------------------------|
|
|:--------------------|:-------:|:--------------------------|
|
||||||
| PCF8574_OK | 0x00 | no error |
|
| PCF8574_OK | 0x00 | no error |
|
||||||
| PCF8574_PIN_ERROR | 0x81 | pin number out of range |
|
| PCF8574_PIN_ERROR | 0x81 | pin number out of range |
|
||||||
| PCF8574_I2C_ERROR | 0x82 | I2C communication error |
|
| PCF8574_I2C_ERROR | 0x82 | I2C communication error |
|
||||||
@ -158,6 +181,17 @@ It is advised to use pull-up or pull-down resistors so the lines have a defined
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
-
|
#### Must
|
||||||
|
|
||||||
|
- keep in sync with PCF8575
|
||||||
|
|
||||||
|
#### Should
|
||||||
|
|
||||||
|
|
||||||
|
#### Could
|
||||||
|
|
||||||
|
- move code to .cpp
|
||||||
|
|
||||||
|
#### Wont
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/PCF8574.git"
|
"url": "https://github.com/RobTillaart/PCF8574.git"
|
||||||
},
|
},
|
||||||
"version": "0.3.7",
|
"version": "0.3.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=PCF8574
|
name=PCF8574
|
||||||
version=0.3.7
|
version=0.3.8
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander
|
sentence=Arduino library for PCF8574 - 8 channel I2C IO expander
|
||||||
|
@ -105,4 +105,5 @@ unittest(test_address)
|
|||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
|
|
||||||
// --------
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user