This is a questions about using RF24Audio and RF24 library in same Arduino sketch.
On node A, I want to transmit data (non-audio) to node B then receive audio data on node A from node B.
This is being attempted using one NRF24L01+ module on node A and one NRF24L01+ module on node B.
Is it possible to do both tasks on same RF module:
- Use RF24 library to transmit non-audio data to node B
- Use RF24Audio library to receive audio data from node A
Right now I'm trying to just test task 1 after calling rfAudio.begin()
, but when I add a call to rfAudio.begin()
in setup()
task 1 no longer receives correct response from node B.
Node B shows it received the expected payload, but node A now always gets null response:
Sent 56924, Got response 0, Round-trip delay 14928 microseconds
Node A (Arduino) Code
RF24 radio(7,8);
RF24Audio rfAudio(radio,1);
const uint64_t addresses[2] = { 0xABCDABCD71LL, 0x544d52687CLL};
void setup() {
Serial.begin(115200);
printf_begin();
rfAudio.begin();
radio.begin();
radio.setPALevel(RF24_PA_MAX);
/* Set our radio options to the audio library defaults */
radio.setChannel(1);
radio.setAutoAck(0);
radio.setCRCLength(RF24_CRC_8);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
radio.printDetails();
radio.startListening();
Serial.println("Setup OK. Begin transmission of audio");
radio.stopListening();
Serial.println(F("Now sending"));
unsigned long start_time = micros();
if (!radio.write( &start_time, sizeof(unsigned long) )) {
Serial.println(F("failed"));
}
radio.startListening(); // Now, continue listening
unsigned long started_waiting_at = micros();
boolean timeout = false;
while ( ! radio.available() ) { // While nothing is received
if (micros() - started_waiting_at > 200000 ) { // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}
rfAudio.begin();
if ( timeout ) { // Describe the results
Serial.println(F("Failed, response timed out."));
} else {
unsigned long got_time;
radio.read( &got_time, sizeof(unsigned long) );
unsigned long end_time = micros();
Serial.print(F("Sent "));
Serial.print(start_time);
Serial.print(F(", Got response "));
Serial.print(got_time);
Serial.print(F(", Round-trip delay "));
Serial.print(end_time - start_time);
Serial.println(F(" microseconds"));
}
}
Node B (RPi) Code
I'm using gettingstarted.cpp example that came with RF24 with 2 changes:
// Radio pipe addresses for the 2 nodes to communicate.
//const uint8_t pipes[][6] = {"1Node","2Node"};
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL};
main()
/* Set our radio options to the audio library defaults */
radio.setChannel(1);
radio.setAutoAck(0);
radio.setCRCLength(RF24_CRC_8);