I made a system which between Arduino and Pi3 communication at the same time both of them transmitter and receiver. There are 6 current sensor (only transmitter) device and 3 on-off switch (transmitter and receiver). Each device works when run individually. When i started all device switches miss data. But every time different switch miss data. I don’t understand this situation. I think it is look like a communication problem. Thanks for advice.
#include<SPI.h>
#include<RF24.h>
RF24 radio(9,10); //ce and cs pins
#define B0 8
const uint64_t listenPipe = 0xE8E8F0F0E1LL;
const uint64_t writePipe = 0xF5F5F5F5E1LL;
void setup(void)
{
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0x70);
radio.openReadingPipe(1, listenPipe);
radio.openWritingPipe(writePipe);
radio.enableDynamicPayloads();
radio.powerUp();
pinMode(B0, OUTPUT);
}
void loop(void){
radio.startListening();
char receivedMessage[32] = {0};
char message = “LIGHT DONE”;
if(radio.available()) {
radio.read(receivedMessage, sizeof(receivedMessage));
radio.stopListening();
}
if(receivedMessage[0] == ‘3’ && receivedMessage[1] == ‘3’){ // 33 message = Light On
digitalWrite(B0, HIGH);
delay(200);
for(int i = 0; i < 40; i++)
radio.write(&message, sizeof(message));
delay(200);
radio.startListening();
}
else if(receivedMessage[0] == ‘4’ && receivedMessage[1] == ‘4’){ // 44 message = Light Off
digitalWrite(B0, LOW);
delay(200);
for(int i = 0; i < 40; i++)
radio.write(&message, sizeof(message));
delay(200);
radio.startListening();
}
delay(500);
}
Robin2
December 1, 2017, 10:44am
#2
Please always use the code button <> for code so it looks like this
#include<SPI.h>
#include<RF24.h>
RF24 radio(9,10); //ce and cs pins
#define B0 8
const uint64_t listenPipe = 0xE8E8F0F0E1LL;
const uint64_t writePipe = 0xF5F5F5F5E1LL;
void setup(void)
{
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0x70);
radio.openReadingPipe(1, listenPipe);
radio.openWritingPipe(writePipe);
radio.enableDynamicPayloads();
radio.powerUp();
pinMode(B0, OUTPUT);
}
void loop(void){
radio.startListening();
char receivedMessage[32] = {0};
char message[] = "LIGHT DONE";
if(radio.available()) {
radio.read(receivedMessage, sizeof(receivedMessage));
radio.stopListening();
}
if(receivedMessage[0] == '3' && receivedMessage[1] == '3'){ // 33 message = Light On
digitalWrite(B0, HIGH);
delay(200);
for(int i = 0; i < 40; i++)
radio.write(&message, sizeof(message));
delay(200);
radio.startListening();
}
else if(receivedMessage[0] == '4' && receivedMessage[1] == '4'){ // 44 message = Light Off
digitalWrite(B0, LOW);
delay(200);
for(int i = 0; i < 40; i++)
radio.write(&message, sizeof(message));
delay(200);
radio.startListening();
}
delay(500);
}
Without seeing the code for the other device it is hard to know what is happening.
You have a lot of delay()s when your listener is not listening. Could that be part of the problem?
…R
Simple nRF24L01+ Tutorial
Get rid of all delays.
The NRF24L01+ can buffer three packets, the fourth+ just gets dropped.
Don’t send 40 packets for each event.
Robin2
December 1, 2017, 1:41pm
#5
meeeeesut:
It is my Pi3 py code.
I can't figure out how to copy that code to my text editor - I have not come across that website before.
Why not just attach the Python code as a txt file if the Forum won't accept .py files?
...R
Robin2
December 1, 2017, 4:23pm
#7
I can't make sense of your Python program. Why has it got all those while True : loops? Code is much easier to develop and maintain if you break a program into short single purpose functions. I suspect a single function could be used for all those WHILEs
Can you write a short Python program that only deals with the nRF24 to illustrate the problem? Wireless problems are hard to debug, so make the code as simple as you possibly can until you reliable communication working.
Plus what @Whandall said.
...R
I don't see any calls to radio.available() in the python code...