Robotics-II-Circuit-Python

Circuit Python tutorials in Robotics II

View the Project on GitHub MrPrattASH/Robotics-II-Circuit-Python

Table of Contents

CircuitPython - FlySky FS-I6X Controller - FS-iA6B Reciever

This page will show you how to use the rc.py library for controlling a FlySky FS-i6(X) controller with an FS-iA6B reciever in circuitpython.

Tutorials


Video Tutorial


Text Tutorial

Library Documentation (Putting it all together)


Program Breakdown

py file here

import time
import board
from rc import RCReceiver

# Initialize the receiver with designated pins for channels
rc = RCReceiver(ch1=board.D10, ch2=board.D11, ch3=None, ch4=None, ch5=board.D12, ch6=board.D13)

# List of channel numbers we are interested in
channels = [1, 2, 5, 6]

# Variables to store the values read from each channel
x = 0
y = 0
sw_b = 0
sw_c = 0

# Main code loop
while True:
    # Read channels in a loop, iterating through our list
    for i in range(len(channels)):
        channel_value = rc.read_channel(channels[i])
        
        if channel_value is not None:
            if channels[i] == 1:
                x = channel_value
            elif channels[i] == 2:
                y = channel_value
            elif channels[i] == 5:
                sw_b = channel_value
            elif channels[i] == 6:
                sw_c = channel_value
                
    # Print the channel values to the console
    print("Ch 1:", x, "Ch 2:", y, "Ch 5:", sw_b, "Ch 6:", sw_c)

Importing Libraries


import time
import board
from rc import RCReceiver

Initializing the Receiver


rc = RCReceiver(ch1=board.D10, ch2=board.D11, ch3=None, ch4=None, ch5=board.D12, ch6=board.D13)

We create an instance of RCReceiver and assign specific microcontroller pins (D10, D11, D12, D13) to the receiver channels 1, 2, 5, and 6 respectively. Channels 3 and 4 are not being used (the left side of our controller with the 6 section transmission), hence they are set to None.

Init Variables


channels = [1, 2, 5, 6]

A list is a collection of items that can be of any data type. Lists in Python are ordered, changeable, and allow duplicate values. while a variable is typically only 1 value, you can think of a list as a group or collection of variables that we can access.

This list contains the number of the channels we will be reading data from.


x = 0
y = 0
sw_b = 0
sw_c = 0

We initialize variables x, y, sw_b, and sw_c to store the values read from channels 1, 2, 5, and 6 respectively. Their values relate to the axis they are reading on our joystick, or the switch at the top of the controller.


While Loop


for i in range(len(channels)):
    channel_value = rc.read_channel(channels[i])
    if channel_value is not None:
        if channels[i] == 1:
            x = channel_value
        elif channels[i] == 2:
            y = channel_value
        elif channels[i] == 5:
            sw_b = channel_value
        elif channels[i] == 6:
            sw_c = channel_value

We then check if channel_value is not None and update the corresponding variables (x, y, sw_b, sw_c) based on which channel was read.


print("Ch 1:", x, "Ch 2:", y, "Ch 5:", sw_b, "Ch 6:", sw_c)

The print statement outputs the values of channels 1, 2, 5, and 6 to the serial console.