How to connect a barcode scanner to your Node-RED application
A guide to connecting a barcode scanner to Node-RED.
Barcode scanners, functioning as Human Interface Devices (HID) similar to keyboards, offer versatile programming options. Variations of barcode scanners can be seen used from anything from checkout counters, logistics, and to manufacturing erp systems. In our case, we kept it basic and we used one to trigger a Node-RED flow, keeping the process straightforward and efficient. Don't let that limit your imagination though, with QR codes, you can store just about anything including recipes in a JSON structure.
# Configuring the scanner and scanning barcodes
We revitalized an older project for this purpose, ensuring it's up-to-date. For Windows users, the setup is straightforward. Start by importing the project, @gdziuba/node-red-usbhid, via the palette manager. Import these flows to get started. This initial flow identified as getHIDdevices will detect all devices connected to your Node-RED environment. Locate your barcode scanner in the debug output. You will see everything from your mouse and keyboard. If you have just recently added the barcode scanner to your computer, it will probably be found at the end. Once you find it note its Product ID and Vendor ID. For us, they would be identified as 1536 and 1504 respectively.
Next, configure the HIDdevice node: replace the default PID with your scanner’s Product ID, and the VID with its Vendor ID.
Test your barcode scanner against any barcode your scanner works with and you should observe an event being triggered in Node-RED and output to debug should be the contents of the barcode.
# Linux Setup
Linux users might face a slightly more complicated setup, as access to communication ports isn't always granted by default, and specific drivers are needed for optimal node functionality. This is due to the security around applications having access to specific devices connected to the system. For this, we recommend following the detailed instructions available in the project's GitHub repository.
At first this project seemed like it was going to be overly complicated, but after updating the node, it became incredibly easy. The way Node-RED is supposed to make it. Simple.
- Step-by-Step Guide to Deploying Node-RED with FlowFuse in balenaCloud
- Capture Data from edge devices with Node-RED
- Import a File into Node-RED with Dashboard 2.0
- Send a File to Node-RED
- Run Node-RED as a service on Windows