Pages: [1] 2   Go Down
Author Topic: (solved) problem reading data from rc receiver  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 24, 2013, 08:45:47 pm by jeremybgilbert » Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
« Last Edit: October 24, 2013, 05:36:35 pm by groundfungus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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)smiley-wink.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, whats wrong here?
Code:
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?
« Last Edit: October 24, 2013, 07:07:36 pm by jeremybgilbert » Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Couple of things but the biggy is your if statement.
Code:
if (ch1 > 1800);

the semicolon is in the wrong place.
Try this:
Code:
if(ch1 > 1800) {
     digitalWrite(13, HIGH);
}

and
Code:
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:
const byte ch1 = 3;
const byte led = 13:

Then instead of using the pin number, refer by the variable
pinMode(ch1,INPUT);
etc.
« Last Edit: October 24, 2013, 07:12:39 pm by groundfungus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok i made changes
Code:
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.
Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok i replaced them but now i get an error on 
Code:
  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
Logged

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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.

« Last Edit: October 24, 2013, 08:04:08 pm by groundfungus » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

BCC AZ USA
Offline Offline
God Member
*****
Karma: 21
Posts: 930
It gets hot so it must be working
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Let' see the code.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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);
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: October 24, 2013, 08:20:59 pm by jeremybgilbert » Logged

Pages: [1] 2   Go Up
Jump to: