Go Down

Topic: nRF24l01 + arduino help (Read 781 times) previous topic - next topic

CyrilAnthony

Feb 14, 2013, 07:15 am Last Edit: Feb 14, 2013, 07:52 am by CyrilAnthony Reason: 1
hi im trying to make two arduinos communicate via nrf24l01 module but im not able to receive any output

here  is the config and code

config1:

arduino micro + nRF24l01

Code: [Select]
#include<Servo.h>
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
Servo throttle;
Servo rudder;
Servo aileron;
Servo elevator;
boolean b = 0;
byte thisChar[8];
int i;
int data[8];
void arm()
{
  throttle.write(0);
  rudder.write(180);
  delay(1000);
  rudder.write(90);
}
void disarm()
{
 throttle.write(0);
  rudder.write(0);
  delay(1000);
  rudder.write(90);
}

void throttle1(byte a)
{
 a=map(a, 0, 255, 0, 180);
 throttle.write(a);
}
void rudder1(byte b)
{
 b=map(b, 0, 255, 0, 180);
 rudder.write(b);
}
void aileron1(byte c)
{
 c=map(c, 0, 255, 0, 180);
 aileron.write(c);
}
void elevator1(byte d)
{
 d=map(d, 0, 255, 0, 180);
 elevator.write(d);
}
void throlock()
{
}
void altlock()
{
}
void setup()
{
 throttle.attach(5);
 rudder.attach(6);
 aileron.attach(9);
 elevator.attach(10);
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
 Mirf.setRADDR((byte *)"serv1");
 Mirf.payload = 8;
 char data[Mirf.payload];
 Mirf.config();
}
 void loop()
 {
   if(!Mirf.isSending() && Mirf.dataReady()){
   Mirf.getData((byte *) data);
  throttle1(data[1]);
  rudder1(data[2]);
  aileron1(data[3]);
  elevator1(data[4]);
  if (data[5]==0xFF)
  {
    arm();
  }
  if (data[6]==0xFF)
  {
    disarm();
  }

   }
 }



config 2:

Arduino mega 1280 +nRF24l01


Code: [Select]
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <SPI.h>
byte thisChar[8];
int data[8];
int i, a, f;
void setup(){
 Serial.begin(9600);
  Serial.println();
 Mirf.spi = &MirfHardwareSpi;
 Mirf.init();
 Mirf.setTADDR((byte *)"serv1");
 Mirf.payload = 8;
 Mirf.config();
}
void loop(){
  if (Serial.available() > 0) {
 int d,a;
 a=1;
 d=Serial.read();
 switch(d)
{
 case'a':
  Serial.println("arming.....");
  data[0]=0x00;
 data[1]=0x00;
 data[2]=0x00;
 data[3]=0x00;
 data[4]=0x00;
 data[5]=0xFF;
 data[6]=0x00;
 data[7]=0x00;
  Serial.println("ARMED......");
break;
case 'b':
   Serial.println("Disarming....");
     data[0]=0x00;
 data[1]=0x00;
 data[2]=0x00;
 data[3]=0x00;
 data[4]=0x00;
 data[5]=0x00;
 data[6]=0xFF;
 data[7]=0x00;
    Serial.println("disarmed.......");

     
break;
 case 'c':

   data[0]=0x00;
 data[1]=0x64;
 data[2]=0x00;
 data[3]=0x00;
 data[4]=0x00;
 data[5]=0x00;
 data[6]=0x00;
 data[7]=0x00;
    Serial.println("MED");

     
break;
 case 'e':

   data[0]=0x00;
 data[1]=0xFF;
 data[2]=0x00;
 data[3]=0x00;
 data[4]=0x00;
 data[5]=0x00;
 data[6]=0x00;
 data[7]=0x00;
    Serial.println("MAX");

     
break;
}
   
   Mirf.send((byte *) &data);
   while(Mirf.isSending()){
   }

}
}



the arduino micro is connected to a kkmulticopter board flashed with xCopter 4.5 firmware
im a total noob just getting to know arduino
thanks.



Nick Gammon

Read this before posting a programming question


Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.


Quote
Code: [Select]
    data[Mirf.payload];


What is that line supposed to do?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

CyrilAnthony

sorry i didnt edit it before posting .

Go Up