Hi Robin2
Thank's a lot for your clear explanation, and your example about simple one way transmission using NFR24L01
I Tried it with my NRF24l01 + PA + LNA
and that's work fine, i just modified a little configuration, adapt it to the hardware connection
I tried another type of simple one way transmission using push button to controll the transmiter
the main idea of the projcet is the transmitter will send "Hello World" message if we push the button on, if we do not push the button, nothing wil transmit
I use pin 7 as vcc for the push button so i set the pin become High
here is the code of Transmitter (using Arduino Mega 2560)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 53); // CE, CSN
const byte address[][6] = {"00001","00002"};
const int pinout = 7;
const int pinin = 4; //input from button to arduino
void setup() {
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(address[1]);
radio.setPALevel(RF24_PA_MIN); // it doesn't matter what power level we use (MIN, LOW, HIGH, MAX)it still works for my trial
radio.stopListening();
pinMode(pinin, INPUT);
pinMode(pinout, OUTPUT);
}
void loop() {
digitalWrite(pinout, HIGH);
int tombol = digitalRead(pinin);
if(tombol != LOW){
txin();}
else{
Serial.println("Press the button to send data");
delay(1000);}
}
void txin(){
bool txan;
const char data[] = "Hello World";
txan = radio.write(&data, sizeof(data));
delay(1000);
if(txan)
Serial.println("Data Sent");
else
Serial.println("Failed");
}
and this is the Receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CNS, CE
const byte address[][6] = {"00001","00002"};
void setup() {
Serial.begin(115200);
radio.begin();
radio.openReadingPipe(0, address[1]);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[90] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
and it works Properly
my question is, i try to make two way transmission which the data is variable
but i try to make simple trial
the main ide is, when i push the button on arduino(1), the first arduino will stop listening and transmit the data (hello world for example) and if we push the button in arduino (2), the second arduino will stop listening and transmit the data
and i try this code for The Arduino(1) (using Arduino uno R3)
include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); //CE,CSN
const byte address[][6] = {"00001","00002"};
const int pinout = 7;
const int pinin = 4;
void setup()
{
// put your setup code here, to run once:
pinMode(pinin, INPUT);
pinMode(pinout, OUTPUT);
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(address[0]);
radio.openReadingPipe(0,address[1]);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(pinout, HIGH);
int button = digitalRead(pinin);
if(button != LOW)
{
radio.stopListening();
abc();
}
else
{
radio.startListening();
Serial.println("Receiving Mode, Press button to send");
delay(1000);
}
if( radio.available() && button == LOW )
{
while (radio.available())
{
char text[] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}
}
void abc()
{
bool txan;
const char data[] = "Hello World1 ";
txan = radio.write(&data, sizeof(data));
delay(1000);
if(txan)
Serial.println("Data Sent");
else
Serial.println("Failed");
}
and this is the code for Arduino(2) (Using Arduino Mega 2560)
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 53); //CE,CSN
const byte address[][6] = {"00001","00002"};
const int pinout = 7;
const int pinin = 4;
void setup()
{
// put your setup code here, to run once:
pinMode(pinin, INPUT);
pinMode(pinout, OUTPUT);
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(address[1]);
radio.openReadingPipe(0,address[0]);
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS);
radio.setRetries(15, 15);
radio.startListening();
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(pinout, HIGH);
int button = digitalRead(pinin);
if(button != LOW)
{
radio.stopListening();
abc();
}
else
{
radio.startListening();
Serial.println("Receiving Mode, Press button to send");
delay(1000);
}
if((radio.available()) && (button == LOW))
{
while (radio.available())
{
char text[50] = "";
radio.read(&text, sizeof(text));
Serial.println(text); }
}
}
void abc()
{
bool txan;
const char data[] = "Hello World 2";
txan = radio.write(&data, sizeof(data));
delay(1000);
if(txan)
Serial.println("Sent");
else
Serial.println("Failed");
}
done uploading but when i try the transmission, it always failed
I hope you can know and explain what is my mistake
thank's a Lot