Hey all,
I am trying to use two NRF24L01 to communicate: one sends data from the A0 and A1 pins and the receiver transmits that to the serial monitor. They seem to be connecting fine, but when I use the serial monitor I just get lots of zeros even when I move the joysticks;
00
00
00
00
00
etc.
I have 10 uF electrolytic capacitors on both modules, and I have already done an independent test of the joysticks, in other words, everything hardware is A-ok.
Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.
The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work
You could try this, It complies ok and should work, I don't have my hardware to hand to test and I know the code should work.
You need to make sure that your CE and CSN pins are set up correct first. If you do not receive any data coming in from the TX unit the Rx flashes LED 13 and displays it on the Seral monitor.
Try it let us know how you get on.
Like Robin2 say's have a good read through the tutorial and try the samples, I did and have learnt a hell of a lot and this is how I got my modules working.
TX code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 7
#define CSN_PIN 8
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
const uint64_t pipeOut = 0xB3B4B5B6A3LL;//0xE8E8F0F0E1LL; //IMPORTANT: The same as in the receiver
struct MyData {
int Channel1;
int Channel2;
};
MyData data;
void setup() {
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setDataRate(RF24_250KBPS);
radio.openWritingPipe(pipeOut);
}
void loop() {
data.Channel1 = analogRead(A0) ;
data.Channel2 = analogRead(A1);
radio.write(&data, sizeof(MyData));
}
RX code:
//####################################################
//# Include all the libraries #
//####################################################
#include <Wire.h> //Wire libary
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
const uint64_t pipeIn = 0xB3B4B5B6A3LL;//0xE8E8F0F0E1LL64 bit encrypicted code
#define CE_PIN 7
#define CSN_PIN 8
const long TX_interval = 500; //Error flag timer for not recieving from the tx
unsigned long lastRecvTime = 0; // escape from recieve data
unsigned long TX_previousMillis = 0; // stores the last mills
RF24 radio(CE_PIN, CSN_PIN);
bool newData = false;
bool lostData = false;
#define Error_led 13
struct MyData {
int Channwl1_IN;
int Channel2_IN;
};
MyData data;
void resetData()
{
unsigned long TX_Error = millis();
newData = false;
if (TX_Error - TX_previousMillis >= TX_interval) {
// save the last time you blinked the LED
TX_previousMillis = TX_Error;
digitalWrite(Error_led, !digitalRead(Error_led));
}
if (newData == false) { //new data received from eLevel
//newData = false;
Serial.println("TX SIGNAL LOST/NO SIGNAL");
}
}
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS); // Both endpoints must have this set the same
radio.setAutoAck(false);
radio.openReadingPipe(1, pipeIn);
radio.startListening();
resetData();
}//--(end setup )---
void recvData()
{
while ( radio.available() ) {
radio.read(&data, sizeof(MyData));
lastRecvTime = millis();
newData = true;
}
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
recvData();
showData();
unsigned long now = millis();
if ( now - lastRecvTime > 1000 ) { //if data stops coming IN within 1 second, lets us know
// signal lost?
resetData();
}
}
void showData() {
Serial.print("Channwl 1:" );
Serial.print(data.Channwl1_IN);
Serial.print(", ");
Serial.print("Channwl 2:" );
Serial.print(data.Channel2_IN);
Serial.println(" ");
}