New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

I connected the RS-232 output of an old weighing indicator directly to the Pi 4 GPIO, and weird characters are coming through

I connected the RS-232 output of an old weighing indicator directly to the Pi 4 GPIO, and weird characters are coming through

Solved 5 4

Translated from Türkçe by AI ·

Hi, I’m a software developer and the hardware side is a bit foreign to me, so tell me if I’m talking nonsense.At a customer’s warehouse entrance there is an old scale indicator with a DB9 RS-232 output on the back. According to the manual, it prints the weight line by line on every weighing. My goal is to read this with a Raspberry Pi 4, send it to Hermetry as telemetry, and then show the daily tonnage on a dashboard.What I did: I connected pins 2, 3 and 5 of the DB9 with jumper wires to the Pi’s GPIO14 (TX), GPIO15 (RX) and GND pins. I enabled serial from raspi-config. In Python I read it like this:

import serial
s = serial.Serial('/dev/serial0', 9600, timeout=2)
while True:
    print(s.readline())

The output looks like this:

b'ùæ þ'
b'ø '
b'àþ'

There is nothing meaningful in it. Also, every now and then a terminal shows something like my own login screen, and I didn’t understand that either. I’m also not sure whether I’ll burn out the indicator or the Pi, since I measured something like -9 V on the indicator output with a multimeter.

Ağ geçidi yine bağlanıyor…
♥ 2

Translated from Türkçe by AI ·

Is the baud rate correct? It could be 4800 or something like that in the indicator’s menu.

♥ 0

Translated from Türkçe by AI ·

I checked the menu, it says 9600 8N1. The manual says so too.

Ağ geçidi yine bağlanıyor…
♥ 1

Translated from Türkçe by AI ·

It’s not the baud rate, it’s the voltage. If you measured -9 V, the answer is already there.An RS-232 signal swings roughly ±3 to ±15 V and its logic is inverted: idle is negative, “1” is negative, “0” is positive. The Pi’s UART, on the other hand, is 3.3 V TTL, 0 to 3.3 V, with normal logic. Connecting them directly gets both the level and the polarity wrong, and that garbage in the output is exactly what you’d expect. On top of that, applying a negative voltage and around 9 V to GPIO15 can kill the pin. Disconnect it right away; it’s luck if the Pi is still intact.I’ve done the same job in two places and used two approaches:1. MAX3232 module (MAX3232, not MAX232; it runs at 3.3 V). Feed VCC from the Pi’s 3.3 V, TTL side to GPIO14/15, RS-232 side to the DB9. 2. The cleaner option: a USB-RS232 adapter (PL2303 or FTDI chip). It shows up as /dev/ttyUSB0 and you don’t have to deal with GPIO at all.About the login screen issue: the Pi’s serial console is open on /dev/serial0. In raspi-config > Interface > Serial Port, answer No to “login shell over serial” and Yes to “serial port hardware”.And about TX/RX crossing: we don’t know whether the scale is DCE or DTE. If no data arrives, swap pins 2 and 3.Sending the data to Hermetry after that part is simple: using paho with an access token, you publish to v1/telemetry:

import re, json, serial
import paho.mqtt.client as mqtt

c = mqtt.Client(client_id="kantar-1")
c.username_pw_set(TOKEN, "")
c.tls_set()
c.connect(BROKER_HOST, 8883, keepalive=60)
c.loop_start()

s = serial.Serial('/dev/ttyUSB0', 9600, timeout=2)
while True:
    line = s.readline().decode('ascii', 'ignore')
    m = re.search(r'(-?d+.d+)s*kg', line)
    if m:
        c.publish("v1/telemetry", json.dumps({"weight_kg": float(m.group(1))}), qos=1)
Kayıtta yoksa olmamıştır.
Accepted solution♥ 8

Translated from Türkçe by AI ·

Converting it to a number with a regex is important. If the indicator prints text like " 12.45 kg" and you send it as is, it stays as text in Hermetry, is not plotted on the chart, and no hourly average or total comes out. In one project we sent text for two weeks, and when we noticed, the historical data was useless.

♥ 0

Translated from Türkçe by AI ·

Solved, thanks.I couldn’t find a USB-RS232 converter, so I got a MAX3232 module from the electronics guy. I connected it, still got garbage, then as Esra said I crossed pins 2 and 3, and the lines started coming in properly. I also turned off the serial console, the login screen disappeared. GPIO15 also came out fine, I got lucky.Thanks to Tuğba’s note, weight_kg is going out as a number from the very start, and it’s being plotted as a graph on the dashboard.

Ağ geçidi yine bağlanıyor…
♥ 0
Viewing 6 posts – 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Join the conversation

Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

Share