Bonjour,
Etant débutant en Arduino et ayant un projet dans le cadre de mon DUT je viens à vous pour solliciter votre aide.
J'ai pour projet de faire communiquer 6 modules nrf24l01 avec une carte arduino uno. Pour cela j'utilise la bibliothèque RF24. J'ai fait deux programmes, l'un pour l'émission et l'autre pour la récepteur entre la carte et un module. Cependant je ne comprend comment faire communiquer plusieurs émetteur à une carte.
Merci d'avance pour vos réponses
Cordialement
Johan Sanchez
bonjour,
chaque carte émettrice aura dans son envoi un identifiant par exemple.
/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 1;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(9,10);
/**********************************************************/
//byte addresses[][6] = {"1Node","2Node"};
const uint8_t adresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool role = 1;
void setup() {
Serial.begin(9600);
Serial.println(F("RF24/examples/GettingStarted"));
printf_begin();
radio.begin();
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_MAX);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.openWritingPipe(adresses[1]);
radio.openReadingPipe(1,adresses[0]);
// Start the radio listening for data
radio.startListening();
radio.printDetails();
}
void loop() {
/****************** Ping Out Role ***************************/
radio.stopListening(); // First, stop listening so we can talk.
Serial.println(F("Now sending"));
unsigned long time = micros(); // Take the time, and send it. This will block until complete
if (!radio.write( &time, sizeof(unsigned long) )){
Serial.println(F("failed"));
}
radio.startListening(); // Now, continue listening
unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
boolean timeout = false; // Set up a variable to indicate if a response was received or not
while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 200000 ){ // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}
if ( timeout ){ // Describe the results
Serial.println(F("Failed, response timed out."));
}else{
unsigned long got_time; // Grab the response, compare, and send to debugging spew
radio.read( &got_time, sizeof(unsigned long) );
unsigned long time = micros();
// Spew it
Serial.print(F("Sent "));
Serial.print(time);
Serial.print(F(", Got response "));
Serial.print(got_time);
Serial.print(F(", Round-trip delay "));
Serial.print(time-got_time);
Serial.println(F(" microseconds"));
}
// Try again 1s later
delay(1000);
} // Loop
Voila mon code pour l'emetteur.
/*
* Getting Started example sketch for nRF24L01+ radios
* This is a very basic example of how to send data from one node to another
* Updated: Dec 2014 by TMRh20
*/
#include <SPI.h>
#include "RF24.h"
#include <printf.h>
/****************** User Config ***************************/
/*** Set this radio as radio number 0 or 1 ***/
bool radioNumber = 0;
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(9,10);
/**********************************************************/
//byte addresses[][6] = {"1Node","2Node"};
const uint8_t adresses[][6] = {"1Node","2Node"};
// Used to control whether this node is sending or receiving
bool role = 0;
void setup() {
Serial.begin(9600);
Serial.println(F("RF24/examples/GettingStarted"));
printf_begin();
radio.begin();
// Set the PA Level low to prevent power supply related issues since this is a
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
radio.setPALevel(RF24_PA_MAX);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.openWritingPipe(adresses[0]);
radio.openReadingPipe(1,adresses[1]);
// Start the radio listening for data
radio.startListening();
radio.printDetails();
}
void loop() {
/****************** Pong Back Role ***************************/
unsigned long got_time;
if( radio.available()){
// Variable for the received timestamp
while (radio.available()) { // While there is data ready
radio.read( &got_time, sizeof(unsigned long) ); // Get the payload
}
radio.stopListening(); // First, stop listening so we can talk
radio.write( &got_time, sizeof(unsigned long) ); // Send the final one back.
radio.startListening(); // Now, resume listening so we catch the next packets.
Serial.print(F("Sent response "));
Serial.println(got_time);
}
} // Loop
Et mon code pour le recepteur.
Je ne sais pas comment changer les adresses 1Node et 2Node sur les programmes.
j'ai pas parlé d'adresse, juste mettre dans l'envoi un identifiant.
style
N1-lesdonnéesenvoyées
N2-lesdonnéesenvoyées
etc.....
pour le récepteur, tu parse après avec le - et tu prends Nx pour identifier.
il serait plus simple de dire ce que tu veux faire exactement.