RC Input channels to code

hello friends,

i have the following code with me. i am planning to control the DC brushed motors using a RC Receiver (FrSky).

The hardware is actually a unbranded 20A DC Motor Driver (attaching image of the hardware...) integrated with Arduino and is reading inputs from the RC Receiver on PIN 6 and PIN 7.

PIN 6 being Forward & Reverse (Channel 2 in RC Receiver)

and

PIN 7 being Left & Right (Channel 1 in RC Receiver)

int RightMotor = 9;     // pin maping according to schematics
int LeftMotor = 10;
int R_dir = 8;
int L_dir = 12;

void setup() {



   TCCR1B = TCCR1B & 0B11111000 | 0B00000100;          // reducing the pwm freq
  pinMode(RightMotor,OUTPUT);
  pinMode(LeftMotor,OUTPUT);
  pinMode(R_dir,OUTPUT);
  pinMode(L_dir,OUTPUT);
 
}

void loop() {
 Forward(255);

}

void Forward(unsigned int Pwm)
{
   digitalWrite(R_dir,HIGH);
   digitalWrite(L_dir,HIGH);
   analogWrite(RightMotor,Pwm);
   analogWrite(LeftMotor,Pwm);
}

void Backward(unsigned int Pwm)
{
   digitalWrite(R_dir,HIGH);
   digitalWrite(L_dir,HIGH);
   analogWrite(RightMotor,Pwm);
   analogWrite(LeftMotor,Pwm);
}

void Left(unsigned int Pwm)
{
   digitalWrite(R_dir,LOW);
   digitalWrite(L_dir,HIGH);
   analogWrite(RightMotor,Pwm);
   analogWrite(LeftMotor,Pwm);
}

void Right(unsigned int Pwm)
{
   digitalWrite(R_dir,HIGH);
   digitalWrite(L_dir,LOW);
   analogWrite(RightMotor,Pwm);
   analogWrite(LeftMotor,Pwm);
}

void Stop()
{
   digitalWrite(RightMotor,LOW);
   digitalWrite(LeftMotor,LOW);
}

thanking in advance for the help.

Do you have a question ?

Thank you for the reply. :relaxed:

Yes... actually I am not understanding how to map the input channels to the program already avaliable.

Here is an example that reads 2 input channels fed by RC signals, makes an alteration to the pulse lengths and outputs the revised pulse to 2 pins to be fed to a quadcopter flight controller.

You don't need the parts of the program beyond receiving the incoming pulses but you can use the pulse length information to trigger the appropriate functions in your program.

const byte yawInPin = 7;
const byte yawOutPin = 8;
unsigned long yawDuration;

const byte thrInPin = 9;
const byte thrOutPin = 10;
unsigned long thrDuration;

void setup()
{
  Serial.begin(115200);
  pinMode(yawInPin, INPUT);
  pinMode(yawOutPin, OUTPUT);

  pinMode(thrInPin, INPUT);
  pinMode(thrOutPin, OUTPUT);
}

void loop()
{
  yawDuration = pulseIn(yawInPin, HIGH);
  yawDuration = map(yawDuration, 1000, 1800, 980, 2020);
  digitalWrite(yawOutPin, HIGH);
  delayMicroseconds(yawDuration);
  digitalWrite(yawOutPin, LOW);  

  thrDuration = pulseIn(thrInPin, HIGH);
  thrDuration = map(thrDuration, 1000, 2000, 980, 2020);
  digitalWrite(thrOutPin, HIGH);
  delayMicroseconds(thrDuration);
  digitalWrite(thrOutPin, LOW);  
}

The two variables you should look at are yawDuration and thrDuration. Try printing them before the map() function and watch them vary depending on the RC signals received.

NOTE that the RC receiver and Arduino must have a common GND connection.

ukhelibob.... thanks a great for the information. i will try it out and report back.

:slight_smile:

thank you once again.