-1

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:

https://www.rtscan.net/raspberry-pi-barcode-scanner/

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')
#port.baudrate=9600
while True:
    port.write("Say something:\n")
    rcv = port.read(10)
    port.write("rnYou sent:" + repr(rcv))
    time.sleep(0.10)

Any ideas on what I might be missing?

MrServer
  • 1
  • 1
  • 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" to the barcoder, and see if there is something back, hopefully "OK . 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 07 '19 at 01:59
  • you might find my answer to a similar question helpful: https://raspberrypi.stackexchange.com/questions/102239/response-to-a-incoming-call-using-python-script – tlfong01 Sep 07 '19 at 02: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 07 '19 at 03:25
  • Ah, let me see. I remember another barcode hobbyist asked the same question and my answer seems to have helped him. https://raspberrypi.stackexchange.com/questions/96562/usb-barcode-scanner-serial-wont-work-just-freezes-hangs – tlfong01 Sep 07 '19 at 03:35
  • Your might to let me know more about your setup, such as which model are your using, do you use the Rpi UART pins, or a USB serial cable etc. Another answer might also help. https://raspberrypi.stackexchange.com/questions/96232/connect-camera-ttl-serial-to-raspberry-pi – tlfong01 Sep 07 '19 at 03:44
  • 1
    Link to barcode scanner? Photo of connections? OS being used? Listing of /boot/config.txt? – joan Sep 07 '19 at 04:40
  • 1
    The code you posted does not read anything from the serial link. It just (needlessly) writes. – joan Sep 07 '19 at 11:37
  • Thank you @tlfong01, I am using a RPi 3b+. The scanner pin output is on this link: https://www.rtscan.net/raspberry-pi-barcode-scanner/. – MrServer Sep 07 '19 at 14:23
  • I am using pin4 & 5 of the scanner to connect to PIN14 & 15 of my PI. i am connecting the scanner RX to my PI TX, with I/O setup as OUT, and the scanner TX to my PI RX with I/O setup as IN. I also followed this link [https://www.circuits.dk/setup-raspberry-pi-3-gpio-uart/] to configure the ttyS0. The barcode scanner works perfectly when using the USB cable, but I need it to be connected to the GPIO pins. The barcode supports multiple interfaces like USB virtual serial mode and UART, I have tried them both, and got the same results. hope this helps! – MrServer Sep 07 '19 at 14:30
  • @joan here is the link [https://tinkersphere.com/sensors/2896-barcode-scanner-ccd-camera-ttl-arduino-raspberry-pi-compatible.html] of the scanner. – MrServer Sep 07 '19 at 14:31
  • @joan last lines fo confit.txt # Additional overlays and parameters are documented /boot/overlays/README # Enable audio (loads snd_bcm2835) dtparam=audio=on # NOOBS Auto-generated Settings: hdmi_force_hotplug=1 start_x=1 gpu_mem=128 enable_uart=1 #dtoverlay=pi3-disable-bt dtoverlay=pi3-miniuart-bt – MrServer Sep 07 '19 at 14:32
  • I made changes to the script to read from serial. I've added: import serial serialport = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3.0) `while True: serialport.write("rnSay something:") rcv = serialport.read(10) serialport.write("rnYou sent:" + repr(rcv))` – MrServer Sep 07 '19 at 14:34
  • @MrServer, Your user manual looks good. I think I would let you test your program first and see how it goes. In the mean time I would go along very slowly. I would suggest to try solution 1. https://imgur.com/gallery/LtcQZi0. It is bed time for me now. So see you tomorrow or day after tomorrow. Good luck. – tlfong01 Sep 07 '19 at 14:49
  • Could you edit your question and include all the new information you have added to the comments? People don't always look at the comments. – joan Sep 07 '19 at 14:50
  • @MrServer, One important question. Did you say you tried the USB cable solution and found it OK? Then why you are trying GPIO UART now? I think USB cable connection is safer than GPIO connection. Anyway, good night and see you later. – tlfong01 Sep 07 '19 at 14:56
  • @MrServer, Before I go to bed, the bible if you have not got it. https://www.rtscan.net/wp-content/uploads/2019/01/RT206_207_208_209Programming_Command_Manual.pdf – tlfong01 Sep 07 '19 at 15:04
  • Thanks a lot @tlfong01! going with solution 1 first. Yes, the scanner came with a USB to RJ45 adapter that includes the buzzer and led, it also have the 12 pin 0.5mm connector for the scanner. I tested and it worked just fine. The reason I want to use the GPIO is that I have other plans for the USB ports, and maybe ( just a maybe) moving to a PI Zero in the future. – MrServer Sep 08 '19 at 00:33
  • @MrServer, Ah I see. I wrongly thought that your "USB" cable was a USB to UART/serial adapter cable. In that case USB UART is very similar to Rpi GPIO UART. Actually your USB cable is USB to RJ45, with 12pin connector and buzzer/led. so I agree with you that it is reasonable to try the GPIO UART first. If you find your program working, you might also consider two things: (1) Use 按USB to serial cable to replace the GPIO serial cable, this make wiring tidier, (2) Add your own buzzer and led , which I think you should, otherwise your customers would LOL at your deaf and blind scanner. – tlfong01 Sep 08 '19 at 00:44
  • @MrServer, Now I have skimmed through both bibles and found everything looking OK. So I will now take a break and leave you debugging your code. Good Luck. (1) RT206/RT207/RT208/RT209 OEM 2d Scan Engine User Guide - RTscan https://www.rtscan.net/wp-content/uploads/2019/01/RT206_207_208_209User_Manual_2018.pdf (2) TTL232 Factory Defualt https://imgur.com/gallery/2NzmxDd – tlfong01 Sep 08 '19 at 01:08
  • @MrServer, I forgot two things. (1) Which model you are using? (2) I found that RTscan's R&D office seems hiding somewhere in my city. So I can GPS and knock at their door for tech support, ... :) – tlfong01 Sep 08 '19 at 01:12
  • Possible duplicate of [How do I make serial work on the Raspberry Pi3 , Pi3B+, PiZeroW](https://raspberrypi.stackexchange.com/questions/45570/how-do-i-make-serial-work-on-the-raspberry-pi3-pi3b-pizerow) – Dmitry Grigoryev Sep 13 '19 at 06:41

1 Answers1

0

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.

MrServer
  • 1
  • 1
  • 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