0

I am a beginner to this,

I have a balance (scale) that I need to read the data (weights of material) from. Data will be read every 10 seconds and I have looked up RS232 codes in here and utilised below code.

I have connected the balance (scale) to the Pi using a serial to USB cable

import serial

port =serial.Serial(

   "/dev/ttyUSB0",
   baudrate=9600,
   parity=serial.PARITY_NONE,
   stopbits=serial.STOPBITS_ONE,
   bytesize=serial.EIGHTBITS,
   writeTimeout = 0,
   timeout = 10)

print(port.isOpen()) 
print(port.readable())
print(port.get_settings())
while True:


 response=port.read(8)
 print(response)

but as the output all I`m getting is
b''

in the balance manual I have below information,

 INTERFACE 
 RS232 Connection             
 Balance (9pins)             PC(9 pins)
 RXD(Input)  2 -----------------3
 TXD(Output) 3 -----------------2
 GND(Ground) 5 -----------------5

 Default Baudrate 9600
 Data format 10bits,0 as start bit,1as stop bit,8digits (ASCII code)
 Ritybit, No.

Thanks in advance you all.

enter image description here

  • Could you edit the question and add a link to the interface specs of the balance? We need details of how it is controlled and what it returns. – joan Feb 27 at 8:11
  • Do you have the crossover in place, as indicated by the connection diagram from the manual? (Pin 2-3, 3-2.) The manual also indicates 10 bits - which I don't understand as it indicates there are 8 data bits, 1 stop and no start or parity, so that makes 9. You might do well to connect the USB adapter to a PC and fiddle around to find the right combination of settings and wiring using a terminal program, then transfer to code when you have it working. – Mark Smith Feb 27 at 8:25
  • @joan I have added the specs from the balance – DrakonianD Feb 27 at 8:41
  • Also, do you know what format you expect the data in? Your code sort of assumes it will be printable characters - maybe that's a reasonable assumption, I don't know. Do you have to send anything to get a response or will the device just send data all the time, unprompted? Again a terminal program would let you experiment. – Mark Smith Feb 27 at 8:43
  • @MarkSmith 10 bits per byte is pretty normal. 1 start, 8 data, 1 stop. – joan Feb 27 at 10:35

Your Answer

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

Browse other questions tagged or ask your own question.