Skip to main content

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)

  • pin_id: GPIO pin connected to the PPM signal comming from the RC receiver.
  • channels: Number of channels in the PPM signal. if the channel count is wrong the packts will be considered invalid.
  • min_value: Minimum timeframe per channel in us (this should be around 1000us for standard equipment).
  • max_value: Minimum timeframe per channel in us (this should be around 2000us for standard equipment).
  • packet_gap: Minimum time gap between packets in us (4000us should be used for standard equipment).

time_since_last_packet()

  • returns the time passed since the last valid packet arrived in us. This will stay below about 5000us if every packet is received correctly. Missing 2 or 3 packets is usually not a problem.

get_valid_packets()

  • returns the number of valid packets received

get_inalid_packets()

  • returns the number of invalid packets received

reset_packet_counters()

  • resets counters for valid and invalid packets received

get_raw_values()

  • returns a list of all raw timeframes in us in the last valid packet received

get_raw_value(channel)

  • returns the raw timeframe in us in the last valid packet received for a given channel
  • channel: channel to get the value from

get_values()

  • returns a list of all values in the last valid packet maped to a range of 0.0 to 1.0 (values are not clipped)

get_value(channel)

  • the value for a given channel in the last valid packet maped to a range of 0.0 to 1.0 (values are not clipped)
  • channel: channel to get the value from

get_values_bi()

  • returns a list of all values in the last valid packet maped to a range of -1.0 to 1.0 (values are not clipped)

get_value_bi(channel)

  • the value for a given channel in the last valid packet maped to a range of -1.0 to 1.0 (values are not clipped)
  • channel: channel to get the value fro

guess_channel_count()

  • returns the number of channels in the last packet (incase you are not sure how many channels your signal has)

Metadata

Release files for micropython-ppm-reader 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for micropython-ppm-reader 1.0.2
File Size Uploaded
micropython-ppm_reader-1.0.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for micropython-ppm-reader 1.0.2
File Interpreter ABI Platform
micropython_ppm_reader-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / micropython-ppm_reader-1.0.2.tar.gz

Download URL micropython-ppm_reader-1.0.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fe061d29b923fe601b1b595839a71484a554378c17b976bec0804b41bd3bab6c
BLAKE2b-256 checksum
How to use checksums
aa3d25acd4aefdb6516c8ab5c31fda694f022e657b1c30f558830b482ba34db1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / micropython_ppm_reader-1.0.2-py3-none-any.whl

Download URL micropython_ppm_reader-1.0.2-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8cd3901ba0146d33aa06dba8bf04d470e78e2a734672fc187ebb1451ad59877d
BLAKE2b-256 checksum
How to use checksums
ab43be1e5f5979c8e1bb42aacaf8954a98674764a92675d2c4c0a69098ecf745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page