I just thought I'd add in regards to the two comments.
Firstly in response to srnet with regards to SPI, my understand under the nRF24L01 configuration usage:
- MOSI indicates data transmitted from the microcontroller (master) to nRF24L01 (slave) - i.e. transmitter
- MISO indicates data transmitted from the nRF24L01 (slave) to the microcontroller (master) - i.e. receiver
This would mean in a one-way set-up my transmitter should have MOSI high and receiver should have MISO high.
My question is why am I seeing both MOSI high under this set-up
Reference: NRF24L01 RF Module Pinout, Arduino Examples, Applications, Features
Secondly in response to Robin2:
I have got both modules as far as they can go (limited by USB length) which is about 2 metres.
Power-wise:
- My transmitter (Arduino Pro Mini) has a 10uF capacitor over the 3.3V which is fed through a voltage regulator (also with a 10uF capacitor) power by x2 18650 Li-ion (3.7V) batteries with a common ground to the USB supply (normally this would also power the Pro Mini when in normal use), which are currently giving around 8V as they are fully charged. Currently I have the PC USB and Li-ion (needed to power nRF24L01) are both on at the moment so now quite sure how the Pro Mini itself it handling the RAW 8V and the 5V Vcc.
- The receiver (Arduino Mega 2560) is powered from the 5V feed with Arduino supply currently via USB) with the nRF24L01 sitting on a header with a voltage regulator and capacitor, though not sure of the exact value.
I have reviewed your tutorials (very handy), though I still have issues.
I've combined both the one-way and connection test in the below scripts - with a few tweaks that just help me.
One thing that has struck me is that the radio.write state is always 0, I have tried this on both Arduinos as well.
I have also attached the scripts and Serial outputs a jpg.
I've also attached a table of pin states as nowhere have I found anything talking about the voltage or response of the pins.
- Firstly is my connection okay from the NRF serial output perspective?
- Are the power supplies suitable?
- Furthermore, do you have expectations as to the voltage all SPI pins?
- Is there anything from the script standing out as wrong
Transmitter:
// SimpleTx - the master or the transmitter
// Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
// Define Radio Pins
// Arduino Pro Mini
// MISO = 12 || MOSI = 11 || SCK = 13
#define CE_PIN 5
#define CSN_PIN 6
/*
// Arduino Mega 2560
// MISO = 50 || MOSI = 51 || SCK = 52
#define CE_PIN 44
#define CSN_PIN 45
*/
// Radio Set-up
const byte slaveAddress[5] = {'R','X','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
// Radio Message Set-up
char dataToSend[10] = "Message 0";
char txNum = '0';
// Transmission Timing
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
//====================
void setup(){
// Serial Set-up
Serial.begin(9600);
delay(1000);
printf_begin();
delay(1000);
Serial.println("SimpleTx Starting");
Serial.println();
// Radio Set-up
radio.begin();
Serial.println("Radio Initial Status");
Serial.println();
radio.printDetails();
Serial.println();
delay(1000);
radio.setDataRate(RF24_250KBPS); // Fast enough.. Better range
radio.setPALevel(RF24_PA_MIN);
radio.setChannel(108); // 2.508 Ghz - Above most Wifi Channels
radio.setRetries(3,15); // setRetries(delay,count) - max 15 for both delay and count
// delay: How long to wait between each retry, in multiples of 250us, max is 15. 0 means 250us, 15 means 4000us.
// count: How many retries before giving up, max 15
radio.openWritingPipe(slaveAddress);
radio.stopListening();
Serial.println("Radio Configured Status");
Serial.println();
delay(1000);
radio.printDetails();
Serial.println();
delay(1000);
}
//====================
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
}
//====================
void send(){
bool rslt;
rslt = radio.write(&dataToSend,sizeof(dataToSend));
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
Serial.print("Data Sent: ");
Serial.print(dataToSend);
Serial.print(" || Transmission Status: ");
Serial.print(rslt);
Serial.print(" - ");
if(rslt){
Serial.println("Acknowledge received");
updateMessage();
}
else{
Serial.println("Tx failed");
}
}
//====================
void updateMessage(){
// so you can see that new data is being sent
txNum += 1;
if(txNum > '9'){
txNum = '0';
}
dataToSend[8] = txNum;
}
//====================
Receiver:
// SimpleRx - the slave or the receiver
// Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
// Define Radio Pins
/*
// Arduino Pro Mini
// MISO = 12 || MOSI = 11 || SCK = 13
#define CE_PIN 5
#define CSN_PIN 6
*/
// Arduino Mega 2560
// MISO = 50 || MOSI = 51 || SCK = 52
#define CE_PIN 44
#define CSN_PIN 45
// Radio Set-up
const byte thisSlaveAddress[5] = {'R','X','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
// Radio Message Set-up
char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;
//====================
void setup(){
// Arduino Mega 2560 Set-up
pinMode(53,OUTPUT);
// Serial Set-up
Serial.begin(9600);
delay(1000);
printf_begin();
delay(1000);
Serial.println("SimpleRx Starting");
Serial.println();
// Radio Set-up
radio.begin();
Serial.println("Radio Initial Status");
Serial.println();
radio.printDetails();
Serial.println();
delay(1000);
radio.setDataRate(RF24_250KBPS); // Fast enough.. Better range
radio.setPALevel(RF24_PA_MIN);
radio.setChannel(108); // 2.508 Ghz - Above most Wifi Channels
radio.openReadingPipe(0,thisSlaveAddress);
radio.startListening();
Serial.println("Radio Configured Status");
Serial.println();
delay(1000);
radio.printDetails();
Serial.println();
delay(1000);
}
//====================
void loop(){
getData();
showData();
}
//====================
void getData(){
newData = false; // Ensures acknowledgement is repeatedly check rather than carried over
if(radio.available()){
radio.read(&dataReceived,sizeof(dataReceived));
newData = true;
}
}
//====================
void showData(){
if(newData == true){
Serial.print("Data received ");
Serial.println(dataReceived);
newData = false;
}
}
//====================

SimpleRX_Original_Mod.ino (1.89 KB)
SimpleTX_Original_Mod.ino (2.63 KB)