7 - TUTORIAL - Connect a receiver to your Teensy (PWM and PPM signals)

Video: https://youtu.be/Qk4d7EuqOUQ

#Robotics #Drones #Arduino #Hardware #Teensy_4

Full code and manual on GitHub
Quadcopter frame PCB on OSHW lab

🔙 Previous Part | Next Part 🔜

↩️ Go Back

Table of Contents:


A) Introduction - desired orientation and throtle

Welcome to the seventh video in this series, where you’ll learn how your Teensy microcontroller can receive commands from the receiver.

There are four commands that you need to pass on to the microcontroller, the desired values for:

  1. the throttle,
  2. roll,
  3. pitch,
  4. and yaw rotation rates.

Let’s get started.


A.1) Building the Circuit

The circuit you are going to build is very straightforward,

and requires only three male-to-female jumper wires.

First, connect a white jumper cable from the receiver channel labeled “PPM” to a digital pin (DC pin) on your Teensy that is capable of receiving PPM signals.

According to the documentation, pin 14 is a suitable pin for this.

Next, power the receiver by connecting the 5-volt output and ground from your Teensy to the receiver.

When making the connections, ensure you connect the white signal cable to the second position of the PPM channel on the receiver (starting from the top).

The 5-volt power cable should be connected to the third position of the PPM channel, and the ground cable to the fourth.


A.2) PWM vs PPM

A.2.1) Understanding PWM Signals

Let’s take a moment to reflect on the idea behind the PWM signal.

Imagine you have a continuously varying throttle command that you send to the receiver.

By sampling the signal every 4 milliseconds, the data can be sent through a cable to your Teensy. This sampling is done using a signal that alternates between a high voltage (1) and a low voltage (0).

By changing the duration of the high part of the signal, you can transmit data. For example, a throttle at 50% corresponds to a high signal that lasts 1.5 milliseconds. A throttle at 100% gives a 2-millisecond high signal, and no throttle gives a 1-millisecond high signal.

This is called PWM (Pulse Width Modulation), as you transfer data by varying the pulse lengths.

Most receivers and ESCs operate at a PWM frequency of 250 Hz, meaning the signal repeats every 4 milliseconds with a length that corresponds to the throttle value.


A.2.2) Understanding PPM Signals

An alternative communication method is PPM (Pulse Position Modulation). With PPM, you transmit the same information by varying the position of the signal in time, rather than the pulse width. The readout frequency remains the same.


A.2.3) The advantage of PPM over PWM

For instance, if you want to send information about two signals—throttle and pitch—using PWM, you would need two separate cables.

This is inefficient because the signals cannot be processed simultaneously in the microcontroller, causing delays.

PPM allows you to send information from multiple signals through a single cable by measuring the time between rising edges of the signal. This makes the process more efficient, as the timing can be used to decode multiple commands.


A.3) Configuring the Radio Controller for PPM Signals

To configure your radio controller to send PPM signals:

  1. Hold the OK button

  2. and select System Setup.

  3. Go to RX Setup

  4. and scroll down to Output Mode.

  5. Select PPM instead of PWM

  6. and save your choice by holding the Cancel button


A.4) Programming the Teensy

Handling PPM signals is fairly complex, so we will use a predefined library called PulsePosition.h.

First, create a PPM input object for the receiver input and call it something appropriate like ReceiverInput. This object will track each pulse, starting from the RISING edge.

For this project, you will use two global variables:

To read the receiver data multiple times in your code, create a function.

This function will first check how many channels are available by using the .available() method of the PPMInput object.

If channels are available, it will read the values from each channel and store them in the array.

In the setup section, tell the Teensy to start reading the PPM stream from pin 14.

In the loop section, call the function to read the values sent from the receiver and print the available number of channels, followed by the values for each channel.

Channels 1, 2, 3, and 4 correspond to roll, pitch, yaw, and throttle inputs, respectively. Keep in mind that the array numbering in Arduino starts at 0, so receiverValue[0] corresponds to channel 1 (roll).


A.4.1) Testing the Circuit

Now, connect the Teensy to your computer. The red LED on your receiver should blink.

Turn on the radio controller, and if the receiver is correctly bound to the transmitter (as shown in the previous video), the red LED should stop blinking.

Upload the code to your Teensy and open the serial monitor. You should see that the receiver sends data from 8 channels to the Teensy, of which we will use only 4.

First, move the throttle stick and observe the value changing between 1000 and 2000 microseconds (or 1 to 2 milliseconds). Continue testing the yaw, pitch, and roll sticks to verify they are working correctly.

Conclusion:
Congratulations! You have successfully made a radio connection between your transmitter, receiver, and Teensy microcontroller. In the next video, you will learn how your Teensy can send PWM commands to control the motors.


🔙 Previous Part | Next Part 🔜

↩️ Go Back


Z) 🗃️ Glossary

File Definition
Uncreated files Origin Note
PPM (Pulse Position Modulation) 7 - TUTORIAL - Connect a receiver to your Teensy (PWM and PPM signals)
PPM (Pulse Position Modulation) 7 - TUTORIAL - Connect a receiver to your Teensy (PWM and PPM signals)
PWM (Pulse Width Modulation) 7 - TUTORIAL - Connect a receiver to your Teensy (PWM and PPM signals)
PWM (Pulse Width Modulation) 7 - TUTORIAL - Connect a receiver to your Teensy (PWM and PPM signals)