/* Demonstrates simple RX and TX operation between RF24 (TX) and NRFLite (RX). Defaults of NRFLite are used. Any of the Basic_RX examples can be used as a receiver. Please read through 'NRFLite.h' for a description of all the methods available in the library. Radio Arduino CE -> 9 CSN -> 10 (Hardware SPI SS) MOSI -> 11 (Hardware SPI MOSI) MISO -> 12 (Hardware SPI MISO) SCK -> 13 (Hardware SPI SCK) IRQ -> No connection VCC -> No more than 3.6 volts GND -> GND */ #include #include "nRF24L01.h" #include "RF24.h" #include "printf.h" // nRF24L01+ configuration defines #define RX_RADIO_ID 0 // send commands to #define TX_RADIO_ID 1 // ourself for receive #define PIN_RADIO_CE 9 #define PIN_RADIO_CSN 10 #define SPI_SPEED 4000000 struct RadioPacket // Any packet up to 32 bytes can be sent. { uint8_t FromRadioId; uint32_t OnTimeMillis; uint32_t FailedTxCount; }; const uint64_t pipes[2] = { 0x0004030201LL, 0x0104030201LL }; RF24 radio(PIN_RADIO_CE,PIN_RADIO_CSN, SPI_SPEED); RadioPacket _radioData; void setup() { Serial.begin(115200); printf_begin(); radio.begin(); radio.setChannel(100); // channel 100 radio.setPALevel(RF24_PA_MAX); // MAX power radio.setDataRate(RF24_2MBPS); // 2MBPS radio.setRetries(1, 15); // 250+1*250us delay, 15 retries radio.enableDynamicAck(); // Enable auto ack radio.enableAckPayload(); // enable payload with ack and dynamic payload length radio.setCRCLength(RF24_CRC_8); // CRC8 radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1, pipes[1]); // Dump the configuration of the rf unit for debugging radio.printDetails(); _radioData.FromRadioId = TX_RADIO_ID; } void loop() { _radioData.OnTimeMillis = millis(); Serial.print("Sending "); Serial.print(_radioData.OnTimeMillis); Serial.print(" ms"); radio.stopListening(); if (radio.write(&_radioData, sizeof(_radioData), true)) { Serial.println("...Success"); } else { Serial.println("...Failed"); _radioData.FailedTxCount++; } radio.startListening(); delay(1000); }