Hola a todos, como siempre las cosas que sobre el papel son faciles, luego a la hora de la verdad te pueden dar muchiiiisimos quebraderos decabeza...
Pues el tema es que quiero comunicar un ardunio UNO con un arduino MEGA con los nrf24l01+, hasta aqui todo parece muy facil... pues un dia y medio... me ha costado poder conectarlos uffff
He probado las librerias Mirf, NRF24 y RF24 master, que son las mas conocidas:
Decir que tengo en cuenta los pines correctos tanto en el UNO como en el MEGA, con la unica libreria que he conseguido conectarlos ha sido con la Mirf, peeeero solo a 2MB, si lo pongo a 1MB o 250KB no funciona...
ya estoy harto de probar cosas... querria comunicarlos a 250KB para un mayor alcance pero no hay manera...
Si alguien sabe como o tiene un codigo QUE FUNCIONE con esa libreria o la que sea se lo agradeceria mucho.
Os pongo mi codigo por si os sirve:
EMISOR ARDUINO UNO:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int rate = 1023;
void setup()
{
Serial.begin(9600);
Mirf.cePin = 9; //ce pin on Mega 2560, REMOVE THIS LINE IF YOU ARE USING AN UNO
Mirf.csnPin = 10; //csn pin on Mega 2560, REMOVE THIS LINE IF YOU ARE USING AN UNO
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload = sizeof(rate);
Mirf.channel = 102;
Mirf.config();
//250kbit, 0dB => (0x27) || 1Mbit, 0dBm, Setup LNA => (0x07) || 2Mbit, 0dBm, Setup LNA => (0x0f)
// Select a data rate of 250 kbps (the lowest possible) and a transmit
// power of 0dB (the largest possible) for maximum receiver sensitivity.
// At this data rate, maintaining <1% saturation with 16 packets sent
// per second requires a packet length < 250000/1600 = 156 bits.
// With a 3-byte address and 1-byte CRC, the framing overhead is
// 6*8+1=49 bits so the maximum payload size is 13*8 = 104 < 107.
Mirf.configRegister(RF_SETUP,0x0f); //0x0f
Mirf.configRegister(EN_AA, 0x00); //Disable auto-acknowledge
//byte rf_setup = 0;
//Mirf.readRegister( RF_SETUP, &rf_setup, sizeof(rf_setup) );
//Serial.print( "rf_setup = " );
//Serial.println( rf_setup, BIN );
//delay(1000);
}
void loop()
{
//rate = analogRead(A0);
Serial.println(rate,DEC);
Mirf.setTADDR((byte *)"clie1");
Mirf.send((byte *) &rate);
while(Mirf.isSending())
{
}
//delay(100);
}
RECEPTOR MEGA:
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
int rate;
int val=0;
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13,LOW);
Serial.begin(9600);
Mirf.cePin = 9; //ce pin on Mega 2560, REMOVE THIS LINE IF YOU ARE USING AN UNO
Mirf.csnPin = 10; //csn pin on Mega 2560, REMOVE THIS LINE IF YOU ARE USING AN UNO
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload = sizeof(rate);
Mirf.channel = 102;
Mirf.config();
//250kbit, 0dB => (0x26) || 1Mbit, 0dBm, Setup LNA => (0x07) || 2Mbit, 0dBm, Setup LNA => (0x0f)
// Select a data rate of 250 kbps (the lowest possible) and a transmit
// power of 0dB (the largest possible) for maximum receiver sensitivity.
// At this data rate, maintaining <1% saturation with 16 packets sent
// per second requires a packet length < 250000/1600 = 156 bits.
// With a 3-byte address and 1-byte CRC, the framing overhead is
// 6*8+1=49 bits so the maximum payload size is 13*8 = 104 < 107.
Mirf.configRegister(RF_SETUP,0x0f); //0x0f
Mirf.configRegister(EN_AA, 0x00); //Disable auto-acknowledge
//byte rf_setup = 0;
//Mirf.readRegister( RF_SETUP, &rf_setup, sizeof(rf_setup) );
//Serial.print( "rf_setup = " );
//Serial.println( rf_setup, BIN );
//delay(1000);
}
void loop()
{
while(!Mirf.dataReady())
{
//digitalWrite(13,LOW);
}
Mirf.getData((byte *) &rate);
Serial.println(rate);
if (rate == 1023)
{
if (val ==0)
{
val = 1023;
digitalWrite(13,HIGH);
}
else
{
val = 0;
digitalWrite(13,LOW);
}
}
//delay(100);
}
Cuando enciendes el emisor manda el valor 1023 continuamente, el receptor si recibe dicho valor parpadea el led 13, ademas de poder verlo con el monitor serie. Es sencillo pero funciona, la libreria es "Mirf"
http://playground.arduino.cc/uploads/InterfacingWithHardware/Mirf.zip
No hagais caso del nombre de las fotos, el del arduino UNO es el emisor, y el del MEGA el receptor