Hola, antes de ir a la pregunta en especifico quisiera explicar de que se trata.
Estoy haciendo un avión controlado por arduino siguiendo un tutorial en instructables (All About Radio Control Aviation Hobby and a DiY Radio Transmitter for Electric Airplanes).
En el transmisor se debe definir que pines digitales del arduino nano se deben utilizar (en este caso conecte al 2 y el 3), no tengo idea como se agregan ni en que parte (al final adjunto el código)
En cuanto al receptor no aparece que pines digitales van destinados a los dos servos de los alerones y el ESC (Electronic speed controller).
seria de mucha ayuda que alguien con mas experiencia me pueda asesorar con esto, estoy recien comenzando en la parte de la programación en arduino
TX
/* By Ayan Pahwa
competely open source, feel free to edit and improve.
No responsibilty in any case is taken by the dev of this code. Use it wisely at your won risk */
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#define Throttle A0
#define Rudder A1
#define Elevator A2
#define LeftAileron 2
#define RightAileron 3 //Ailerons will be activated when these pins recieve active low
const uint64_t pipe = 0xE8E8F0F0E1LL; //Unique address for communication
RF24 radio(9,10); //SPI bus+9,10 pins
int t,x,y;
int joystick[5]; //variable array to store joystick readings
void setup()
{
//Serial.begin(9600); //Enable serial for debugging
digitalWrite(LeftAileron, HIGH); //Activating pull-ups
digitalWrite(RightAileron, HIGH);
radio.begin();
radio.setPALevel(RF24_PA_MAX); //For Maximum range
radio.setPayloadSize(10);
radio.setDataRate(RF24_250KBPS);
radio.setRetries(15,15);
radio.openWritingPipe(pipe);
}
void loop()
{
t=analogRead(Throttle);
x=analogRead(Rudder);
y=analogRead(Elevator);
int l=digitalRead(LeftAileron);
int r=digitalRead(RightAileron);
joystick[0]=map(t,0,1023,1000,2000); //map values according to desired throws
joystick[1]=map(x,0,1023,30,160);
joystick[2]=map(y,0,1023,45,150);
joystick[3]=l;
joystick[4]=r;
radio.write(joystick, sizeof(joystick));
}
RX
/* By Ayan Pahwa
competely open source, feel free to edit and improve.
No responsibilty in any case is taken by the dev of this code. Use it wisely at your won risk */
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include<Servo.h>
Servo Throttle,Rudder,Elevator,LeftAileron,RightAileron ;
const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(9,10);
int joystick[5];
void setup()
{
/*Serial.begin(9600);
delay(1000);
Serial.println("Starting Rx");*/ //Enable serial for debugging
attachMotors();
calibrateMotors();
radio.begin();
detachMotors();
radio.setPALevel(RF24_PA_MAX);
radio.setPayloadSize(10);
radio.setDataRate(RF24_250KBPS);
radio.setRetries(15,15);
radio.openReadingPipe(1,pipe);
radio.startListening();;
}
void loop()
{
detachMotors();
if(radio.available())
{
bool done=false;
while(!done)
{
done=radio.read(joystick,sizeof(joystick));
}
attachMotors();
int a=joystick[0];
int b= joystick[1]; //stores values from tx
int c=joystick[2];
int d=joystick[3];
int e=joystick[4];
//Serial.println(a);
//Serial.println(b);
//Serial.println(c);
//Serial.println(d);
//Serial.println(e);
// Serial.println(f);
delay(20);
Throttle.writeMicroseconds(a); //write values to motor
Rudder.write(b);
Elevator.write(180-c);
if(d== LOW)
{
LeftAileron.write(180); ////to activate right aileron
RightAileron.write(180);
delay(15);
}
else if(e == LOW)
{
LeftAileron.write(0); //to activate left aileron
RightAileron.write(0);
delay(15);
}
else
{
LeftAileron.write(100);
RightAileron.write(110); //Ailerons at neutral pos
delay(15);
}
}
else
{
calibrateMotors();
delay(15);
}
}
void attachMotors()
{
Throttle.attach(3);
Rudder.attach(4);
Elevator.attach(5);
LeftAileron.attach(6);
RightAileron.attach(7);
}
void calibrateMotors()
{
Rudder.write(90);
Elevator.write(90);
LeftAileron.write(100);
RightAileron.write(110); //centering servo shafts
}
void detachMotors()
{
Throttle.detach();
Rudder.detach();
Elevator.detach();
LeftAileron.detach();
RightAileron.detach();
}
TX.ino (1.34 KB)
RX.ino (2.22 KB)