Difference between revisions of "NRF2401 Wireless Communication"

From Tuxamito
Jump to: navigation, search
(Created page with " <pre> #include <SPI.h> #include <nRF24L01.h> #include <RF24.h> RF24 radio(7, 8); const byte rxAddr[6] = "00001"; char text[32] = {0}; void setup() { while (!Serial);...")
(No difference)

Revision as of 14:38, 29 October 2016


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";
char text[32] = {0};

void setup()
{
  while (!Serial);
  Serial.begin(115200);
  
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  
  radio.startListening();


  Serial.println("Listening!");
}

void loop()
{
  if (radio.available())
  {
    radio.read(text, sizeof(text));  
    Serial.println(text);
  }
}


#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>

byte i = 0;
char text[24] = {0};

RF24 radio(7, 8);


const byte rxAddr[6] = "00001";

void setup()
{
  Serial.begin(115200);
  printf_begin();

  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();

  Serial.println("Ready!");
}

void loop()
{
  sprintf(text, "Hello World %d", i);
  Serial.println(text);
  radio.write(text, sizeof(text));
  i++;

  //radio.printDetails();
  delay(1000);
}