RC Driver
Python Library for PWM Driver, Power Monitor, ADC, Tachometer and PWM Decoder.
Turta_RCDriver library is responsible for reading tachometer inputs, analog inputs, PWM decode results, PWM generation, LED lighting control, CPU fan control, reading CPU temperature and measuring battery Voltage.
Add the following statement to the top of your Python code.
from turta_rcdriverhat import Turta_RCDriver
Then, create an instance of the RCDriver class.
rc = Turta_RCDriver.RCDriver()
Now you're ready to access the library by calling its instance.
Sets the PWM pulse length of selected channel at 60Hz.
set_pwm(ch, pos)
Parameters
PWM_OUT ch: PWM Output channel. Int pos: Pulse length. (-128 is 1000us, 0 is 1500us, 128 is 2000us.) Returns
None
Sets all PWM pulse lengths at 60Hz.
set_pwms(pos)
Parameters
Int[] pos: Pulse length. (-128 is 1000us, 0 is 1500us, 128 is 2000us), channels S, T, 3 and 4 respectively. Returns
None
Sets the fan speed.
set_fan(speed)
Parameters
Byte speed: Fan speed. (0 to 100, 0 is off, 100 is full speed.) Returns
None
Sets the PWM pulse length of selected channel at 60Hz.
set_pwm(ch, pos)
Parameters
PWM_OUT ch: PWM Output channel. Int pos: Pulse length. (-128 is 1000us, 0 is 1500us, 128 is 2000us.) Returns
None
Sets the brightness of the selected LED.
set_led(led, b)
Parameters
LED_OUT led: LED channel. Int b: LED brightness. (0 to 4095, 0 is off, 4095 is full bright.) Returns
None
Sets the brightnesses of the LEDs.
set_leds(b)
Parameters
Int[] b: LED brightness. (0 to 4095.) Front, rear, stop, left and right respectively. Returns
None
Sets controller PWM outputs off. (Steering, Throttle, Aux 3, Aux 4.)
set_pwms_off()
Parameters
None Returns
None
Sets all LEDs off.
set_leds_off()
Parameters
None Returns
None
Reads the battery Voltage.
read_voltage()
Parameters
None Returns
Float: Battery Voltage.
Reads the pulse length of the selected PWM channel.
read_pwm(ch)
Parameters
PWM_IN ch: PWM Channel. Returns
Int: Pulse length in microseconds.
Reads the pulse length of the all PWM channels.
read_pwms()
Parameters
None Returns
Int[]: Pulse length in microseconds, channel S, T, 3 and 4 respectively.
Reads the analog input of the selected channel.
read_analog(ch)
Parameters
ANALOG_IN ch: Analog input channel. Returns
Int: 10-Bits analog value. (0 to 1023)
Reads the analog inputs of all four channels.
read_analogs()
Parameters
None Returns
Int[]: 10-Bits analog value. (0 to 1023) Channel 1 to 4 respectively.
Reads the speed of vehicle using the selected tachometer input.
read_tach(ch, ticks_per_rev, dia_cm, mph)
Parameters
TACH_IN ch: Tachometer channel. Int ticks_per_rev: Ticks per revolution. (Default is 1.) Int dia_cm: Diameter in cm. (Default none returns RPM.) Bool mph: True for MPH, False for KMH output. Checked only if dia_cm is set. (Default is False.) Returns
Float: Vehicle speed or RPM.
Reads the speed of vehicle using the tachometer inputs.
read_tachs(ticks_per_rev, dia_cm, mph)
Parameters
Int ticks_per_rev: Ticks per revolution. (Default is 1.) Int dia_cm: Diameter in cm. (Default none returns RPM.) Bool mph: True for MPH, False for KMH output. Checked only if dia_cm is set. (Default is False.) Returns
Float[]: Vehicle speed or RPM, left and right respectively.
Reads the temperature of the Raspberry Pi's CPU.
read_cpu_temp(fahrenheit)
Parameters
None Returns
Float: CPU Temperature.
Sends Who_Am_I command to the MCU, checks if it responses correctly.
test_mcu()
Parameters
None Returns
Bool: True if the device responses with 0xBD, False if not.
When exiting from the program, the library turns off all board functions. (Stops PWM generation, turns LEDs off, turns off LEDs.)
Last modified 3yr ago