Arduino Mega to Raspberry Pi 3 gateway over serial problems

  • Hello, I'm using an Arduino Mega to read my sensors and trying to send it to Raspberry Pi serial gateway. I want to use USB serial port (Serial) for debug output, and use Serial2 to send data to Raspberry Pi. I do have a voltage divider between the two to drop from 5V to 3.3, and that part doesn't seem to be the problem initially, when I run minicom on the raspberry pi, I see the sensor values being sent as below when I open a door.

    CTRL-A Z for help | 9600 8N1 | NOR | Minicom 2.7 | VT102 | Offline | serial0

    However when running mysgw, I never see anything on the same port.

    This is my ./configure:

     ./configure --my-transport=rs485 --my-rs485-serial-port=/dev/serial0 --my-serial-baudrate=9600

    Same value combination that works for minicom doesn't seem to bring up anything on mysgw:

     sudo ./bin/mysgw
    Feb 17 20:58:50 INFO  Starting gateway...
    Feb 17 20:58:50 INFO  Protocol version - 2.3.2
    Feb 17 20:58:50 DEBUG MCO:BGN:INIT GW,CP=RSNGL---,FQ=NA,REL=255,VER=2.3.2
    Feb 17 20:58:50 DEBUG TSF:LRT:OK
    Feb 17 20:58:50 DEBUG TSM:INIT
    Feb 17 20:58:50 DEBUG TSF:WUR:MS=0
    Feb 17 20:58:50 DEBUG Serial port /dev/serial0 (9600 baud) created
    Feb 17 20:58:50 DEBUG TSM:INIT:TSP OK
    Feb 17 20:58:50 DEBUG TSM:INIT:GW MODE
    Feb 17 20:58:50 DEBUG TSM:READY:ID=0,PAR=0,DIS=0
    Feb 17 20:58:50 DEBUG MCO:REG:NOT NEEDED
    Feb 17 20:58:50 DEBUG Listening for connections on
    Feb 17 20:58:50 DEBUG MCO:BGN:STP
    Feb 17 20:58:50 DEBUG MCO:BGN:INIT OK,TSP=1
    Feb 17 20:58:50 DEBUG TSM:READY:NWD REQ
    Feb 17 20:58:50 DEBUG ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:

    This part is so far is priority #1, however I also never get any debug output on Arduino serial monitor. I tried different permutations of all the lines below on my sketch with and without the serial ports on define line, and while most seem to send something over to pi (Serial2), none of them ever produce any output on serial monitor (Serial):

    #define MY_DEBUG Serial
    #define MY_GATEWAY_SERIAL Serial2
    #define MY_BAUD_RATE 9600
    #define MY_RS485
    #define MY_RS485_HWSERIAL Serial2
    #define MY_RS485_BAUD_RATE 9600
    #define MY_SERIALDEVICE Serial2
    #define MY_DEBUGDEVICE Serial

    I appreciate any assistance you can provide, thanks for reading.

  • It looks like I may have misunderstood that RS485 does not work over regular uart serial ports on Arduino and Raspberry Pi, and I probably need an additional rs485 module for both of them. I prefer a wired solution for this particular use case though, and I'm still not clear on what I should do, and buy for the most optimal solution.

  • Despite having temporary alternatives, I'm looking into if I can somehow add direct point to point communication over uart serial (/dev/Serial0 in my case) by modifying MyTransportRS485.cpp, but I'm not sure if this will work on a linux raspberry pi gateway, since functions there seem to be arduino specific. If anyone can point me in the right direction, I'd be grateful.

  • I finally got it working reading through google searches. I'd like to provide how I did it for anyone that may run into a similar issue in the future. While looking for this solution, I saw at least one person who had the exact same issue and their problem went unresolved.

    Raspberry Pi 3 is connected to Arduino Mega through regular serial link. Raspberry pi uses uart pins that map to Serial0 in raspbian. On Arduino Mega I use Serial2 pins (16,17). There's a voltage divider circuit between the two that reduces 5v to 3.3 for the pi.

    I compiled my gateway on pi with below:

    ./configure --my-transport=rs485 --my-rs485-serial-port=/dev/serial0 --my-rs485-baudrate=9600

    On Arduino I have these define lines:

    #define MY_DEBUG
    #define MY_DEBUGDEVICE Serial
    #define MY_RS485
    #define MY_RS485_HWSERIAL Serial2
    #define MY_NODE_ID 1
    #define MY_RS485_BAUD_RATE 9600
    #define MY_RS485_DE_PIN -1

    I'm not an expert on this by any means, but out of everything I tried, this is what worked for me. There are still some remaining issues:

    • Possibly due to line noise or voltage being low on Arduino, I've had one crash that made Arduino print gibberish on serial and it stopped transmitting anything at all.
    • I use Home Assistant and it seems to give up on MySensors if it doesn't receive anything in a while. Requires restart of HA core. Not very reliable.

    I still welcome any insight into this process and any alternatives/recommendations. I'd like to make this as reliable as possible, but my knowledge of these systems and electronics is limited.

Log in to reply

Suggested Topics