Raspberry Pi Barcode Scanner with GPIO

Previously, I shared two articles demonstrating how to build a Raspberry Pi barcode scanner in C/C++ with Dynamsoft Barcode Reader SDK, and how to optimize the code with thread. The hardware I used only includes Raspberry Pi 2 and Webcam. Now it is time to have fun with GPIO (General-purpose input/output). Assume you want to get rid of the display screen for making a robot with power bank, wheel, and webcam. And you need to use some indicators to monitor the status of barcode recognition. How to make it with GPIO pins and other peripherals?

raspberry pi GPIO and LED

Compose the GPIO Circuit and Blink LED in Python

To get started with Raspberry Pi physical interface, it is recommended to read the official tutorial.

With an LED, a resistor and jumper leads, we can compose a simple GPIO circuit :

GPIO circuit

GPIO Zero is a pre-installed Python library for controlling GPIO components. With the library, we can easily flash the LED on and off at run-time in Python:

from gpiozero import LED
from time import sleep

led = LED(17)

while True:

Improve Raspberry Pi Barcode Scanner with GPIO in C/C++

Do you want to use the above code? Although you can make a Python wrapper for Dynamsoft Barcode Reader SDK, it is better to use a GPIO access library written in C – WiringPi.

Install WiringPi with following commands:

git clone git://git.drogon.net/wiringPi
cd wiringPi

Here is the simplest blink program with WiringPi:

#include <wiringPi.h>
int main (void)
  wiringPiSetup () ;
  pinMode (0, OUTPUT) ;
  for (;;)
    digitalWrite (0, HIGH) ; delay (500) ;
    digitalWrite (0,  LOW) ; delay (500) ;
  return 0 ;

According to the API, we can update the source code of Raspberry Pi barcode scanner:

Raspberry Pi barcode scanner

When barcodes detected, flash the LED with:

digitalWrite(0, HIGH); 

Here is the demo video:

If you are interested in Dynamsoft Barcode Reader SDK for Raspberry Pi, contact support@dynamsoft.com.

Source Code