micropython-ppm-reader


Namemicropython-ppm-reader JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryDecodes PPM signals from RC receivers
upload_time2022-12-26 09:12:16
maintainer
docs_urlNone
author
requires_python
licenseMIT License Copyright (c) 2022 redoxcode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ppm reader rc remote receiver
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## 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](https://github.com/redoxcode/micropython-ppm_reader/#API) and a few [examples](https://github.com/redoxcode/micropython-ppm_reader/#Examples) below.

## Examples

### Print the values of all channels
```Python
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
```Python
#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
```Python
#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
```Python
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)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "micropython-ppm-reader",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "PPM,reader,rc,remote,receiver",
    "author": "",
    "author_email": "redoxcode <redoxcode@github.com>",
    "download_url": "https://files.pythonhosted.org/packages/aa/3d/25acd4aefdb6516c8ab5c31fda694f022e657b1c30f558830b482ba34db1/micropython-ppm_reader-1.0.2.tar.gz",
    "platform": null,
    "description": "## Description\nA micropython library to decode PPM signals coming from a RC receiver (as used for rc planes and drones).\n\nThis library is focused on savety and includes functions that can be used to detect a faulty or lost signal.\n**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!**\n\nCreated for the use with pi pico, but should work on other boards as well.\nYou can find the [API documentation](https://github.com/redoxcode/micropython-ppm_reader/#API) and a few [examples](https://github.com/redoxcode/micropython-ppm_reader/#Examples) below.\n\n## Examples\n\n### Print the values of all channels\n```Python\nfrom ppm_reader import PpmReader\nppm_pin_id=28\nppm_channels=8\nppmReader=PpmReader(ppm_pin_id,ppm_channels)\nwhile True:\n    time.sleep(0.5)\n    print(ppmReader.get_values())\n```\n### Find the number of channels\n```Python\n#the number of channels should be known before you init PpmReader\n#if the channel number is incorrect only guess_channel_count will work\nfrom ppm_reader import PpmReader\nppm_pin_id=28\nppmReader=PpmReader(ppm_pin_id,channels=0)\nwhile True:\n    time.sleep(0.5)\n    print(ppmReader.guess_channel_count())\n```\n### Find values for min_value and max_value\n```Python\n#move the controls to the extreme positions and observe the values\nfrom ppm_reader import PpmReader\nppm_pin_id=28\nppm_channels=8\nppmReader=PpmReader(ppm_pin_id,ppm_channels)\nwhile True:\n    time.sleep(0.5)\n    print(ppmReader.get_raw_values())\n```\n### Check for a loss of signal\n```Python\nfrom ppm_reader import PpmReader\nppm_pin_id=28\nppm_channels=8\nppmReader=PpmReader(ppm_pin_id,ppm_channels)\n\n#wait initial connection with the remote\nwhile ppmReader.get_valid_packets() == 0:\n    print(\"waiting for connection ...\")\n    time.sleep(0.5)\nprint(\"connected.\")\n\n#got signal, continue to main loop\nwhile True:\n    last_packet_time=ppmReader.time_since_last_packet()\n    print(last_packet_time)\n    if last_packet_time>25000: \n        #25ms without a new packet\n        #take security measures here (for example stop all motors)\n        print(\"connection lost\")\n        #wait for connection\n        while ppmReader.time_since_last_packet()>25000:\n            pass\n        print(\"connected again\")\n    else:\n        #connection ok. Do something here\n        print(ppmReader.get_values())\n```\n\n## API\n### class PpmReader(pin_id,channels,min_value=1000,max_value=2000,packet_gap=4000)\n- pin_id: GPIO pin connected to the PPM signal comming from the RC receiver.\n- channels: Number of channels in the PPM signal. if the channel count is wrong the packts will be considered invalid.       \n- min_value: Minimum timeframe per channel in us (this should be around 1000us for standard equipment).\n- max_value: Minimum timeframe per channel in us (this should be around 2000us for standard equipment).   \n- packet_gap: Minimum time gap between packets in us (4000us should be used for standard equipment).\n\n```time_since_last_packet()```\n- 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.\n\n```get_valid_packets()```\n- returns the number of valid packets received\n\n```get_inalid_packets()```\n- returns the number of invalid packets received\n    \n```reset_packet_counters()```\n- resets counters for valid and invalid packets received\n    \n```get_raw_values()```\n- returns a list of all raw timeframes in us in the last valid packet received\n\n```get_raw_value(channel)```\n- returns the raw timeframe in us in the last valid packet received for a given channel\n- channel: channel to get the value from\n\n```get_values()```\n- 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)\n\n```get_value(channel)```\n- 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)\n- channel: channel to get the value from\n\n```get_values_bi()```\n- 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)\n\n```get_value_bi(channel)```\n- 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)\n- channel: channel to get the value fro\n\n\n```guess_channel_count()```\n- returns the number of channels in the last packet (incase you are not sure how many channels your signal has)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 redoxcode  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  ",
    "summary": "Decodes PPM signals from RC receivers",
    "version": "1.0.2",
    "split_keywords": [
        "ppm",
        "reader",
        "rc",
        "remote",
        "receiver"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8bb9b873a368d2015706e624bc073ed0",
                "sha256": "8cd3901ba0146d33aa06dba8bf04d470e78e2a734672fc187ebb1451ad59877d"
            },
            "downloads": -1,
            "filename": "micropython_ppm_reader-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8bb9b873a368d2015706e624bc073ed0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5174,
            "upload_time": "2022-12-26T09:12:14",
            "upload_time_iso_8601": "2022-12-26T09:12:14.989081Z",
            "url": "https://files.pythonhosted.org/packages/ab/43/be1e5f5979c8e1bb42aacaf8954a98674764a92675d2c4c0a69098ecf745/micropython_ppm_reader-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "d7895143e6b73cd096582917bcbe5bd4",
                "sha256": "fe061d29b923fe601b1b595839a71484a554378c17b976bec0804b41bd3bab6c"
            },
            "downloads": -1,
            "filename": "micropython-ppm_reader-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d7895143e6b73cd096582917bcbe5bd4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4272,
            "upload_time": "2022-12-26T09:12:16",
            "upload_time_iso_8601": "2022-12-26T09:12:16.832271Z",
            "url": "https://files.pythonhosted.org/packages/aa/3d/25acd4aefdb6516c8ab5c31fda694f022e657b1c30f558830b482ba34db1/micropython-ppm_reader-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-26 09:12:16",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "micropython-ppm-reader"
}
        
Elapsed time: 0.03333s