We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Omega2+ serial not working as expected



  • Hey folks,
    I'm trying to connect my Omega2+ to a wireless water tank measurement system so I can check the tank water levels from my phone without having to go look at display on little receiver. There's a serial port on the receiver with a very simple API. I've written a script to grab the data, however I'm having trouble actually getting the serial connection from the omega to talk to the receiver. I get either nothing, or a bunch of garbage characters coming back.

    If I connect my laptop to the receiver with a USB to serial adapter, my script works fine, and I get the data I expect. However it doesn't work on the Omega2+

    I'm using python3 and the pyserial library, connecting at 9600 baud. Is there something i'm missing here?

    I've tried two different Omega2's, the power dock, and the arduino dock. Same behavior regardless of the combination, so I don't think it's them. The Omega's are from feb 2017, and I just updated their firmware to the latest available.

    the code is below, in case it's relevant:

    The code:
    #!/usr/bin/python

    import binascii
    import serial
    import time

    ser = serial.Serial(port='/dev/ttyS1',
    baudrate=9600,
    timeout=None,
    xonxoff=False,
    rtscts=False,
    dsrdtr=False,
    parity=serial.PARITY_NONE,
    bytesize=serial.EIGHTBITS,
    stopbits=serial.STOPBITS_ONE) # open serial port
    i = 0
    while True:
    #the following request asks the receiver to return the data for the first tank:
    send_bytes = serial.to_bytes([0x02,0x01,0x01,0x0D])
    print("Sending: ", send_bytes)
    ser.write(send_bytes)
    readbyte = ser.read(1)
    i += 1
    #the next two conditionals are to deal with garbage chars
    if readbyte == serial.to_bytes([0x00]):
    print("I got a zero..")
    continue
    if readbyte != serial.to_bytes([0x02]):
    print("I read this unexpected byte: %d",readbyte)
    else:
    #looks like we found a message
    tankID,sequence,tankLevel,RSSI,temp,battery,Alarm,endbit = ser.read(8)
    print("tankID" , tankID)
    print("sequence" , sequence)
    print("tankLevel" , tankLevel)
    print("RSSI" , RSSI)
    print("temp" , temp)
    print("battery" , battery)
    print("Alarm" , Alarm)
    print("endbit" , endbit)
    time.sleep(5)

    ser.close() # close port



  • Hi James: I've had enormous trouble getting Onion Omega 2+ UART to work properly. There's clearly a bug somewhere, although it's hard to say where. We think it's in musl, but, regardless, it's not something easy to fix. The latest builds of the Onion firmware are especially bad. The present stable build works somewhat. This bug is actually preventing me from deploying Onions commercially.

    Here's the thread from August that details this very issue.
    https://community.onion.io/topic/3654/request-for-improvement-on-driver-for-ttys_-or-help-to-do-it-myself



  • @JP-Norair said in Omega2+ serial not working as expected:

    https://community.onion.io/topic/3654/request-for-improvement-on-driver-for-ttys_-or-help-to-do-it-myself

    So i'm not the only one, and i'm not crazy.. that's good at least.

    Looking at all the diagnostics you've run I'm guessing the python library must be making some calls that run afoul of the bug in the UART driver. in my case I can use a USB to serial adapter with my device, but broken serial drivers seriously impairs what I had planned to use these for. That's frustrating.



  • @James-Penick Do you mind if I contact you outside the Onion forums? You can send me a Linked-In page and we can work it out from there, if it makes sense. I want to ask you a few things that are outside the scope of this forum.



  • msg sent

    continuing the saga for the edification of anyone else interested. I tried a USB to serial adaptor with the FTDI FT232RL chipset. It's a sabrent so I guess it's not a counterfeit?

    The cable worked fine from my laptop to the device I was querying. Attaching it to my onion showed things working better than the onboard UART, but I still saw corrupted data.

    I realized that omega had python2 installed, so I installed python3, and then things worked fine. No idea why, as that doesn't make sense. But whatever, it works so i'll call it good enough.

    I'm pretty frustrated that the omega2+ onboard UART doesn't work right, but I don't know how to debug that any further



  • @James-Penick I built my own board to plug in my Omega2, it has some other stuff on it I needed as well but it allowed me the change the USB-Serial chip. Maybe this will work for you.



  • That's a good idea, I might play with doing that.. Or i can look into doing one that ties into some GPIO pins.

    Of course, it'd be nice if we could all just use one of the two rs232 interfaces already on the darn device.



  • @James-Penick Please let us know what is your "wireless water tank measurement system" device.



  • @György-Farkas sure, it's this: https://www.rainharvest.com/aquatel-d110-s-wireless-tank-level-monitor-with-rs-232-interface.asp

    receivers are placed on each tank to measure the water level with ultrasonic pulses. The level data is sent back to a little receiver station that has an RS232 port on it. My goal is to take that data and ship it off to something like amazon IOT so I can check the water level from my phone without having to go look at the display on the device.



  • @James-Penick Thank you.
    What type of USB to serial adapter are you using to connect the receiver to your laptop?



  • @György-Farkas I bought the Sabrent CB-FTDI, and use it to connect both the laptop to the receiver and to connect the omega2+ to the receiver in lieu of the onboard serial.



  • @James-Penick The receiver has a real RS232 port and you are using a USB to RS232 adapter/cable.
    USB 2.0 to Serial (9-Pin) DB-9 RS-232 Adapter Cable 6ft Cable
    You connected that cable to the USB Host port of your Omega2+ - so you are using the ttyUSB0 serial "port" instead of the ttyS1 port.
    Please try to correct the Python code.
    Sorry, I didn't read one of your previous posts. 😞

    If you want to use Omega2's ttyS1 serial port then connect it to the receiver via an RS232 to 3.3V TTL converter.
    For example:
    MAX3232 RS232 Serial Port to TTL Converter Module DB9 Connector with Cables



  • Oh, cool! I'll give that a shot and report back. Thank you!



  • @György-Farkas that did the trick, it works via the rs232 TTL converter. I never even considered the voltage before. Thank you!



  • @James-Penick So "Omega2+ serial working as expected" 🙂
    Well done. Congrats!


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.