🚀 โปรเจกต์สแกนบาร์โค้ดด้วย Raspberry Pi 🚀

🚀 Raspberry Pi Barcode Scanning Project 🚀

, by Global Pi GTI, 2 min reading time

✅ Summary Scan barcode → Record video → Scan again → Save to USB Use Picamera2 to record video. Support 720p video and save files as MP4. Set to run automatically when the device is turned on. 💡 Ready to use! 🎉 If you are interested in more information or to order Raspberry Pi devices and barcode scanners, please visit our website for more details!


We will use Raspberry Pi to easily control the scanning and recording of videos, and save the files to a USB Drive immediately.

🔧 Raspberry Pi installation and setup steps

  1. Update your system and install the required packages. Open Terminal and type this command:

     sudo apt update && sudo apt upgrade -y
     sudo apt install python3-pip python3-opencv libopencv-dev ffmpeg -y
  2. Enable Raspberry Pi Camera Run the command:

     sudo raspi-config

    Then go to:

    • Interface Options → Camera → Enable.

    • Interface Options → Legacy Camera → Enable (for new Raspberry Pi OS)

    Then reboot your device:

     sudo reboot
  3. Install Python Libraries Install the required libraries:

    pip3 install opencv-python numpy imutils pyzbar picamera2



    📜 Python code for scanning barcodes and recording videos

    We will use the code below to scan barcode and record video:

    • Get the first barcode

    • Record 10 seconds of video

    • Get the second barcode

    • Name the video file as "barcode+datetime.mp4".

    • Save the file to a USB drive

    Running code

    After setting everything up, run the code with this command:

     python3 barcode_video.py

    📌 Check USB Drive

    Check if the USB Drive is connected:

     lsblk

    If it is not mounted automatically, run this command:

    sudo mount /dev/sda1 /media/pi/USB

    🔄 Set to run automatically when the device is turned on.

    To make the program run as soon as the Raspberry Pi is turned on:

    1. Open the rc.local file:

     sudo nano /etc/rc.local
    1. Add this line before exit 0 :

     python3 /home/pi/barcode_video.py &
    1. press CTRL + XY → Enter

    🚀 System Test

    1. Plug in the barcode scanner and USB drive.

    2. Open Terminal and run:

    python3 barcode_video.py
    1. Scan the barcode twice and check if the video file is saved to the USB Drive.

    🎯 Precautions

    • Check if the barcode scanner is a HID Keyboard.

    • If using multiple USBs, you may need to adjust USB_PATH to match the mount location.

    • The video resolution can be changed in the record_video() function.

Tags


Blog posts

© 2025 บริษัท โกลบอลโทรนิค อินเตอร์เทรด จํากัด, Powered by Shopify

  • PayPal

Login

Forgot your password?

Don't have an account yet?
Create account