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:
- I have the configured the ttyS0 on my RPi.
- I can see ttyS0 if I do
ls /dev -l
cat /dev/ttyS0
- opens a connection, not getting I/O error- Ive scanner RX (IN) connected to RPI TX (Out)
- Ive scanner TX (OUT) connected to RPI RX (IN)
- 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?
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:30Enable 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:32I've added:
import serial
serialport = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=3.0)
– MrServer Sep 07 '19 at 14:34while True: serialport.write("rnSay something:") rcv = serialport.read(10) serialport.write("rnYou sent:" + repr(rcv))
(2) TTL232 Factory Defualt https://imgur.com/gallery/2NzmxDd
– tlfong01 Sep 08 '19 at 01:08