Smart Home Automation Forum
[Arduino IDE demo source code for KC868-A6]--#01-nRF24L01_code - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A6 (https://www.kincony.com/forum/forumdisplay.php?fid=22)
+--- Thread: [Arduino IDE demo source code for KC868-A6]--#01-nRF24L01_code (/showthread.php?tid=1859)



[Arduino IDE demo source code for KC868-A6]--#01-nRF24L01_code - KinCony Support - 04-25-2022

[Arduino IDE demo source code for KC868-A6]--#01-nRF24L01_code
Receive code

Code:
/*Receive code*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 22
#define CSN_PIN 5

const uint64_t id = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

#define SIZE 32            // this is the maximum for this example. (minimum is 1)
char buffer[SIZE + 1];     // for the RX node
uint8_t counter = 0;       // for counting the number of received payloads

void setup()
{
   Serial.begin(9600);
   delay(1000);
   Serial.println("Nrf24L01 Receiver Starting");
   radio.begin();
   radio.openReadingPipe(1,id);
   radio.startListening();;
}

void loop()
{
    if (radio.available()) {         // is there a payload?
      radio.read(&buffer, SIZE);     // fetch payload from FIFO
      Serial.print("Received:");
      Serial.print(buffer);          // print the payload's value
      Serial.print(" - ");
      Serial.println(counter++);     // print the received counter
    }
}


Transmitter code

Code:
/*Transmitter code*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 22
#define CSN_PIN 5

const uint64_t abc = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);
char data[] = "Hello World, KinCony";

void setup()
{
   Serial.begin(9600);
   radio.begin();
   radio.openWritingPipe(abc);
}

void loop()
{
   radio.write( data, sizeof(data) );
}
   

.zip   1.nRF24L01.zip (Size: 1.5 KB / Downloads: 287)


.txt   KC868-A6_pin_define.txt (Size: 421 bytes / Downloads: 264)