0
import time
import Jetson.GPIO as GPIO

gpio_pin = 388 # Orbitty carrier 7(GPIO_0) pin

# Sbus signal encoding function
def encode_sbus(channels, failsafe=False):
    sbus_data = [0] * 25  # Sbus frame is 25 bytes long and all channels are encoded as 16 bits.
    sbus_data[0] = 0x0F  # Sbus frame start byte
    sbus_data[24] = 0x00  # Sbus frame end byte

    if failsafe:
        # activate failsafe
        sbus_data[23] = 0x04

    for i in range(16):
        channel_value = channels[i]
        if channel_value < 1005:  # if channel value is less than the minimum value, set it to the minimum value
            channel_value = 1005
        elif channel_value > 1950:  # if channel value is greater than the maximum value, set it to the maximum value
            channel_value = 1950

        # encode the channel value
        bit_pos = i % 8
        byte_pos = (i // 8) + 1
        if bit_pos == 0:
            sbus_data[byte_pos] |= (channel_value & 0x07) << 1
            sbus_data[byte_pos + 1] = (channel_value & 0x07F8) >> 3
        elif bit_pos == 1:
            sbus_data[byte_pos] |= (channel_value & 0x03) << 3
            sbus_data[byte_pos + 1] |= (channel_value & 0x07F0) >> 1
        else:
            sbus_data[byte_pos] |= (channel_value & 0x01) << (bit_pos + 3)
            sbus_data[byte_pos + 1] |= (channel_value & 0x07F0) >> (bit_pos - 1)

    return sbus_data

# GPIO pin setup
GPIO.setmode(GPIO.BOARD)
GPIO.setup(gpio_pin, GPIO.OUT)

# initialize channel values
channels = [1500] * 16  # initialize all 16 channels to the center value of 1500

while True:
    # adjust channel values here as needed
    channels[0] = 1600  # example: set channel 1 to 1600
    channels[1] = 1400  # example: set channel 2 to 1400

    # encode the updated channel values into an Sbus signal
    sbus_signal = encode_sbus(channels)

    # Example of activate FAILSAFE.
    # sbus_signal = encode_sbus(channels, failsafe=True)

    # send the Sbus signal through the GPIO pin
    GPIO.output(gpio_pin, GPIO.HIGH)
    time.sleep(0.000150)
    for i in range(25):
        for j in range(8):
            GPIO.output(gpio_pin, sbus_signal[i] & (1 << j))
            time.sleep(0.000150)
    GPIO.output(gpio_pin, GPIO.LOW)
    time.sleep(0.003)

This is my code, What i want to do is Generate Sbus signal with Jetson tx2(Orbitty Carrier), and transmit it throgh GPIO pin. So I searched that gpio 338 is orbitty carriers gpio 0. And, i connected a wire gpio 0 and FC(Hpbbywing F4G3).. But code didt work, and log says 388pin is not available..if i change the pin num, this code will work but notthing happens in Betaflight configurator.....

What should i doo..Thankyou!(sry for bad ENG)

I want to operate Hobbywing fc with Jetson Tx2

0 Answers0