Nikkilae / PPM-reader

An interrupt based PPM signal reader for Arduino
GNU General Public License v3.0
77 stars 44 forks source link

PPM Reader for Arduino

PPM Reader is an interrupt based pulse-position modulation (PPM) signal reading library for Arduino. Its purpose is to provide an easy to use, non-blocking solution for reading PPM signals from an RC receiver that is able to output channel data as PPM.

Using interrupts (instead of pulseIn or some equivalent) to detect pulses means that reading the signal can be done in a non-blocking way. This means that using PPM Reader doesn't significantly slow down your program's code and you can do any other timing sensitive processes in your program meanwhile reading the incoming PPM signals.

The library uses zeitgeist87's InterruptHandler library for object-oriented interrupt handling. A copy of a compatible version of the library is included in this repository.

Usage

Installation

Download the contents of this repository on your computer. Move the downloaded PPMReader and InterruptHandler directories in your Arduino library directory.

Arduino setup and code

Connect your RC receiver's PPM pin to your Arduino board's digital pin. Make sure that you use a pin that supports interrupts. You can find information on that from the Arduino language reference.

When referring to channel numbers in the above methods, note that channel numbers start from 1, not 0.

Example Arduino sketch


#include <PPMReader.h>
// #include <InterruptHandler.h>   <-- You may need this on some versions of Arduino

// Initialize a PPMReader on digital pin 3 with 6 expected channels.
int interruptPin = 3;
int channelAmount = 6;
PPMReader ppm(interruptPin, channelAmount);

void setup() {
    Serial.begin(9600);
}

void loop() {
    // Print latest valid values from all channels
    for (int channel = 1; channel <= channelAmount; ++channel) {
        unsigned long value = ppm.latestValidChannelValue(channel, 0);
        Serial.print(String(value) + " ");
    }
    Serial.println();
}

Fine tuning

The PPMReader class should work with default settings for many regular RC receivers that output PPM. The default settings are as follows (all of them represent time in microseconds):

You can modify any of the above settings directly from the PPMReader object. They are public unsigned long variables.

Testing

The library has been tested and proven to work on the following setup:

Please mention any issues, bugs or improvement ideas.