Home

Awesome

pypi version shield pypi downloads per month shield

Description

A micropython library to decode PPM signals coming from a RC receiver (as used for rc planes and drones).

This library is focused on savety and includes functions that can be used to detect a faulty or lost signal. For this it is required to init the PpmReader class with the correct number of channels in the PPM signal. This might be a different number than the amount of servo connectors on the RC receiver hardware!

Created for the use with pi pico, but should work on other boards as well. You can find the API documentation and a few examples below.

Examples

Print the values of all channels

from ppm_reader import PpmReader
ppm_pin_id=28
ppm_channels=8
ppmReader=PpmReader(ppm_pin_id,ppm_channels)
while True:
    time.sleep(0.5)
    print(ppmReader.get_values())

Find the number of channels

#the number of channels should be known before you init PpmReader
#if the channel number is incorrect only guess_channel_count will work
from ppm_reader import PpmReader
ppm_pin_id=28
ppmReader=PpmReader(ppm_pin_id,channels=0)
while True:
    time.sleep(0.5)
    print(ppmReader.guess_channel_count())

Find values for min_value and max_value

#move the controls to the extreme positions and observe the values
from ppm_reader import PpmReader
ppm_pin_id=28
ppm_channels=8
ppmReader=PpmReader(ppm_pin_id,ppm_channels)
while True:
    time.sleep(0.5)
    print(ppmReader.get_raw_values())

Check for a loss of signal

from ppm_reader import PpmReader
ppm_pin_id=28
ppm_channels=8
ppmReader=PpmReader(ppm_pin_id,ppm_channels)

#wait initial connection with the remote
while ppmReader.get_valid_packets() == 0:
    print("waiting for connection ...")
    time.sleep(0.5)
print("connected.")

#got signal, continue to main loop
while True:
    last_packet_time=ppmReader.time_since_last_packet()
    print(last_packet_time)
    if last_packet_time>25000: 
        #25ms without a new packet
        #take security measures here (for example stop all motors)
        print("connection lost")
        #wait for connection
        while ppmReader.time_since_last_packet()>25000:
            pass
        print("connected again")
    else:
        #connection ok. Do something here
        print(ppmReader.get_values())

API

class PpmReader(pin_id,channels,min_value=1000,max_value=2000,packet_gap=4000)

time_since_last_packet()

get_valid_packets()

get_inalid_packets()

reset_packet_counters()

get_raw_values()

get_raw_value(channel)

get_values()

get_value(channel)

get_values_bi()

get_value_bi(channel)

guess_channel_count()