How to read data from weighing scale in raspberry pi via RS232 to USB

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
ahmedrao
Posts: 1
Joined: Sat Oct 26, 2019 5:06 am

How to read data from weighing scale in raspberry pi via RS232 to USB

Post by ahmedrao » Sat Oct 26, 2019 6:11 am

Hi everyone,
I am trying to read data from weighing scale YH-T7E using raspberry pi via RS232 to USB cable in pyhon. However, when I am reading the data via it gives me empty string.

Here is my code:

Code: Select all

mport serial
import time
ser = serial.Serial('/dev/ttyUSB2',
					baudrate=9600,
					parity=serial.PARITY_EVEN, 
					stopbits=serial.STOPBITS_ONE,
					bytesize=serial.SEVENBITS,
					timeout = 1)

while True:
	print(ser.read())
The output of above code is:

Code: Select all

b''
I have also tried:

Code: Select all

while True:
	data = ''
	while ser.inWaiting() > 0:
	data += ser.read()
	if data:
		print("Received: ", data)
And output of this code is nothing since it keeps on waiting.

Can someone please give me some guidance.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to read data from weighing scale in raspberry pi via RS232 to USB

Post by Roberthh » Sat Oct 26, 2019 6:57 am

Even if this is not the forum for issues with RaspBerri pi, I hooked up my RasPi and tested it. The following slightly modified test code works for me:

Code: Select all

import serial
import time
ser = serial.Serial('/dev/ttyUSB0',
    baudrate=9600,
    parity=serial.PARITY_EVEN, 
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.SEVENBITS,
    timeout = 1)

while True:
    ser.write(b"blabla")
    time.sleep(0.1) # wiat for the data to get sent
    print(ser.read(ser.in_waiting))
    time.sleep(1)
I connected a USB/Serial bridge, which showed up as /dev/ttyUSB0, and made a loopback between TX and RX. So I can conclude that the RasPi side works, and that there is some other issue. Possibly:

- wrong /dev/ttyUSBx device
- TX and RX not properly assigned
- the YH-T7E is not sending data at all
- the YH-T7E tries to send, but needs a handshake signal, which is not present (RTS)

Post Reply