How to Build C/C++ Barcode Reader App on Raspberry Pi 4

Raspberry Pi 4 Specifications

  • Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
  • 2GB, 4GB or 8GB LPDDR4–3200 SDRAM (depending on model)
  • 2.4 GHz and 5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE
  • Gigabit Ethernet
  • 2 USB 3.0 ports; 2 USB 2.0 ports.
  • 2 × micro-HDMI ports (up to 4kp60 supported)

My Hardware Components

Raspberry Pi OS Installation and Configuration

Installation

  1. Download Raspberry Pi OS.
  2. Write the OS image to an SD card with Win32 Disk Imager.
  3. Insert the SD card into Raspberry Pi 4 and connect to power via USB-C connector (minimum 3A*).

Configuration

sudo apt updatesudo apt install tightvncserver xrdp
df -HFilesystem      Size  Used Avail Use% Mounted on/dev/root        32G  8.9G   21G  30% /devtmpfs        1.9G     0  1.9G   0% /devtmpfs           2.1G     0  2.1G   0% /dev/shmtmpfs           2.1G  9.1M  2.1G   1% /runtmpfs           5.3M  4.1k  5.3M   1% /run/locktmpfs           2.1G     0  2.1G   0% /sys/fs/cgroup/dev/mmcblk0p1  265M   54M  211M  21% /boottmpfs           405M  4.1k  405M   1% /run/user/1000
sudo raspi-config

OpenCV Installation

sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libjpeg-dev libpng-dev libtiff-dev
mkdir buildcd buildcmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_GENERATE_PKGCONFIG=ON ..make -j4sudo make install

C/C++ Barcode Reader Project

cd /home/pimkdir raspberry-pi-cpp-barcode
link_directories("${PROJECT_SOURCE_DIR}/platforms/linux/")find_package(OpenCV REQUIRED)include_directories("${PROJECT_BINARY_DIR}" "${PROJECT_SOURCE_DIR}/include/")add_executable(BarcodeReader ssd1306_i2c.c BarcodeReader.cxx)target_link_libraries (BarcodeReader "DynamsoftBarcodeReader" ${OpenCV_LIBS} wiringPi)
mkdir buildcd buildcmake ..cmake –build ../BarcodeReader

How to AutoStart Programs

#!/bin/sh/home/pi/raspberry-pi-cpp-barcode/build/BarcodeReader
chmod a+x autostart.sh
[Desktop Entry]Type=ApplicationExec=sh /home/pi/autostart.sh
sudo reboot

Source Code

--

--

--

Manager of Dynamsoft Open Source Projects | Tech Lover

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

If You Start Working As a Developer, Don’t Make These Mistakes

Firebase Android Codelab

Architecture behind a Web Scraper that runs on the AWS Cloud

APACHE SPARK-RDD

Create API Rest with Laravel 7 Passport Authentication (Part 1)

Is it Possible for a Code to be “Dirty”?

Crash Course in HTTP Requests Using Python

How to connect Python and IBM Database

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Xiao Ling

Xiao Ling

Manager of Dynamsoft Open Source Projects | Tech Lover

More from Medium

The differences between static and dynamic libraries in C.

How to build OpenCV with Cuda and cuDNN support in Windows

Scripting LCD on Wio Terminal with ArduPy

Programming a pothole detector in Python and deploying a TFLite model on Raspberry Pi 4