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)
Baud değil, voltaj sorunu. -9 V ölçtüysen zaten cevap orada.
RS-232 sinyali yaklaşık ±3 ile ±15 V arası ve mantığı ters: boşta negatif, “1” negatif, “0” pozitif. Pi’nin UART’ı ise 3.3 V TTL, 0 ile 3.3 V arası ve düz mantık. Doğrudan bağlayınca hem seviye hem polarite yanlış, çıktıdaki çöp tam olarak bu. Üstelik GPIO15’e negatif ve 9 V civarı gerilim vermek pini öldürebilir. Hemen sök, Pi’nin hâlâ sağlam olması şans.
Bende iki depoda aynı iş var, iki yol kullandım:
1. MAX3232 modülü (MAX232 değil, 3232; 3.3 V ile çalışan). VCC’yi Pi’nin 3.3 V’una ver, TTL tarafı GPIO14/15, RS-232 tarafı DB9’a. 2. Daha temizi: USB-RS232 çevirici (PL2303 ya da FTDI çipli). /dev/ttyUSB0 olarak çıkıyor, GPIO ile hiç uğraşmıyorsun.
Login ekranı meselesi: Pi seri konsolu /dev/serial0 üzerinden açık. raspi-config > Interface > Serial Port’ta “login shell over serial” sorusuna Hayır, “serial port hardware” sorusuna Evet de.
Bir de TX/RX çaprazlaması: gösterge DCE mi DTE mi bilmiyoruz. Veri gelmezse 2 ile 3’ü yer değiştir.
Okuduktan sonra Hermetry’ye gönderme kısmı basit, paho ile access token’la v1/telemetry‘ye yayınlıyorsun:
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)

