Hola a todos, después de leer un montón, probar muchísimos sketch, librerías y demás, y no encontrar lo que busco, os pregunto a los entendidos si hay alguna manera de hacer lo que os voy a exponer.
Dispongo de un arduino DUE, que es el receptor y 4 arduinos nano que son los emisores, en cada nano tengo un nrf24l01 para que pueda comunicarse con el receptor, si he conseguido que se comunique pero no los 4 a la vez.
Os pongo el código ultimo que he probado a ver si alguno de vosotros me puede orientar.
De momento solo tengo 3 puestos
Emisor1
/*
* 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"
/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node","3Node","4Node"};
// Used to control whether this node is sending or receiving
struct LECTURA {
byte id;
byte angulo;
};
void setup() {
Serial.begin(57600);
Serial.println(F("Emisor 1"));
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_LOW);
radio.setChannel (120);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.openWritingPipe(addresses[0]);
}
void loop() {
LECTURA enviar;
enviar.id=1;
enviar.angulo=10;
Serial.println(F("Enviando 1..."));
if (!radio.write( &enviar, sizeof(LECTURA) )){
Serial.println(F("fallo al enviar"));
}
delay(1000);
} // Loop
Emisor2
/*
* 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"
/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node","3Node","4Node"};
// Used to control whether this node is sending or receiving
struct LECTURA {
byte id;
byte angulo;
};
void setup() {
Serial.begin(57600);
Serial.println(F("Emisor 2"));
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_LOW);
radio.setChannel(121);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.openWritingPipe(addresses[0]);
}
void loop() {
LECTURA enviar;
enviar.id=2;
enviar.angulo=20;
Serial.println(F("Enviando 2..."));
if (!radio.write( &enviar, sizeof(LECTURA) )){
Serial.println(F("fallo al enviar"));
}
delay(1000);
} // Loop
Emisor3
/*
* 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"
/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node","3Node","4Node"};
struct LECTURA {
byte id;
byte angulo;
};
void setup() {
Serial.begin(57600);
Serial.println(F("Emisor 3"));
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_LOW);
radio.setChannel (122);
// Open a writing and reading pipe on each radio, with opposite addresses
radio.openWritingPipe(addresses[0]);
}
void loop() {
LECTURA enviar;
enviar.id=3;
enviar.angulo=30;
Serial.println(F("Enviando 3..."));
if (!radio.write( &enviar, sizeof(LECTURA) )){
Serial.println(F("fallo al enviar"));
}
delay(1000);
} // Loop
Receptor
//Lee de 3 sensores distintos, cada uno debe enviar un byte con su id (1 2 3) en ASCII
#include <SPI.h>
#include "RF24.h"
/****************** User Config ***************************/
/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8 */
RF24 radio(7,8);
/**********************************************************/
byte addresses[][6] = {"1Node","2Node","3Node","4Node"};
struct LECTURA {
byte id;
byte angulo;
};
void setup() {
Serial.begin(57600);
radio.begin();
// Set the PA Level low to prevent power supply related issues since this is a
radio.setPALevel(RF24_PA_LOW);
// getting_started sketch, and the likelihood of close proximity of the devices. RF24_PA_MAX is default.
}
void loop() {
LECTURA recibido;
uint8_t canal=0;
for (canal=120;canal < 123;canal++){
radio.setChannel (canal);
radio.openReadingPipe(1,addresses[0]);
radio.startListening();
Serial.print("Leyendo en canal "); Serial.print(canal); Serial.println();
if( radio.available()){
radio.read( &recibido, sizeof(LECTURA) ); // Get the payload
Serial.print("Recibido id "); Serial.print(recibido.id); Serial.print("Recibido angulo "); Serial.print(recibido.angulo); Serial.println();
}
radio.stopListening(); // First, stop listening so we can talk
}
delay (300);
} // Loop
Quizá haya alguna manera mejor de hacerlo, solo necesito que cada emisor envié al receptor 4 variables diferentes.
Un saludo.