Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cedargrovestudios/circuitpython_shadowwatcher
A CircuitPython helper class to detect a shadow cast over an analog light sensor such as the ALS-PT19 phototransistor.
https://github.com/cedargrovestudios/circuitpython_shadowwatcher
adafruit-pyportal als-pt19 circuitpython circuitpython-community-bundle gesture-detection light-sensor phototransistor shadow-detection
Last synced: about 2 months ago
JSON representation
A CircuitPython helper class to detect a shadow cast over an analog light sensor such as the ALS-PT19 phototransistor.
- Host: GitHub
- URL: https://github.com/cedargrovestudios/circuitpython_shadowwatcher
- Owner: CedarGroveStudios
- License: mit
- Created: 2022-10-14T05:10:27.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-07T05:09:20.000Z (almost 2 years ago)
- Last Synced: 2023-03-11T15:06:04.999Z (almost 2 years ago)
- Topics: adafruit-pyportal, als-pt19, circuitpython, circuitpython-community-bundle, gesture-detection, light-sensor, phototransistor, shadow-detection
- Language: Python
- Homepage:
- Size: 595 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Introduction
============.. image:: https://img.shields.io/discord/327254708534116352.svg
:target: https://adafru.it/discord
:alt: Discord.. image:: https://github.com/CedarGroveStudios/CircuitPython_ShadowWatcher/workflows/Build%20CI/badge.svg
:target: https://github.com/CedarGroveStudios/CircuitPython_ShadowWatcher/actions
:alt: Build Status.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code Style: BlackA CircuitPython helper class to detect a shadow cast over an analog light sensor
such as the ALS-PT19 phototransistor.ShadowWatcher is a CircuitPython helper class to detect a shadow cast over an
analog light sensor such as the ALS-PT19 phototransistor used in the Adafruit
PyPortal, PyGamer, PyBadge, CircuitPlayground Express, CircuitPlayground
Bluefruit, and the ALS-PT19 breakout board. Incorporates a low-pass filter to
reduce sensitivity to flickering light levels which may be caused by power line
frequency or light dimmer PWM passthrough. Useful as a simple gesture detector.Dependencies
=============
This driver depends on:* `Adafruit CircuitPython `_
* Analog light sensor hardware such as the ALS-PT19 phototransistor with an output value directly in proportion to the light intensity.
The ShadowWatcher was primarily built for and tested on the PyPortal, but
should be able to function reliably on other microcontrollers with similar
sensors. The automatic samples mode will test the microcontroller's analog
acquision latency and adjust the internal low-pass filter's sample size to
maintain the ~25 Hz cutoff frequency.Please ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloading
`the Adafruit library and driver bundle `_
or individual libraries can be installed using
`circup `_.Installing to a Connected CircuitPython Device with Circup
==========================================================Make sure that you have ``circup`` installed in your Python environment.
Install it with the following command if necessary:.. code-block:: shell
pip3 install circup
With ``circup`` installed and your CircuitPython device connected use the
following command to install:.. code-block:: shell
circup install cedargrove_shadowwatcher
Or the following command to update an existing version:
.. code-block:: shell
circup update
Usage Example
=============.. code-block:: python
import board
import time
from shadowwatcher import ShadowWatcher
# Instantiate detector class and establish background level
gesture = ShadowWatcher(pin=board.LIGHT, auto=True)
while True:
if gesture.detect():
print(f"SHADOW DETECTED")
while gesture.detect():
# Wait until the shadow is gone
time.sleep(1)
# Rebaseline the background level
gesture.refresh_background()
print(f"background: {gesture.background:6.0f}")Documentation
=============
API documentation for this library can be found on `Read the Docs `_.The ShadowWatcher helper class was tested on the PyPortal, but should be able to
function reliably on other microcontrollers with similar sensors. The automatic
samples mode will test the microcontroller's analog acquisition latency and
adjust the internal low-pass filter's sample size to maintain the ~25 Hz cutoff
frequency.The left oscilloscope image shows the sampled sensor light level value in a room
with a dimmed LED light source (yellow trace). Note that the primary frequency
of the signal is 120Hz (purple frequency spectrum graph). The right image shows
the sampled sensor light level value after filtering... image:: https://github.com/CedarGroveStudios/CircuitPython_ShadowWatcher/blob/main/media/FIR_boxcar_filter_pyportal.png
For information on building library documentation, please check out
`this guide `_.Contributing
============Contributions are welcome! Please read our `Code of Conduct
`_
before contributing to help this project stay welcoming.