Go Down

Topic: (solved) problem reading data from rc receiver (Read 1 time) previous topic - next topic

Oct 25, 2013, 12:29 am Last Edit: Oct 25, 2013, 03:45 am by jeremybgilbert Reason: 1
i am trying to read data from a frsky rc receiver. i have an extra channel hooked to A0 on the arduino, when i open the serial monitor it is constantly sending random integers. is there something i can put in-between the signal wire from my receiver and A0 to make it stop constantly sending random integers and only send one or two? i want to be able to flip a switch on my rc transmitter and control a TIP120 hooked to a digital pin on the arduino.

groundfungus

#1
Oct 25, 2013, 12:33 am Last Edit: Oct 25, 2013, 12:36 am by groundfungus Reason: 1
Is the output from the receiver supposed to connect to a servo?  If so, it is a PWM signal and the servo position is encoded as a pulse width.  You hook the receiver output to a DIGITAL input and measure the pulse width with the puilseIn() function.  Then set a digital output based on the pulse width ( if(PW > 1800) turn on tip120).

ill give that a try. thank you! ill post results later. im going to read up on this puilseIn() function and look at some example sketches and maybe that will work.

ok, im lost.... im trying to take pieces of code from multiple sources and make this work but im not getting anywhere.

groundfungus

Code: [Select]
width = pulseIn(ch3Pin, HIGH, 30000);

this will write the pulse width, in microseconds to the variable width.  The pin is low at the start and when it goes high pulseIn() will time till the pin goes low again.  If there is no high going edge within 30mS (30000 microseconds) it will time out and return.
If this doesn't do what you want, post your code and the results (Serial.print(width);).

#5
Oct 25, 2013, 01:57 am Last Edit: Oct 25, 2013, 02:07 am by jeremybgilbert Reason: 1
ok, whats wrong here?
Code: [Select]
int ch1;
int led;
void setup() {

 pinMode(3, INPUT);
 pinMode(13, OUTPUT);

 Serial.begin(9600);

}

void loop() {

 ch1 = pulseIn(3, HIGH, 25000);


 Serial.print("Channel 1:");
 Serial.println(ch1);
 if (ch1 > 1800);
 digitalWrite(13, HIGH);
}


in the serial monitor i see: channel1 1:977 when the switch is off
and i see channel1 1:1990 when the switch is on
the LED is not coming on when the value is over 1800. did i leave something out of the code?

groundfungus

#6
Oct 25, 2013, 02:07 am Last Edit: Oct 25, 2013, 02:12 am by groundfungus Reason: 1
Couple of things but the biggy is your if statement.
Code: [Select]
if (ch1 > 1800);

the semicolon is in the wrong place.
Try this:
Code: [Select]

if(ch1 > 1800) {
    digitalWrite(13, HIGH);
}


and
Code: [Select]
int ch1;
int led;


You should give those variables values to point to the pins, they can be bytes to save sram and const so they are saved in flash not sram

Code: [Select]

const byte ch1 = 3;
const byte led = 13:


Then instead of using the pin number, refer by the variable
pinMode(ch1,INPUT);
etc.

ok i made changes
Code: [Select]
int ch1;
int led;
void setup() {

  const byte ch1 = 3;
  const byte led = 13;
 
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  ch1 = pulseIn(ch1, HIGH, 30000);

  Serial.print("Channel 1:");
  Serial.println(ch1);       
  if(ch1 > 1800) {
     digitalWrite(led, HIGH);
  }

Serial.println();

delay(100);
}


but now in the serial monitor it only shows this:
Channel 1:0
doesnt matter if the switch is on or off it doesnt change.

groundfungus

You put the const byte stuff in void setup(). 
They are out of scope for void loop().  I'll leave it to you to look up variable scoping.
Put them before setup in place of the int declarations (int ch1;).

ok i replaced them but now i get an error on 
Code: [Select]
  ch1 = pulseIn(ch1, HIGH, 30000);

it says
" in function 'void loop()':
error: assignment of read-only variable 'ch1' "

i feel like we are getting close lol
im sorry for all the fuss. i need to brush up on my arduino language lol

groundfungus

#10
Oct 25, 2013, 03:00 am Last Edit: Oct 25, 2013, 03:04 am by groundfungus Reason: 1
You are trying to write the pulse width to the variable that names a pin.  My example use the variable width to hold pulse width.  
It can be an int cause it won't ever be bigger than 32000.
Code: [Select]

int width = pulseIn(ch1, HIGH, 30000);
 Serial.print("Channel 1:  ");
 Serial.println(width);      
 if(width > 1800) {
    digitalWrite(led, HIGH);


We will make it.  I have this fresh in my mind cause I just used it for motor control on my RC paddlewheel tow boat.


well now the serial monitor shows 982 with the switch on or off.

groundfungus


Code: [Select]
const byte ch1 = 3;
const byte led = 13;
void setup() {

  const byte ch1 = 3;
  const byte led = 13;
 
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  int width = pulseIn(ch1, HIGH, 30000);
  Serial.print("Channel 1:  ");
  Serial.println(width);       
  if(width > 1800) {
     digitalWrite(led, HIGH);

  }

Serial.println();

delay(100);
}

#14
Oct 25, 2013, 03:14 am Last Edit: Oct 25, 2013, 03:20 am by jeremybgilbert Reason: 1
wait... something is not right. i think my transmitter lost its bind. bc i uploaded the original code just to check and it still wasnt changing values when i switch it. let me re-bind and see

edit: im dumb. the reason the value wasnt changing is i had un-ticked the auto scroll button. lmao. the values are changing but the led is still not coming on

Go Up