Assistance with serial API (Rpi SBGC). How do I set things up on non-UART1 port?
  • Hello,

    I'm using the SimpleBGC 32-bit controller, v3.0. I need to be able to communicate with the controller via a raspberry pi.

    Using python, I've written the software to send commands to the board (I'll share it with the community once I'm done) and checked that the commands are correct using an oscilloscope. I've built a logic level converter as the board's UART is 5V, and confirmed that it works. My code looks something like this:

    import serial, numpy as np

    ser = serial.Serial('/dev/serial0',

    x = bytearray()
    x.append(np.uint8(0x3e)) # >
    x.append(np.uint8(0x4d)) # command
    x.append(np.uint8(0x00)) # data length
    x.append(np.uint8(0x4d)) # checksum
    ser.write(x) # this is correct, when viewed on oscilloscope

    I have also look at the board's UART Tx pin and it looks correct when the board is communicating via the GUI. I have no idea why this isn't working! Any tips?

    In the off chance that the controller's UART Rx pin is broken, what is the process to connect to one of the other UART slots? The documentation is a bit confusing on that. What settings should I change in the GUI?

  • Hello!

    If you mean UART 5V in the controller, it's not correct: UART's on the board are 5v-tolerant, but the natural logic is 3.3V, so you do not need an LLC.

    Which UART do you connect, the main that is routed to 4 pin "5V Gnd Rx-Tx"? It is connected parallel to the on-board USB-to-UART coverter, so can not be used when the USB is connected and GUI connection is established.

    Additional UART is on the [RC_ROLL (Rx), RC_YAW (Tx)]. You need to enable it setting this option:

    Rc tab - RC_ROLL pin mode = SBGC Serial API.

    There is also 3rd uart named UART2 (RX only) on Aux 3, can be enabled in the "Hardware" tab.

    Regards, Aleksey
  • Hi Aleksey

    Thanks the help. I've since gotten it to communicate. I think I was having issues with the USB interfering and my checksum calculation

    I find the documentation to be in general really well done, though I'm not sure it's actually mentioned that the UARTs are TTL (may have just missed it) so it could be something to add for the next version?


    One more question - I seem to be making a mistake when calculating the checksum for a mix of positive and negative gimbal angles. I fill a python list with numpy uint8's and int16's and then sum them, but I get the wrong result when I input negative numbers for the angles.

    Example python code:
    >>> body_data = [np.uint8(2), np.int8(10), np.int16(-10)]
    >>> body_checksum = np.uint8(sum(body_data )) # => outputs 2 = 2 + 10 - 10

    When I scope the arduino output I see that it seems to give something else. Could you clarify what I should be doing? I'll post back if I figure this out tomorrow

  • I figured it out, and forgot to post back here. My error was that I wasn't treating int16's as two separate bytes. The correct code is as follows (note that 'data' is a list of numpy scalars, like np.int16 and np.uint8)

    body_checksum = 0
    if data_size > 0:
    ----for d in data:
    --------if d.nbytes == 1:
    ------------body_checksum += d
    --------elif d.nbytes == 2:
    ------------d_bytes = d.tobytes()
    ------------message.append(d_bytes[0]) # working with little endian
    ------------body_checksum += d_bytes[0] + d_bytes[1] # add the two bytes as if there were two independent numbers

    ----if debug:
    --------print('body_checksum = %i' % body_checksum)


    (added dashes because the forums don't seem to like spaces)