Pages: [1]   Go Down
Author Topic: Arduino R/C HELP!!!!!  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
Baja California and California
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Tururu!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, im trying to use a RC helicopter circuit board to remote control my arduino, the board is connected to a digital input in the arduino (were suppose to be a servo) i can read successfully the signals sended by the remote control, i used "reverse engineering" of the code, that control a servo, to read with arduino like a servo do, a ITS WORKS, yeahh!, but the problems is that i only be able to read just 1 axis, if write a second part of the code to read a second pin Input, the system crash, i made every kind of test, and nothing, the only thing i only know is that i need to use the interrupt function , suggestions? sorry for my English, i tried to post in the spanish version of the forum, but nobody answer me smiley-sad, ok the code is :

By the way, im trying to make an RC helicopter, estabilized by arduino using accelerometers, an able to move with the RC control, but smoothly smiley, off course ill post my results, pics and code.

///////////INputs
int xPin = 2;          //Input pin of Axis X
/////////
int time = 0;  //counter in microseconds
int lock = 0;  //locks code sequences , to improve performance
int pulse = 0; //store the readed pulse of the remote control, to use it letter.

void setup() {
  pinMode(xPin, INPUT); //put the pin as an input
  Serial.begin(9600); // start com. With the PC
}
void loop()  
{
  readX(); //Read Axis X, thats is connected to Pin 4
}
////////////////////////////////////////////////////////////////////////////////

void readX()
{
  if(digitalRead(xPin) == HIGH) //See if the Input is in High
  {  
    do //Start Loop to count the width of the signal
    {
     time = time + 1;  //is the counter, incremenet every micro second  
     delayMicroseconds(1);  //Delay
    }
    while(digitalRead(xPin) == HIGH); //The loops repeat, over and over, until the Input get LOW state.
    lock = 1; // Unlock the next part of the code, i dont why exactly, but this improve the code A LOT
  }
 
  if((digitalRead(xPin) == LOW)& (lock == 1))//Initiate only when the state is in LOW, and is Unlocked
  {    
    Serial.print("RC-X:"); //Print text to the PC
    Serial.println(time); //Print the value to the PC
    pulse=time;  //save the value to use it next
    time = 0; //restart the clock counter
    lock = 0; // Lock again the code.
  }
}

if you connect a circuit board of a RC airplane or whatever, you will be able to read the signal, the problem is: if you want to read 2 signals, is impossible. HELP!!!!!  :-[
« Last Edit: November 04, 2007, 07:10:35 pm by jordi » Logged

Baja California and California
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Tururu!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

could be a serial Trans. problem?
Logged

Baja California and California
Offline Offline
Full Member
***
Karma: 1
Posts: 110
Tururu!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the post of the Microsecond interrump?, Now i able to read the signals coming from my RC controller with my arduino, here is the way how i made it, support now the reading of two Axis, as the same time, i think is possible to read a more: Good Look to everyone!!!  ;D

This code is for remote control the arduino with a conventional RC controller, like futaba, etc. I connected the central circuit of my RC helicopter to arduino (were suppose to be connected the servos) to digital pin 7 for axis "X" and digital pin 8 for axis "Y".

int xPin = 7;          //Pin IN of servo Axis X
int yPin = 8;          //Pin IN of servo Axis Y
int timeX = 0;  //Show the readed control position
int timeY = 0;
long lastPulseX = 0;    // the time in milliseconds of the last pulse
long lastPulseY = 0;
long mstime = 0;     // reads the time in miliseconds
long hptime = 0;     // Reads the time in Microseconds

extern volatile unsigned long timer0_overflow_count;

unsigned long hpticks (void)
{
  return (timer0_overflow_count << smiley-cool + TCNT0;
}

void setup() {
  Serial.begin(9600);
  pinMode(xPin, INPUT); //The R/C signal pin as an input pin
  pinMode(yPin, INPUT);
}
void loop() {

  if(millis() - lastPulseX >= 5) //Read Axis X every 5 milis
  {
    while(!digitalRead(xPin) == HIGH) //Waits for signal coming from axis X
    {
      continue;
    }
    mstime = millis();
    hptime = hpticks()*4; //When the signal arrives, here we going to record the start time of reciving
    while(!digitalRead(xPin) == LOW){
      continue;
    }
    mstime = millis();
    timeX = (hpticks()*4) - hptime;  //Here takes the diferences of  the Start and finish times, the result is the signal from RC.
    Serial.println(timeX); //Print the results
    Serial.print ("\t");
    hptime = 0;
    lastPulseX = millis();
  }  

  ///////////////////////////The same, but now for axis Y

  if(millis() - lastPulseY >= 5)
  {
    while(!digitalRead(yPin) == HIGH){
      continue;
    }
    mstime = millis();
    hptime = hpticks()*4;
    while(!digitalRead(yPin) == LOW){
      continue;
    }
    mstime = millis();
    timeY = (hpticks()*4) - hptime;    
    Serial.print(timeY);  
    Serial.print ("\t");
    hptime = 0;
    lastPulseY = millis();
  }  
}
« Last Edit: November 06, 2007, 01:40:16 am by jordi » Logged

Pages: [1]   Go Up
Jump to: