Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bmengineer-gear/RuTiTe
Python script to record flashlight runtime using a Raspberry Pi and a TSL2591
https://github.com/bmengineer-gear/RuTiTe
Last synced: about 2 months ago
JSON representation
Python script to record flashlight runtime using a Raspberry Pi and a TSL2591
- Host: GitHub
- URL: https://github.com/bmengineer-gear/RuTiTe
- Owner: bmengineer-gear
- License: gpl-3.0
- Created: 2020-06-01T18:57:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-05T14:37:16.000Z (about 4 years ago)
- Last Synced: 2024-08-06T12:23:32.882Z (6 months ago)
- Language: Python
- Size: 403 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - bmengineer-gear/RuTiTe - Python script to record flashlight runtime using a Raspberry Pi and a TSL2591 (Python)
README
# RuTiTe
Python script to record flashlight runtime test (RuTiTe) using a Raspberry Pi and a TSL2591.
# Installation
To install this script, just copy rutite.py to the directory you're working in. You'll need to have python3 installed along with the following dependencies:
- time
- math
- os
- csv
- board
- busio
- adafruit_tsl2591
- RPi
- argparse
- sys
- matplotlibRun the following commands to install all the required dependencies on a fresh install of Raspberry Pi OS:
pip3 install adafruit-blinka
pip3 install adafruit-circuitpython-tsl2591
pip3 install matplotlib# Usage
At it's most basic, you can just run `python3 rutite.py`, and this script will fire up. It will print out to the terminal to let you know when it's ready for you to turn on a light and start the test, and record the runtime to a .csv file.
## Options
If you want to get fancy, there's plenty of configurability available.
- `-i` sets the interval between recordings, so `python3 rutite.py -i 0.5` would record a measurement every half second, instead of the default once per second.
- `-o` sets the output file name, so `python3 rutite.py -o flashlighttest.csv` would save the results in a file named flashlighttest.csv. If this isn't used, a timestamp will be used as the file name.
- `-d` sets the maximum duration the test will run for in minutes. `python3 rutite.py -d 15` If this isn't specified, the test won't stop automatically after a certain time.
- `-tp` sets the percent to terminate the test at. If you wanted the test to stop after the output reaches 10% of what it was at 30 seconds, you would run `python3 rutite.py -tp 10`. Note that when it reaches the set level, it keeps recording for a bit longer.
- `-pp` and `pd` both determine how often updates are printed to the terminal. If you wanted an update every time the output had changed by 10%, or every 30 minutes (whichever came first), you would run `python3 rutite.py -pp 10 -pd 30`.
- `-r` records relative time alongside the absolute time. If you're plotting the results afterwards, this makes sure the graph will start at 0 - but it will make the recorded file size a bit bigger.
- `-g` outputs a plot when the script is done. Right now this only works when either `-d`, `-tp`, or both is used and you let the script run until it's done.
## Example
I ran the following test of the highest mode of a lumintop FW1A:
```
pi@rpi0:~ $ python3 runtimetestandplot.py -o FW1Aturbo.csv -i 0.3 -d 5 -g 'FW1A Turbo' -pp 10
```
As a result I got the following printed out in the terminal:
```
15:14:16 Saving as FW1Aturbo.csv
15:14:18 Ready to start the test. Turn on the light now.
```
At this point I turned on the light in the mode I wanted to test:
```
15:14:24 Light detected. Recording started.
15:14:55 Sampling period complete. The output at 30s was 1931.6 lux. Sampling period max = 2159.3 lux, min = 1903.9 lux.
The test will run until you stop it, or it has recorded for 5 minutes, or it reaches 193.2 lux (10.0% of the output at 30s).
15:15:13 Output is at 90% (1732 lux)
15:15:17 Output is at 79% (1523 lux)
15:15:27 Output is at 69% (1324 lux)
15:15:36 Output is at 58% (1125 lux)
15:16:10 Output is at 48% (930 lux)
15:17:27 Output is at 38% (734 lux)
15:19:24 Test complete
```
All done! I now have two files in my directory - `FW1Aturbo.csv` and `FW1A Turbo.png`.
The csv file looks something like this:
```
time,lux,absolute time,lumens
1594408465.550655,2159.2926719999996,,2159.2926719999996
1594408466.3578901,2142.548352,,2142.548352
1594408467.1652982,2131.97952,,2131.97952
...
```
and the image looks like this:
![example plot](https://github.com/bmengineer-gear/RuTiTe/blob/state-machine/exampleplot.png)
# Limitations
Maximum lux of the sensor is 88,000. If the lux recorded by the sensor is too high, you should adjust your setup so less light is hitting the sensor.
# Hardware Setup
This test uses a raspberry pi and the sensor. I've added LEDs to my setup for quick status indication at a glance, but these are completely optional. No screen is required if you're starting tests over ssh. An internet connection is required for timing.
![wiring diagram](https://github.com/bmengineer-gear/runtimetest/blob/master/runtimetestwiringdiagram.png)
I've replaced the first LED with a green one on my own setup.
# Test Setup
To perform a test with the finished hardware, you'll need a setup that directs some of the light from a flashlight to the sensor. Even a room will work, but objects moving around (including you) can affect the results, as can anyone turning on a light. I use a box for this reason.
It's important that the light being tested is the only light source hitting the sensor, and that test setup remains stationary while the test is running.
# Planned Changes
- Add option to record IR mode for IR lights
- Switch from sloppy delays to scheduling
# Known Issues
- If the light exceeds the sensor ceiling, the script will crash. If this happens, uncomment `#sensor.gain = adafruit_tsl2591.GAIN_LOW` in the code, and try again. If it still happens, you need to adjust your setup so less light reaches the sensor.
- Plotting doesn't work if you manually stop the test