Note for future: https://raspberrypi.stackexchange.com/questions/89732/run-a-script-at-shutdown-on-raspbian
2 light sensors display the speed of an object moving in front of it in feet per second (this can be changed). The 5 most recent speeds are displayed on the user interface.
From the two light sensors, plug the red wires into 5v and the black wires into ground on the Raspberry Pi. Plug the white wire from the the sensor that will activate first as the object passes through to whatever IO pin is written in the config.py file (default 23). Do the same for the white wire from the light sensor which will have the object go past it last (default 24).
The pinout for the Raspberry Pi 3 can be found here
There are 3 important files: main.py, config.py, and userinterface.py.
This file is the main loop. All commands apart from the user interface are run through here.
- Ensure importation of your command or function.
- Add function that is supposed to loop in the main.py loop function
from objectspeed import checkSpeed
def loop():
if (config.mainRunsLoop):
checkSpeed() # if config is set to run check speed, it will add checkSpeed function to the loop from objectspeed file
else:
osc.reset(config.timeoutTime) # if config is set to run sensor callback function, a timeout is set to reset variables after config.timeoutTime in seconds
A single place to store variables which affect how the program runs
Change variable values to change how functions work
This is a variable used in the objectspeed file. Changing this variable will specify the distance between the two light sensors, which is necessary for the calculation of speed
lightSensorDistance = 3 # distance in inches, 1 hole separation = 3 inches, 0 hole = 1.5 inches
The information which the user can see at a glance. This updates on a different loop compared to the main.py loop.
- Create text using guizero library
- Change text using guizero library in loop function
text4 = Text(app, "xx", grid=[5, 0]) # creation of text
def loop():
recents = read('recents') # views content of array in log.json file
text4.value = recents[-1]["value"] # sets text element to value of the array's last element
If changes are made to main.py or userinterace.py and it is no longer running on startup, go into cmd and cd into the files path. Then run these commands:
chmod +x main.py
chmod +x userinterface.py