15. Barcode

15.1. Introduction

The most common one-dimensional code in daily life is the barcode on the various goods you buy. It is a graphic identifier that represents information using black and white stripes of different widths. A barcode usually consists of black bars and white bars of different widths arranged alternately (black absorbs all colors of light while white reflects all colors of light, giving very high contrast, so it is the most commonly used), and is designed according to specific encoding rules. The barcode on a product can carry all kinds of information about the product, and of course we can also directly encode byte information into a one-dimensional code.

15.2. Supported One-Dimensional Code Types

  • EAN2

  • EAN5

  • EAN8

  • UPCE

  • ISBN10

  • UPCA

  • EAN13

  • ISBN13

  • I25

  • DATABAR (RSS-14)

  • DATABAR_EXP (RSS-Expanded)

  • CODABAR

  • CODE39

  • PDF417

  • CODE93

  • CODE128

15.3. Python Example

Barcode
#mPythonType:0
from mpython import *
import smartcamera_k230 as smartcamera

smart_camera = smartcamera.SmartCameraK230(tx=Pin.P1, rx=Pin.P0)

smart_camera.model_init(23)

while True:
    smart_camera.bar_code.recognize()
    if smart_camera.bar_code.type != None:
        print(str('Barcode type: ') + str(smart_camera.bar_code.type))
        print(str('Barcode data: ') + str(smart_camera.bar_code.info))

15.4. mPython Graphical Example

../../../../_images/barcode_recognition.png