Skip to content

Commit 06866da

Browse files
committed
0.1.0 PIR8575
1 parent 42e79a6 commit 06866da

File tree

16 files changed

+583
-0
lines changed

16 files changed

+583
-0
lines changed

libraries/PIR8575/.arduino-ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
# - esp8266
26+
# - mega2560
27+
- rpipico
28+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: json-syntax-check
16+
uses: limitusus/json-syntax-check@v2
17+
with:
18+
pattern: "\\.json$"

libraries/PIR8575/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log PIR8575
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2025-01-28
10+
- initial version
11+

libraries/PIR8575/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025-2025 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/PIR8575/PIR8575.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#pragma once
2+
//
3+
// FILE: PIR8575.h
4+
// AUTHOR: Rob Tillaart
5+
// VERSION: 0.1.0
6+
// DATE: 2025-01-28
7+
// PURPOSE: Arduino library for 16 channel PIR detection system based upon PCF8575
8+
// Also works (limited) with PCF8574.
9+
10+
11+
#include "Arduino.h"
12+
#include "Wire.h"
13+
14+
#define PIR8575_LIB_VERSION (F("0.1.0"))
15+
16+
#define PIR8575_OK 0x00
17+
#define PIR8575_PIN_ERROR 0x81
18+
#define PIR8575_I2C_ERROR 0x82
19+
20+
21+
class PIR8575
22+
{
23+
public:
24+
// CONSTRUCTOR
25+
// pins to set.
26+
PIR8575(uint8_t address, TwoWire * wire = &Wire)
27+
{
28+
_address = address;
29+
_wire = wire;
30+
};
31+
32+
bool begin()
33+
{
34+
if (! isConnected()) return false;
35+
return true;
36+
};
37+
38+
bool isConnected()
39+
{
40+
_wire->beginTransmission(_address);
41+
return ( _wire->endTransmission() == 0);
42+
};
43+
44+
uint8_t getAddress()
45+
{
46+
return _address;
47+
};
48+
49+
uint16_t read16()
50+
{
51+
if (_wire->requestFrom(_address, (uint8_t)2) != 2)
52+
{
53+
_error = PIR8575_I2C_ERROR;
54+
return _dataIn; // last value
55+
}
56+
_dataIn = _wire->read(); // low 8 bits
57+
_dataIn |= (_wire->read() << 8); // high 8 bits
58+
return _dataIn;
59+
};
60+
61+
uint16_t read(uint8_t pir)
62+
{
63+
if (pir > 15)
64+
{
65+
_error = PIR8575_PIN_ERROR;
66+
return 0;
67+
}
68+
read16();
69+
return (_dataIn & (1 << pir)) > 0;
70+
};
71+
72+
int lastError()
73+
{
74+
int e = _error;
75+
_error = PIR8575_OK; // reset error after read, is this wise?
76+
return e;
77+
};
78+
79+
80+
protected:
81+
uint8_t _address;
82+
TwoWire * _wire;
83+
uint16_t _dataIn = 0;
84+
uint8_t _error = PIR8575_OK;
85+
};
86+
87+
88+
// -- END OF FILE --
89+

libraries/PIR8575/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/PIR8575/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/PIR8575/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/PIR8575/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/PIR8575/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/PIR8575/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/PIR8575.svg)](https://github.com/RobTillaart/PIR8575/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/PIR8575/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/PIR8575.svg?maxAge=3600)](https://github.com/RobTillaart/PIR8575/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/PIR8575.svg)](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+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
# - uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
# - m4
24+
- esp32
25+
# - esp8266
26+
# - mega2560
27+
- rpipico
28+

0 commit comments

Comments
 (0)