Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!

PWM Receiver

Posted by ManTis, in Electronics 25 March 2012 · 705 views

Arduino Quadcopter
As I'm learning more and more about electronics, I have more advanced ideas in my head. Currently my goal is to create a POV display, using motors, servos and shift registers ( which are new stuff I learned about ). However, that's not what I worked on today.

The friend that lent me his Arduino kit is putting together a quadcopter, and he wants it to be Arduino-controlled. He has a FlySky FS-TH9X transmitter that he wants to control the 'copter, and paired FS-R8B receiver that will be used to provide Arduino with information necessary for controlling the flying contraption.

I asked if I can be of any use to him, and he said that indeed I could - I got the job of putting the FlySky controllers to work.

I had absolutely no idea what it's all about, so he gave me a crash course: there are 8 interesting pins on the receiver that I need to connect as arduino inputs, and that the signal is most likely PPM or Pulse Position Modulation, so I should google something about that. The website I found shown that it's a timing based system, where frequency of HIGH signals is used to indicate the value that's transmitted. I asked my friends how to use oscilloscope, because I have never used it before, and I have learned that it's a bit different system. It was PWM or Pulse Width Modulation, not PPM. Instead of frequency of HIGH spikes, HIGH signal lasts for certain time in a loop, and length of that signal can be converted to value. Oscilloscope measurements displayed values of ~1ms for minimum length signal, ~2ms for maximum length signal, and the loop period of 20ms on current controller settings. I only needed to count that and convert to something that could be more intuitive ( I chose a -127 to 127 range, so that it would fit into a signed char ).

I connected all the pins to the inputs 13 to 6, because why not ( naah, just pulling your leg, since I'm communicating through serial with computer, and pins 0 and 1 are used for that communication, I decided to start from other side of board.

With a help of another friend, I quickly put together a code for parsing the pulses into values:

const int minVal = 1000;
const int maxVal = 2000;
char values[8] = {};
unsigned long currentState[8] = {};
unsigned long currentStartCycle[8] = {};
int ch1 = 13;
int ch2 = 12;
int ch3 = 11;
int ch4 = 10;
int ch5 = 9;
int ch6 = 8;
int ch7 = 7;
int ch8 = 6;
int startCycle  = 0;
int currentCycle = 0;

void setup() {			  
  pinMode(ch1, INPUT);	  
  pinMode(ch2, INPUT);	  
  pinMode(ch3, INPUT);	  
  pinMode(ch4, INPUT);	  
  pinMode(ch5, INPUT);	  
  pinMode(ch6, INPUT);	  
  pinMode(ch7, INPUT);	  
  pinMode(ch8, INPUT);	
  startCycle = millis();
  currentCycle = startCycle;

  for ( int i = 0; i < 8; i++)
	values[i] = 0;
	currentState[i] = 0;
	currentStartCycle[i] = 0;
void loop()
  int currentMicros = micros();

  for ( int i = 0; i < 8; i++)
	// trololo
	if ( digitalRead(13 - i) == HIGH &&
		currentState[i] == 0 )
		  currentState[i] = 1;
		  currentStartCycle[i] = currentMicros;
	// very trololo :>
	else if ( digitalRead(13 - i) == LOW &&
		currentState[i] == 1)
		  values[i] = map ( currentMicros - currentStartCycle[i], minVal, maxVal, -127, 127);		
		  currentState[i] = 0;
  currentCycle = millis();
  if ( currentCycle < startCycle )
	startCycle = currentCycle ;

  if ( currentCycle > startCycle + 1000 )
	startCycle = currentCycle;
	for ( int i = 0; i < 8; i++)
	  Serial.print("| Ch");
	  Serial.print(i + 1, DEC );
	  Serial.print(": ");
	  Serial.print(values[i], DEC);	

And it works! I managed to learn how to do remote control Posted Image. Now, my DeathBots that will help me take over the world are another step closer.

Oh yeah, and here's how my desk looked like ( yeah, just showing off ;) )

Posted Image

Till next time!

August 2015 »

30 31