Pet hospitals use veterinary scale such as the Weight South VS-2501 for weighing small to large animals. A hospital associate would guide the pet to the scale, read the weight from the scale panel, and type it into the medical record system. What if we want to integrate the scale into various technology projects, such as streaming the output on larger screen displays or automatically capturing the data as part of the electronic medical record systems? Here is what I did as an experiment with the Weight South VS-2501 scale.
The VS-2501 scale has a display housing with 1 inch LED digits to allow easy viewing of the scale output from a distance. It is mainly used for reading out the results just like a traditional weight scale. In the back, a 3 pin RS-232 serial port is found. Note that the brochure shows a 9-pin serial, which makes it more likely that the port was later switched to a standard 9-pin serial. My goal was to first connect through the RS232 port, then determine the format of the data that I can capture through the interface, and finally come up with some initial code that would consume the data.
VS 2501 Front Panel
VS 2501 Back Panel
What I then set up to do is:
- create a cable with a 3-pin round connector, from one side, and a standard 9-pin serial connect from the other side. The cable would map 3-pins (TX, RX, and GRND) from the VS2501 RS232 socket to 3 pins (pin 2 - Receive Data, 3 - Transmit Data, and 5 - Signal Groud) in the serial connector.
- plug the cable between the weight scale and a Raspberry PI then execute some code to capture the results of the weight scale automatically.
Making the 3-pin RS232 to a 9-pin Serial cable
First I ordered an $8 HxChen 3pin metal Male Female Panel connector and then soldered the pins to connect with the respective pins onto the weight scale.
VS 2501 Circuit and the RS 232 component
From the circuit image above, the RS232 component has a 3-wire connection: Green is TX (Transmit Data), Red is RX (Receive Data), and black GRND (common ground). Those can then be mapped on to the aviation 3-pin connector as pin 1 - TX, pin 2 - RX, and pin 3 - GRND. The DB 9 connector for a serial connector shows pin 2 for RX, pin 3 for TX, and pin 5 for GRND. With that in mind, I built my custom adapter that interfaces between the 3pin RS232 and a traditional 9pin serial connector (photo below).
After that I used another $8 USB to serial adapter, Benfei USB to RS-232 Male 9-pin DB9 Serial, which includes a chipset that converts serial to USB signals and vice versa.
Note: I previously experimented with ADAFRUIT Industries 954 USB-to-TTL Serial Cable, Anmbest 2PCS MAX3232 3.3V to 5V DB9 Male RS232 Serial Prot to TTL Converter, Ableconn PI232DB9M Compact GPIO TX/RX to DB9M RS232 Serial Expansion Board for Raspberry Pi, and StarTech.com 1 Port USB to Serial RS232 Adapter - Prolific PL-2303 - USB to DB9 Serial Adapter Cable - RS232 Serial Converter ICUSB232V2. With the first 3, I had to use the GPIO in the Raspberry PI while the cable ones were more practical because they were simply external USB connectors.
The final cable is shown below:
Preparing the Weight Scale Panel & the Raspberry Pi
I first did the setup work using my primary Raspberry PI 4 before I replicated the work on the cheaper and smaller version, the Raspberry PI Zero W. My thought that a cheaper $5 or $10 Raspberry Pi Zero is more than enough for capturing data signals from the weight scale. I am not going to go through the process of setting up a Raspberry PI here. You can follow the instructions at the link Raspberry Pi Setup Instructions. A Raspberry Pi needs a power adapter and other necessary components to make it more practical in projects, so I purchased the Vilros Raspberry Pi Zero W Starter Kit for $29. It included a lot of items:
- Pi Zero W - Featuring :802.11 b/g/n wireless LAN-Bluetooth 4.1-Bluetooth Low Energy (BLE)
- 2.5A Power Supply Designed for Raspberry Pi-HDMI-Mini HDMI Adapter-Micro USB OTG
- Premium Black Case with 3 Covers-1 Closed Cover-1 with GPIO Access Cover-1 with Camera Mount Cover
- 40 Pin Header—Heat sink for Raspberry PI Zero–Camera Module Adapter
Photo below is the photo of such asn amazing small computer with all the wiring connected including the cable that I made.
Hooked Up the Raspberry PI with the Weight Scale
Note: a key step in the process is to enable Serial access in the Raspberry PI. Instructions of how to enable serial port is found here.
Once I completed setting up the Raspberry PI, i checked through its terminal to see if it can recognize the USB to Serial connector. The last row in the image photo below shows that the Raspberry Pi identified the USB to Serial connector and saw it hooked up to the USB device ttyUSB0.
I came to find out (the hard way) that the RS232 interface in the weight scale is disabled by default. Moreover, there are some settings that I need to setup using the LED panel. I did not know all that at first, so I spend hours testing everything with no success. At one point it was the disabled port. At another point, it was the incorrect wiring on the circuit. But that don’t matter now.
The VS-2501 Instruction Manual shows the steps to make menu changes.
Menu item: C18 Serial Interface configuration:
0: close serial connection 1: continuous sending, connect big display 2: print method, connect printer 3: command request method, connect computer 4: PC continues sending format, connect computer <— SELECT THIS ONE 5: PC / big display continues sending format
Menu Item: C19 Baud Rate: 0=1200 / 1=2400 / 2=4800 / 3=9600 <– SELECT number 3
Now that the weight scale panel is set as Menu 18 Option 4 and Menu 19 Option 3, we are ready to connect!
I wrote the following Python code and uploaded it to the Raspberry Pi:
#!/usr/bin/env python3 import time import serial import time ser = serial.Serial( port='/dev/ttyUSB0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=None ) output="" while 1: x=ser.read() time.sleep(1) data_left = ser.inWaiting() x += ser.read(data_left) if x: print (x)
ran the code, and it worked!
Note that it did not perfectly work from the first time. I went through various frustrating moments. The first one was when nothing would come out from the code. I was having a hard time determining if my system is recognizing the weight scale or not. With all the Googling and soul searching, I could not find my answers until I went back through the VS-2501 manual and come to discover that the RS232 port was disabled! Once I enabled the port using the display menu, as mentioned above, I started getting gibberish data from the weight scale. I went through a process of elimination where I tried every one of the menu options under C18 menu and different baud rates under C19 menu. No success. Even though each option under the menu item C18 generated different type of output, the data returned was always gibberish. At one point, I thought that the gibberish data may be related to bad character set encoding and decoding, So I started experimenting with binary to ASCII conversions, sending data signals to the weight scale and deciphering the output. Yet, no success. I was giving up, until, one afternoon, I decided to call the vendor Weight South.
I got hold of a person whose first asked me “which hospital are you calling for”. I told her that I am part of Banfield IT and I am doing an experiment with the weight scale. She then connected me to a technician named Charlie. He told me that I should have C18 Option 4 and C19 Option 3 in the VS-2501 menu setup, and the serial connection should have parity=none, stopbits=one, bytesize=8, which what I already have. He was kind and very helpful. He told me that no one tried connecting the scale to a Raspberry Pi before. They usually connect it to a printer or a some software in Windows. I guess I was the first! Cool, but only if I can get it working! Anyway, his recommendation did not help because it happened to be the same as I had setup. But, at least, it confirmed that my settings are all correct. The code was always returning gibberish data from the weight scale, no matter what I did - different serial cables, soldering a new cable, testing the resistance and voltage with my multimeter, coming up with new code, restarting everything, and more. Later that afternoon, I took a step back, unplugged everything, felt I was defeated, and went on with my day.
Later that night, and out of the blue, an idea hit me. What if the RS232 wiring were incorrectly connected. Instead of the RED cable connecting to the TX pin and the GREEN cable connected to the RX port inside the VS-2501 circuit, what if we switch them? What if the manufacturer had incorrectly hooked up the RS232 component in the weight scale circuit. So I opened back the VS-2501 and rewired the RS232 connector by connecting the GREEN cable to the TX pin and the RED cable to the RX pin. I felt it was safe to do because I am only switching RX with TX data connections and voltage on the RS232 to USB cable is under control since serial to USB converter is controlling it. Worst case my $8 cable or my $10 Raspberry Pi will mess up. Not likely but that is the maximum that could happen.
Ran the code, and it worked! Every time, some one or some thing is on the scale, my code is capturing the weights beautifully!
With that, I now have a fully connected small computer device that we could use to leverage weight scale data into various projects. The next step is to now write some code that makes proper use of the weight scale data.