Bonjour ,j'aurai besoin de vos lumières car dernièrement j'ai voulus essayé les modules nRF24L01 pour pourvoir faire communiquer 2 arduino entre elle. Pour cela j'ai voulus pour le récepteur utiliser 2 boutons poussoir afin que le récepteur active soit la led 1 ou la led 2 en fonction du bouton que j'ai activer . En gros si j'appuie sur le bouton 1 alors la led 1 s'active et si le bouton 2 alors la led 2 s'active. Et c'est la que les ennuie commence car l'emmeteur se met à envoyé des infos que je n'ai pas demandé et le récepteur se met à faire clignoter rapidement 1 des deux led sans raison.
Le programme est le pour l'emmeteur:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001"; //Byte of array representing the address. This is the address where we will send the data. This should be same on the receiving side.
int button_pin = 2;
int button_pin1 = 4;
boolean button_state = 0;
boolean button_state1 = 0;
void setup() {
pinMode(button_pin, INPUT);
pinMode (button_pin1, INPUT);
radio.begin(); //Starting the Wireless communication
radio.openWritingPipe(address); //Setting the address where we will send the data
radio.setPALevel(RF24_PA_MAX); //You can set it as minimum or maximum depending on the distance between the transmitter and receiver.
radio.stopListening(); //This sets the module as transmitter
}
void loop()
{
button_state = digitalRead(button_pin);
if (button_state == HIGH)
{
const char text[] = "Your Button State is HIGH";
radio.write(&text, sizeof(text)); //Sending the message to receiver
}
else
{
const char text[] = "Your Button State is LOW";
radio.write(&text, sizeof(text)); //Sending the message to receiver
}
radio.write(&button_state, sizeof(button_state)); //Sending the message to receiver
delay(5);
button_state1 = digitalRead(button_pin1);
if (button_state1 == HIGH)
{
const char text[] = "Your Button State1 is HIGH";
radio.write(&text, sizeof(text)); //Sending the message to receiver
}
else
{
const char text[] = "Your Button State1 is LOW";
radio.write(&text, sizeof(text)); //Sending the message to receiver
}
radio.write(&button_state1, sizeof(button_state1)); //Sending the message to receiver
delay(5);
}
Pour le recepteur :
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
boolean button_state = 0;
boolean button_state1 = 0;
void setup() {
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address); //Setting the address at which we will receive the data
radio.setPALevel(RF24_PA_MAX); //You can set this as minimum or maximum depending on the distance between the transmitter and receiver.
radio.startListening(); //This sets the module as receiver
}
void loop()
{
if (radio.available()) //Looking for the data.
{
char text[32] = ""; //Saving the incoming data
radio.read(&text, sizeof(text)); //Reading the data
radio.read(&button_state, sizeof(button_state));
if (button_state == HIGH && button_state1 == LOW)
{
digitalWrite(6, HIGH);
digitalWrite(3, LOW);
Serial.println(text);
}
else
{
digitalWrite(6, LOW);
digitalWrite(3, LOW);
Serial.println(text);
}
radio.read(&button_state1, sizeof(button_state1)); //Reading the data
if (button_state1 == HIGH && button_state == LOW){
digitalWrite(6,LOW);
digitalWrite(3, HIGH);
Serial.println(text);
}
else {
digitalWrite(6,LOW);
digitalWrite(3, LOW);
Serial.println(text);
}
}
delay(5);
}