0

Printing Barcode Reader Data on LCD using Raspberry Pi
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Printing Barcode Reader Data on LCD using Raspberry Pi

by choudharyas on Mon Apr 26, 2021 4:27 am

Hi
I am trying to read Barcode Reader data over serial using Raspberry Pi and then print it on 16*2 LCD Display using Adafruit Char_LCD library. I was able to read the barcode data but when i tried to print it on LCD display it doesn't print the data on display. I am able to display int number, float and strings and it is displaying everything except Barcode Data.

The data that i am getting from Barcode reader is in Bytes and i need to convert it to String. So i used byte.decode("utf-8") and then tried to display it on LCD but no Luck.
can anyone tell me how can i display the barcode reader data on LED. Thanks

The code that i tried is given below:
Code: Select all | TOGGLE FULL SIZE
 
    import serial
    import string
    import RPi.GPIO as gpio
    import time
    import Adafruit_CharLCD as LCD

    port = "/dev/ttyAMA0"
    ser = serial.Serial(port, baudrate = 9600, timeout = 0.5)

    lcd_rs = 25
    lcd_en = 24
    lcd_d4 = 23
    lcd_d5 = 17
    lcd_d6 = 18
    lcd_d7 = 22
    lcd_backlight = 2

    lcd_columns = 16
    lcd_rows = 2

    lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows,
    lcd_backlight)

    while 1:

      data = ser.readline()
      print(data)
      lcd.message("Barcode:")
      lcd.message(str(data))
    time.sleep(2) 

choudharyas
 
Posts: 2
Joined: Mon Dec 09, 2019 4:47 am

Re: Printing Barcode Reader Data on LCD using Raspberry Pi

by mikeysklar on Mon Apr 26, 2021 6:52 pm

Are you seeing the barcode print out on the serial console?

Can you share an example barcode number you trying to use? I suspect this can be resolved by breaking down the barcode as individual digits 'int' or 'char' and sending them through. There might be a library function to assist.

mikeysklar
 
Posts: 4577
Joined: Mon Aug 01, 2016 8:10 pm

Re: Printing Barcode Reader Data on LCD using Raspberry Pi

by choudharyas on Tue Apr 27, 2021 12:53 am

mikeysklar wrote:Are you seeing the barcode print out on the serial console?

Can you share an example barcode number you trying to use? I suspect this can be resolved by breaking down the barcode as individual digits 'int' or 'char' and sending them through. There might be a library function to assist.


Yeah it is printing the Barcode number on console. The barcode number that i scanned is = "8906093330975". The output is in bytes format. So after converting it to string i tried to break it down using substring but it didn't print any substring.

choudharyas
 
Posts: 2
Joined: Mon Dec 09, 2019 4:47 am

Re: Printing Barcode Reader Data on LCD using Raspberry Pi

by mikeysklar on Tue Apr 27, 2021 5:12 pm

You following the right approach to try:

Code: Select all | TOGGLE FULL SIZE
lcd.message(str(data))


Since that is not working take a look at using other python specific methods like string.digits()

https://docs.python.org/2/library/strin ... ing-syntax

mikeysklar
 
Posts: 4577
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.