I have set up a system using 4 arduino clones, each wired to an NRF24L01+ radio. I am using the RF24 library by maniacbug (https://github.com/maniacbug/RF24) and have set-up the nodes with 1 base node as a receiver and 3 child nodes that transmits continuously to the receiver.
What I want to do is to send the read and analog value wirelessly from the child nodes to the base node as fast as possible. I used the starping example as a guide and it looks almost realtime when only 1 child node is active. When I turn on another child node, most of the time the update stops for a while then continue on, with randomly updating either child 1 or child 2.
I'm guessing there's a collision that's causing the delays. How do I lessen these delays? I'm thinking of having some sort of scheduling system for the children to send their messages (like, child2 will send only after child1, etc.) I also tried radio.setAutoAck(false)
in an attempt to lessen the delays but that made all my readings stop altogether.
base node:
#include "Timer.h"
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
Timer t;
const uint64_t pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL };
unsigned int values[3] = {0,0,0};
void setup(void)
{
Serial.begin(115200);
printf_begin();
//printf("Receiver Node Active\n\r");
radio.begin();
radio.openReadingPipe(1,pipes[0]);
radio.openReadingPipe(2,pipes[1]);
radio.openReadingPipe(3,pipes[2]);
radio.openReadingPipe(4,pipes[3]);
radio.openReadingPipe(5,pipes[4]);
radio.startListening();
radio.printDetails();
t.every(1, print_values); //call print_values() every 1ms
}
void loop(void)
{
int sender_id;
uint8_t pipe_num;
if ( radio.available(&pipe_num) )
{
unsigned int message;
bool done = false;
while (!done)
{
done = radio.read( &message, sizeof(message) );
}
sender_id = pipe_num - 1;
values[sender_id-1] = message;
}
delay(1);
t.update();
}
void print_values(){
//formatted for arduinoscope
printf("%d %d %d 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n", values[0], values[1], values[2]);
}
// vim:ai:ci sts=2 sw=2 ft=cpp
child node:
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
RF24 radio(0,1);
const int SW01 = 18;
const int SW02 = 19;
const uint64_t pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL };
int node_id;
void setup(void)
{
node_id=3; //hard coded id
radio.begin();
radio.openWritingPipe(pipes[node_id]);
}
void loop(void)
{
unsigned int val = analogRead(A0);
radio.write( &val, sizeof(val) );
//delay(1);
}
writeAckPayload
.