I have a raspberry pizero W that is connected via GPIO pins to a flowmeter and USB to a barcode scanner. I have python script that uses a callback function to be alerted when the GPIO input is sensed. This python script needs to be continuously running on the pizero in order to recognize when the flowmeter is activated and process the input.
The problem is that I also have a barcode scanner attached via USB to the pizero. I would like the pizero to also recognize when a barcode is scanned and process that input as well.
The pizero should then send a message that incorporates both information from the flowmeter and information from the barcode scanner.
Is there a way to do this in the same python script? How can I have the pizero listen and process from two inputs simultaneously? Would separating this into two different scripts be easier to implement, and if so, can I run them both at the same time and somehow unify the information they provide in a 3rd continuously running script?
Thank you!
Some clarifications per comments (thank you for the input):
- input pin from the flowmeter is
GPIO 17
which is an SPI connection - also have a 5V power and ground pin connected.
The script needs to be run at system startup. I will look at systemctl
as I hadn't heard of it until it was mentioned.
The Pi normally recognizes a barcode being scanned as keyboard input (i.e. a series of digits followed by a newline character) when the flowmeter is not attached.
When I send a message that includes the flowmeter and barcode information, I need to send a JSON object from python that includes both pieces of information and a time stamp of when the information was received.
This JSON object will be sent over wifi to a raspberry pi server with a static ip on the same home network as the pizero. The raspberry pi server has access to a Django database that should incorporate the JSON object information into the database.