42

Create a DIY Raspberry Pi Bar Code Scanner

TOM TRAN / SYSTEMS LIBRARIAN, LIBRARY TECHNOLOGY DIRECTOR

Minnesota State University, Mankato Memorial Library

Type of Library Best Suited for: Any

Cost Estimate: $100

Makerspace Necessary? No

PROJECT DESCRIPTION

We will be configuring a Raspberry Pi camera module to read bar codes or QR codes. Libraries use different types of bar codes attached to books and other items. This project is great for students to learn Python programming, LINUX commands, and downloading and installing software.

OVERVIEW

In order to use the camera as a bar code scanner, you will learn how to configure the camera for the Pi. Participants will learn some general concepts of downloading LINUX software and installing it on the Pi. Participants will learn LINUX commands to configure software to read and translate bar codes and/or QR codes.

For this project, participants will be installing the SimpleCV software. SimpleCV is an image-processing software to perform image manipulation and recognition. Its scanner can read bar codes and QR codes. Participants will also be installing the ZBar library. ZBar is a module that provides an interface to the bar code reading library. And finally, participants will be installing User space Vide04LINUX (UV4L), which is a collection of modules for cross-platform drivers for audio and video streaming and output devices.

FIGURE 42.1

Raspberry Pi bar code scanner

The programming language we will be working with is Python, which is an easy-to-learn programming language. It can be used to create web pages, apps, and games. The Python script takes in the video feed from the camera and then compares it against the installed libraries to translate and display the bar code or QR code. The output will be displayed onto the screen

MATERIALS LIST

NECESSARY EQUIPMENT

STEP-BY-STEP INSTRUCTIONS

  1. 1. Enable the camera on the Pi
    1. a. Connect the camera to the Pi (see your owner’s manual)
    2. b. Boot up Pi
    3. c. Open the terminal window
    4. d. Type the following command at the prompt: sudo raspi-config
    1. e. The raspi-config window will pop up. Select Enable Camera
    2. f. On the next screen, “Would you like the camera interface to be enabled?” Enable the camera by selecting <Yes>
    3. g. The camera interface is enabled. Select <OK>
    4. h. Select <Finish>. The system will prompt you to reboot the Pi. Go ahead and reboot.
  2. 2. Installing SimpleCV on the Raspberry Pi
    1. a. Open the terminal window
    2. b. Type the following commands in the terminal window to download the necessary updates and dependencies
  3. You will be prompted to continue [Y/n], enter Y
  4. This will take a few minutes to install.
    1. c. Installing SimpleCV from github
    1. d. Installing svgwrite:
  5. 3. Installing the ZBar library
    1. a. Open the terminal window
    2. b. Install updates and install python-zbar
  6. 4. Installing uv41
  7. 5. Create your Python file, read.py
    • You will use the pico editor to create a Python file called read.py
    • Type the programming codes and save the file
    • Save the file and exit
    • ^O WriteOut
    • ^X Exit
  8. 6. Running the program
    1. a. Open the terminal window
    2. b. One way to run a Python script in the terminal window is to type the following command: python read.py

Place the bar code or QR code you want to scan in front of the camera. The bar code data or QR code will be displayed.

FIGURE 42.2

Sample QR code

LEARNING OUTCOMES

Through this project, participants will . . .

RECOMMENDED NEXT PROJECTS