Created
January 27, 2016 06:48
-
-
Save jgarland79/69a18bc77693a544ea52 to your computer and use it in GitHub Desktop.
Am I doing this right? I'm not getting anything at all. It says "Starting" and then nothing at all... Other NRF24 lib examples work with my arduino, but mine doesn't even print the radio config like it should before it enters the loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include "nRF24L01.h" | |
#include "RF24.h" | |
#include "printf.h" | |
RF24 radio(9,10); | |
const int min_payload_size = 4; | |
const int max_payload_size = 32; | |
const int payload_size_increments_by = 1; | |
int next_payload_size = min_payload_size; | |
char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
printf_begin(); | |
Serial.println(F("Starting")); | |
radio.begin(); | |
radio.setAutoAck(false); | |
radio.enableDynamicPayloads(); | |
radio.openReadingPipe(0,0xC7B6A5); | |
radio.openReadingPipe(1,0xFCFBFA); | |
radio.openReadingPipe(2,0xF1); | |
radio.setChannel(31); //PCB channel 3 | |
radio.startListening(); | |
radio.printDetails(); | |
} | |
void loop() { | |
while ( radio.available() ) | |
{ | |
// Fetch the payload, and see if this was the last one. | |
uint8_t len = radio.getDynamicPayloadSize(); | |
// If a corrupt dynamic payload is received, it will be flushed | |
if(!len){ | |
continue; | |
} | |
radio.read( receive_payload, len ); | |
// Put a zero at the end for easy printing | |
receive_payload[len] = 0; | |
// Spew it | |
Serial.print(F("Got response size=")); | |
Serial.print(len); | |
Serial.print(F(" value=")); | |
Serial.println(receive_payload); | |
// First, stop listening so we can talk | |
radio.stopListening(); | |
// Send the final one back. | |
radio.write( receive_payload, len ); | |
Serial.println(F("Sent response.")); | |
// Now, resume listening so we catch the next packets. | |
radio.startListening(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment