More than a year a published a post called Generate PPM signal with Arduino. Today it's time for part two: How to read PPM signal with Arduino?. Strange thing: internet does not gives very useful information on this topic. Strange, right? Some links to pages that does it either very very wrong or in not simple way.

There is a one almost good solution. It's an example code by Hasi123. Short, efficient and actaully works almost out of the box. But it has 2 problems:

  1. It is not a library. You have to copy paste code
  2. It alters Timer1 and that means, that many other things stops to work: PMW output, Servo library or anything else that uses Timer1. Crap...

So, I've invested some of my time and, based on that code, I've created Arduino library called PPMReader. Advantages?

  1. It is a library (!)
  2. It does not alters any timers (!)

Example code, that reads PPM signal connected to Pin 2 of Arduino Uno or Pro Mini (and other using ATmega328) and prints decoded channels over serial port would look like this:

#include "PPMReader.h"

// PPMReader(pin, interrupt)
PPMReader ppmReader(2, 0);

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

void loop()
{
  static int count;
  while (ppmReader.get(count) != 0) { //print out the servo values
      Serial.print(ppmReader.get(count));
      Serial.print("  ");
      count++;
  }
  count = 0;
  delay(500);
}

The only required configuration is a decission of a pin and interrupt. Not all pins have hardware interrupts, so on many boards this is limited to:

  • Arduino Uno, Pro Mini and other based on ATmega328: pin 2 / interrupt 0 or pin 3 / interrupt 1
  • Arduino Pro Micro and other based on ATmega32u4: pin 3 / interrupt 0, pin 2 / interrupt 1, pin 0 / interrupt 1, pin 1 / interrupt 3, pin 7 / interrupt 4

PPMReader Arduino library can be downloaded from GitHub.