NFR24 module code help


what im trying control forward , backward functions on 2 seperate buttons have first code rx remote secound tx
code: [select]
/* simple project remote controlling nrf24l01+ radios.
 we have 2 nodes, transmitter (this one) , receiver attached car.
 the idea transmit  2 parameters , 1 direction (backward, or forward speed) other steering (left, or right degree of rotation).
 the nrf24l01 transmit values in type of "uint8_t" maximum of 256 each packet, values of direction divided (10) @ tx side,
 then multiplied 10 again @ rx side.
 the rx rules output received parameters port 3 , 6 servo , esc are attached
 a condition required prevent controller transmitting values not useful (like 1480-1530 esc , 88-92 servo) save more power as can
 */

#include <spi.h>
#include "nrf24l01.h"
#include "rf24.h"
#include "printf.h"
#include "motordriver.h"
//
// hardware configuration
//
// set nrf24l01 radio on spi bus plus pins 9 & 10
rf24 radio(9,10);

uint8_t data[2] ; //buffer store received data
const uint8_t buffer_size = sizeof(data);

 
const int tx_led=4;// transmission indicator
const int transmit_pin=6;
 int transmit_enable;
 int forwrdbutton=2;
 int backwrdbutton=3;
 
//
// topology
//

// single radio pipe address 2 nodes communicate.
const uint64_t pipe = 0xe8e8f0f0e1ll;


//
// setup
//

void setup(void)
{
motordriver.init();
motordriver.setspeed(50,motorb);
motordriver.setspeed(50,motora);
  serial.begin(9600);
  printf_begin();

  //
  // setup , configure rf radio
  //

  radio.begin();

  radio.openwritingpipe(pipe);
  //
  // dump configuration of rf unit debugging
  //

  radio.printdetails();

  //
  // set buttons
  //

 
   pinmode(forwrdbutton,input );
   pinmode(backwrdbutton,input);
   pinmode(transmit_enable,input);
    pinmode(tx_led,output);
  digitalwrite(tx_led,low);
 
 
}

void loop(void)
{

    if(digitalread(forwrdbutton)==1)
      motordriver.goforward();
    else if(!backwrdbutton)
      motordriver.stop(); 
  transmit_enable=!digitalread(transmit_pin);
  //an error ratio around +3,-3 appears  coming joystick  time,
  //so neglect them (using following if statement) because make system transmitting data , useless , waste of power

  if(!forwrdbutton)
  {
    printf("now sending...");
    bool ok = radio.write( data, buffer_size );
    if (ok)
    printf("ok\n\r");
    else
    printf("failed\n\r");
    delay(15);
    digitalwrite(tx_led,high); //turn led on after transmission
  }
  else digitalwrite(tx_led,low);//keep led off when no transmission
}
[code]
/*
 written by: mujahed altahle
 
this work licensed under creative commons attribution-noncommercial-sharealike 3.0 unported license.
to view copy of license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
or send letter creative commons, 444 castro street, suite 900, mountain view, california, 94041, usa.

 */
/* simple project remote controlling nrf24l01+ radios.
 we have 2 nodes, transmitter (this one) , receiver attached car.
 the idea transmit  2 parameters , 1 direction (backward, or forward speed) other steering (left, or right degree of rotation).
 the nrf24l01 transmit values in type of "uint8_t" maximum of 256 each packet, values of direction divided (10) @ tx side,
 then multiplied 10 again @ rx side.
 the rx rules output received parameters port 3 , 6 servo , esc are attached
 a condition required prevent controller transmitting values not useful (like 1480-1530 esc , 88-92 servo) save more power as can
 */
 
#include "motordriver.h"
#include <spi.h>
#include "nrf24l01.h"
#include "rf24.h"
#include "printf.h"
//
// hardware configuration
//

// set nrf24l01 radio on spi bus plus pins 9 & 10
rf24 radio(8,53);

servo servo; //steering servo declaration
servo esc; // electronic speed contoller declaration

// single radio pipe address 2 nodes communicate.
const uint64_t pipe = 0xe8e8f0f0e1ll;

//
// payload
//

uint8_t received_data[2];
uint8_t num_received_data =sizeof(received_data);

//
// setup
//

void setup(void)
{
  delay(3000); //wait until esc starts in case of arduino got power first
 
  //
  // print preamble
  //

  serial.begin(57600);
  printf_begin();

  //
  // setup , configure rf radio
  //

  radio.begin(); //begin operation of chip.
  // simple sketch opens single pipes these 2 nodes communicate
  // , forth.  1 listens on it, other talks it.
  radio.openreadingpipe(1,pipe);
  radio.startlistening();
  //
  // dump configuration of rf unit debugging
  //
  radio.printdetails();
}


void loop(void)
{
  // if there data ready
  if ( radio.available() )
  {
    bool done = false;
   
    while (!done)
    {
      // fetch payload, , see if last one.
      done = radio.read( received_data, num_received_data );
     
    }
  }
}[/code]

the transmit pin im confused on connect module or simple open on 1 , ran pin ground on other


Arduino Forum > Using Arduino > Programming Questions > NFR24 module code help


arduino

Comments