I have 3 nodes in my system. One centralNode
and two sensor nodes (right
and left
).
Sensor nodes transmit data to the centralNode
and receive from it.
centralNode
may transmit to both nodes and receive from them.
I'm using an Arduino nano for central node and Uno and Mega for sensor nodes. I'm using nRF24's base module (with regulators and caps and all) but one node does not have base module (Although I've given it a descent 3.3 V and bypass caps).
Here is my problem:
1- It seems the centralNode can't detect which nodes data it is receiving. I can sometimes get it to work using different delays for sensorNodes but again, on reset it messes up the data.
How can I detect which data's reading the centralNode is receiving?
2- How can I use radio.available(??) I've put 0, 1 , 2 and pipe addresses in ?? but it does not work (prints garbage data) radio.available's API
Here are the codes:
centralNode:
/*
Testing multi-node functionality of nRF24l01+
This is centralNode code
BOM
1 Arduino Nano centralNode
1 Ardiuno Uno rightSensorNode
1 Arduino Mega leftSensorNode
3 nRF24l01+
*/
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
#define CEpin 6
#define CSpin 7
RF24 radio(CEpin, CSpin);
byte addresses [][6] = {"1Node", "2Node", "3Node"};
int rightNodeCount = 0;
int leftNodeCount = 0;
void setup() {
Serial.begin(115200);
Serial.println(F("This is the central node"));
printf_begin();
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1, addresses[1]);
radio.openReadingPipe(2, addresses[2]);
radio.startListening();
radio.printDetails();
}
void loop() {
if (radio.available()) {
radio.read(&rightNodeCount, sizeof(rightNodeCount));
radio.read(&leftNodeCount, sizeof(leftNodeCount));
}
// if (radio.available(1)) {
// radio.read(&leftNodeCount, sizeof(leftNodeCount));
// }
Serial.println("centralNode is reporting:");
Serial.print("centralNode address : ");
Serial.println((char *)addresses[0]);
Serial.print("rightNode address : ");
Serial.println((char *)addresses[1]);
Serial.print("rightNodeCount = ");
Serial.println(rightNodeCount);
Serial.print("leftNode address : ");
Serial.println((char *)addresses[2]);
Serial.print("leftNodeCount = ");
Serial.println(leftNodeCount);
Serial.println("---END OF REPORT---\n\n\n\n");
delay(500);
}
rightSensorNode:
/*
Testing multi-node functionality of nRF24l01+
This is rightSensorNode code
BOM
1 Arduino Nano centralNode
1 Ardiuno Uno rightSensorNode
1 Arduino Mega leftSensorNode
3 nRF24l01+
*/
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
#define CEpin 7
#define CSpin 8
RF24 radio(CEpin, CSpin);
byte addresses [][6] = {"1Node", "2Node", "3Node"};
int rightNodeCount = 0;
void setup() {
Serial.begin(115200);
Serial.println(F("This is the right node"));
printf_begin();
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(addresses[1])
radio.printDetails();
}
void loop() {
rightNodeCount++;
Serial.println("Sending data to centralNode");
Serial.print("rightNode address : ");
Serial.println((char *)addresses[1]);
Serial.print("rightNodeCount = ");
Serial.println(rightNodeCount);
radio.write(&rightNodeCount, sizeof(rightNodeCount));
Serial.println("---END OF REPORT---\n\n\n\n");
delay(1000);
}
leftSensorNode:
/*
Testing multi-node functionality of nRF24l01+
This is leftSensorNode code
BOM
1 Arduino Nano centralNode
1 Ardiuno Uno rightSensorNode
1 Arduino Mega leftSensorNode
3 nRF24l01+
*/
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
#define CEpin 7
#define CSpin 8
RF24 radio(CEpin, CSpin);
byte addresses [][6] = {"1Node", "2Node", "3Node"};
int leftNodeCount = 0;
void setup() {
Serial.begin(115200);
Serial.println(F("This is the left node"));
printf_begin();
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.openWritingPipe(addresses[2]);
radio.printDetails();
}
void loop() {
leftNodeCount++;
Serial.println("Sending data to centralNode");
Serial.print("leftNode address : ");
Serial.println((char *)addresses[2]);
Serial.print("leftNodeCount = ");
Serial.println(leftNodeCount);
radio.write(&leftNodeCount, sizeof(leftNodeCount));
Serial.println("---END OF REPORT---\n\n\n\n");
delay(1000);
}