Arduino Forum

Topics => Robotics => Topic started by: Reeghan45 on Oct 25, 2019, 08:15 am

Title: Trouble with Arduino and rc reciever
Post by: Reeghan45 on Oct 25, 2019, 08:15 am
Hi, I am not 100% sure if this is the right forum to ask this but I need a quick solution to this problem.

I am a grade 9 student and my final building project for the year is to build some sort of toy. So what I have decided to do is to make a RC helicopter out of recycled materials to cut down the costs. I am using an arduino UNO as it's processor, an FRSKY XM+ MICRO D16 SBUS FULL RANGE RECEIVER UP TO 16CH as a receiver and a Taranis QX7 as a transmitter.

I have successfully gotten the receiver to talk to the arduino UNO and it is displaying the correct values, but the problem I am encountering is at random the values suddenly change. When the stick of the transmitter is positioned in the middle the code in the serial monitor reads (1500) , just as it should be. But about every 14 frames the value suddenly jumps from 1500 to 957. And then immediately goes back to 1500 again and after another delay it jumps back to 957 again. Which isn't really a big deal with the motors but the servo's jerk around like crazy. Any ideas what the problem is? as far as I can tell there is nothing wrong with my code and the receiver is working fine.

Code:

#include <sbus.h>
#include <Servo.h>

// used pins
#define SBUS_PIN 3   // D3
#define SERVO_PIN 2  // D2
int motorControl = 5;
int Speed = 0;
SBUS sbus;
Servo servo1;

void setup() {
  Serial.begin(115200);
  sbus.begin(SBUS_PIN, sbusBlocking);
  servo1.attach(SERVO_PIN);
  pinMode(motorControl, OUTPUT);
  analogWrite(motorControl, 0);
}


void loop() {
//analogWrite(motorControl, 10);

int sensorValue = sbus.getChannel(4);

Serial.println(sensorValue);

Speed = map(sensorValue, 988, 2011, 0, 179);


  if (sbus.waitFrame()) {

    servo1.write(Speed);
 
   delay (50);

 // analogWrite(motorControl, Speed);
   
  }

 delay(50);

}


(Circuit attached)
Title: Re: Trouble with Arduino and rc reciever
Post by: Paul_KD7HB on Oct 26, 2019, 07:10 pm
Do you suppose the "delay" in your code allows some signals to be missed?

Paul
Title: Re: Trouble with Arduino and rc reciever
Post by: TomGeorge on Oct 28, 2019, 01:25 pm
Hi, 
Welcome to the forum.


Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html  (http://forum.arduino.cc/index.php/topic,148850.0.html). 
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

OPs circuit:
(https://forum.arduino.cc/index.php?action=dlattach;topic=642723.0;attach=329802)

Thanks.. Tom... :)