|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/PIR8575/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/PIR8575/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/PIR8575/issues) |
| 6 | + |
| 7 | +[](https://github.com/RobTillaart/PIR8575/blob/master/LICENSE) |
| 8 | +[](https://github.com/RobTillaart/PIR8575/releases) |
| 9 | +[](https://registry.platformio.org/libraries/robtillaart/PIR8575) |
| 10 | + |
| 11 | + |
| 12 | +# PIR8575 |
| 13 | + |
| 14 | +Arduino library for 16 channel PIR detection system based upon PCF8575. |
| 15 | + |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +**Experimental** |
| 20 | + |
| 21 | +The library gives control over up to 16 parallel working PIR devices over I2C. |
| 22 | + |
| 23 | +The idea for this library came up in a discussion about how to fully cover an |
| 24 | +area with PIR sensors without blind spots and how to check them. |
| 25 | +The existing PIR library (see below) uses the pins of a processor, which is fast. |
| 26 | +However there are only so many free pins for IO, so then the idea for this |
| 27 | +library popped up. |
| 28 | + |
| 29 | +The library is based upon the well tested PCF8575 library (stripped version) |
| 30 | +and is expected to work to some extend with the PCF8574. (to be verified). |
| 31 | + |
| 32 | +To connect the PIR units (especially 16 ones) one has to connect a separate |
| 33 | +power supply as these cannot be powered directly by a typical microprocessor. |
| 34 | + |
| 35 | +The library is not tested with many PIR sensors yet. |
| 36 | + |
| 37 | +As always, feedback is welcome. |
| 38 | + |
| 39 | + |
| 40 | +### I2C address |
| 41 | + |
| 42 | +The base address of teh PCF8575 = 0x20 + 0..7 depending on address pins A0..A2. |
| 43 | + |
| 44 | + |
| 45 | +### Interrupts intro |
| 46 | + |
| 47 | +The PIR8575 (PCF8575) has an interrupt output line (INT) to notify an MCU |
| 48 | +that one of the input lines has changed its status. |
| 49 | +This can be used to prevent active polling of the PCF8575, which can be |
| 50 | +more efficient. |
| 51 | + |
| 52 | +See datasheet PCF8575 for details. |
| 53 | + |
| 54 | + |
| 55 | +### Related |
| 56 | + |
| 57 | +- https://github.com/RobTillaart/PIR |
| 58 | +- https://github.com/RobTillaart/PCF8575 16 bit IO expander. |
| 59 | + |
| 60 | + |
| 61 | +## Interface |
| 62 | + |
| 63 | +```cpp |
| 64 | +#include "PIR8575.h" |
| 65 | +``` |
| 66 | + |
| 67 | +### Constructor |
| 68 | + |
| 69 | +- **PIR8575(uint8_t address, TwoWire \* wire = &Wire)** Constructor with |
| 70 | +I2C device address, and the optional Wire interface as parameter. |
| 71 | +- **bool begin()** returns true if device address is seen on I2C bus. |
| 72 | +- **bool isConnected()** checks if the address is visible on the I2C bus. |
| 73 | +- **uint8_t getAddress()** returns the device address. |
| 74 | + |
| 75 | +### Read |
| 76 | + |
| 77 | +- **uint16_t read16()** reads all 16 pins at once. This one does the actual reading. |
| 78 | +- **uint8_t read(uint8_t pir)** reads a single PIR device; parameter pir = 0..15. |
| 79 | +- **int lastError()** returns the last error from the lib. (see .h file). |
| 80 | + |
| 81 | + |
| 82 | +## Error codes |
| 83 | + |
| 84 | +| name | value | description | |
| 85 | +|:--------------------|:-------:|:--------------------------| |
| 86 | +| PIR8575_OK | 0x00 | no error | |
| 87 | +| PIR8575_PIN_ERROR | 0x81 | pin number out of range | |
| 88 | +| PIR8575_I2C_ERROR | 0x82 | I2C communication error | |
| 89 | + |
| 90 | + |
| 91 | +## Future |
| 92 | + |
| 93 | +#### Must |
| 94 | + |
| 95 | +- update documentation. |
| 96 | +- test with hardware |
| 97 | + |
| 98 | +#### Should |
| 99 | + |
| 100 | +- add examples |
| 101 | + - PIR scanner 360 degrees, "clock" |
| 102 | + - corridor ? |
| 103 | +- polarity of all pins - in begin()? (conditional XOR in read). |
| 104 | + |
| 105 | +#### Could |
| 106 | + |
| 107 | +- move code to .cpp |
| 108 | +- use of mask during read |
| 109 | +- configure number of PIR's (1..16) in begin()?. |
| 110 | + |
| 111 | +#### Wont |
| 112 | + |
| 113 | + |
| 114 | +## Support |
| 115 | + |
| 116 | +If you appreciate my libraries, you can support the development and maintenance. |
| 117 | +Improve the quality of the libraries by providing issues and Pull Requests, or |
| 118 | +donate through PayPal or GitHub sponsors. |
| 119 | + |
| 120 | +Thank you, |
| 121 | + |
| 122 | + |
0 commit comments