Remote to Cont Sample
This sample demonstrates transferring RC remote inputs to steering servo and ESC.
- 1.Download the sample code from https://github.com/Turta-io/RCDriverHAT/blob/master/Samples/Python/Remote_to_Controller.py
- 2.Copy the sample code to a folder on the Raspberry Pi.
- 3.Open terminal, and then go to the folder you copied the sample.
- 4.Run the sample with the following command:
#This sample demonstrates transferring RC remote inputs to steering servo and ESC.
#Install RC Driver HAT library with "pip3 install turta-rcdriverhat"
from time import sleep
from turta_rcdriverhat import Turta_RCDriver
rc = Turta_RCDriver.RCDriver()
#Activate fan at 50% speed
#Read multiple PWMs
pwm_all = rc.read_pwms()
if pwm_all is not None: #Check if data is received
#Convert PWM timespans to PWM output that RC servo motors and ESCs understand
for p in range(4):
if pwm_all[p] == 0:
pwm_all[p] = 1500
elif pwm_all[p] < 1000:
pwm_all[p] = 1000
elif pwm_all[p] > 2000:
pwm_all[p] = 2000
temp = math.floor((pwm_all[p] * 0.256) - 384)
pwm_all[p] = temp
#Set Multiple PWMs
#Print the output data
print("PWM S.....: " + str(pwm_all))
print("PWM T.....: " + str(pwm_all))
print("PWM 3.....: " + str(pwm_all))
print("PWM 4.....: " + str(pwm_all))
#Exit on CTRL+C
When you run the sample, it reads PWM pulses from the receiver port, and generates pulses on control port accordingly. The example output should be like this:
PWM S.....: 52
PWM T.....: -12
PWM 3.....: 0
PWM 4.....: 0
To stop the Python script, just press CTRL + C.