Reading Input from a Barcode Scanner using Python, a Raspberry Pi and Serial Port
Interacting with hardware such as a barcode scanner has become increasingly straightforward due to the evolution of Python and it’s many open-source libraries. In this article we will in particular focus on how to use Python, along with the PySerial library, to interact with a barcode scanner connected to a Raspberry Pi.
1. Prerequisites
- A Barcode Scanner: This could be any standard scanner, I’m using a mini scanner bought off Aliexpress
- A Raspberry Pi: You can use any computer, I am using a Raspberry Pi
- Python: Anything newer than Python 3.6, I am using Python 3.10
- PySerial: This is the library we will use to communicate with the reader
2. Setting Up the Barcode Scanner
For this tutorial we will be using the scanner in serial mode. Most scanners typically come with a manual full of barcodes that when scanned change the device settings, though it’s possible yours will default to serial mode.