Pages: [1]   Go Down
Author Topic: nRF24l01 + arduino help  (Read 696 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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.


 
« Last Edit: February 14, 2013, 01:52:48 am by CyrilAnthony » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18728
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    data[Mirf.payload];

What is that line supposed to do?
Logged


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

sorry i didnt edit it before posting .
Logged

Pages: [1]   Go Up
Jump to: