Working with RC and Arduino: Part 1

The HK-T6A V2 is a classic 6-channel RC Transmitter, best option for starters.

HK-T6XV2-M1
HK-T6XV2-M1

The 4 channels are used for flying while rest 2 can be used for landing purposes. It is programmable as well. For that purpose one need to have the programming cable. It requires 12 V as the optimum voltage supply level. However, the status of LED shows the voltage level.

NEVER EXCEED 12 V..

Red : Voltage < 9.1 V

Orange :  9.4 V < Voltage < 10.1 V

Green : 10.4 < Voltage < 12

I used 12 V adapter with 1 A current rating.

Its range is upto 1 km for LOS, which is quite sufficient. Another big point is its cheap receivers, which comes for 9 $ only.

That is enough for the blah blah.. 😛

Getting To The Interfacing Part:

Now for the interfacing part, one need to understand the types of waves and communication happening between the Tx & Rx. For each channel, a continuous pulse with different HIGH and low duration is sent. Fortunately, one does not need to go into the communication depth to understand its interfacing. 🙂

Purpose of whole practice is to count the duration for which the pulse was HIGH.

There are two ways to do that.

1. Polling method: pulseIn function in arduino

2. Interrupt method – described in next blog

POLLING METHOD:

There is a standard simple function in arduino for this purpose – PulseIn()

The syntax for the function is – pulseIn(pin, value).

e.g.. to count the duration for high/low pulse on pin 5, we will use pulseIn(5, HIGH/LOW).

Here is the connection and the complete arduino code for this.

Connection Diagram
Connection Diagram

The corresponding arduino code is :


// code starts here

/*
 RC PulseIn Demonstration
 By: Shantanu Sharma
 Date: 20/10/2013.
 contact me at : shantanu.785@gmail.com
 */

int ch1=5;
 int ch2=6;
 int ch3=7;
 int led = 13;
 void setup() {

pinMode(ch1, INPUT); // Set our input and output pins as such
 pinMode(ch2, INPUT);
 pinMode(ch3, INPUT);
 pinMode(led, OUTPUT);
 Serial.begin(9600); //initialise serial

}

void loop() {

ch1 = pulseIn(5, HIGH, 25000); // Read the HIGH pulse width of
 ch2 = pulseIn(6, HIGH, 25000); // each channel with timeout specified
 ch3 = pulseIn(7, HIGH, 25000);

Serial.print("Channel 1:"); // Printing the value of
 Serial.print(ch1); // each channel
 Serial.print("\t");
 Serial.print("Channel 2:");
 Serial.print(ch2);
 Serial.print("\t");
 Serial.print("Channel 3:");
 Serial.println(ch3); // for new line

digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(400); // wait for a second
 digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
 delay(400);
 }

//

Now , the actual reason for giving this ineffective, slow, resource wasting code comes.

DISADVANTAGES:

The pulseIn() function works by the way of polling the pin. Polling is such a waste of CPU cycles. Once the CPU is in Delay function or for sake any function, it will not be checking the HIGH pulse and hence all the RC commands sent during this are smoothly ignored by the controller. This leads to blunders, you can think of our own.. 😛

So this code is not recommended at all.

Check out in next blog for Interrupt method .

Advertisements

About Shantanu Sharma

Currently working as Software R&D member in Samsung R&D India.

Posted on October 27, 2013, in 8-Bit Embedded World, Projects and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s