Im having some issues reading from a barcode scanner module.. The scanner works just fine if it is used with a USB adapter, my goal is to use the RX & TX GPIO of my RPi to control it.

What I am trying to do is something similar to this:


My problem is that I am not getting any data after scanning the barcodes.

This is what I have done so far:

  1. I have the configured the ttyS0 on my RPi.
  2. I can see ttyS0 if I do ls /dev -l
  3. cat /dev/ttyS0 - opens a connection, not getting I/O error
  4. Ive scanner RX (IN) connected to RPI TX (Out)
  5. Ive scanner TX (OUT) connected to RPI RX (IN)
  6. wrote small python file to read and write info on the screen:
import serial
import time 

port = serial.Serial('/dev/ttyS0')
while True:
    port.write("Say something:\n")
    rcv = port.read(10)
    port.write("rnYou sent:" + repr(rcv))

Any ideas on what I might be missing?

  • So your program in Step 7 does not seem to work. I would suggest two things: (1) Modify your program to do a loopback test, to make sure the wiring etc is OK. (2) Instead of the python program, use a terminal emulator (I would recommend SuperTerm, as recommended by SparkFun), to input something, say "AT<new Line>" to the barcoder, and see if there is something back, hopefully "OK <newline>. If your have something in something out, then it is time to run your python program. If you have no experience on testing UART loop back, let me know and I can show you a newbie version.
    – tlfong01
    Sep 7 '19 at 1:59
  • you might find my answer to a similar question helpful: raspberrypi.stackexchange.com/questions/102239/…
    – tlfong01
    Sep 7 '19 at 2:01
  • @tlfong01, I don't have any experience on testing UART.. my main issue is that I am not getting any data when scanning the barcodes..
    – MrServer
    Sep 7 '19 at 3:25
  • 1
    Link to barcode scanner? Photo of connections? OS being used? Listing of /boot/config.txt?
    – joan
    Sep 7 '19 at 4:40
  • 1
    The code you posted does not read anything from the serial link. It just (needlessly) writes.
    – joan
    Sep 7 '19 at 11:37

Thank you tlfon01, you pointed me on the right direction. I ended up solving this problem by disabling the BT, and using ttyAMA0 instead of ttyS0.

  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Feb 10 '20 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.