Has any progress been made in this field? I've looked at several post of similar problems using both the NRF24L01 and Ethernet shield together and couldn't find anything that seemed like a consistent solution. I've tried a few suggestions, like using pin 53 as the CSN for the radio, and nothing has worked so far. I monitored the CS pins while the program ran and every time the radio was selected, it never released the line, causing the server to become non-responsive. I concluded that it wasn't receiving an ack and so continuously retried, tying up the line. I switched from the radio.write command to the radio.writeFast command and the server stopped freezing but nothing is transmitted from the radio. I'm using an Arduino Mega 2560, the Wiznet 5100 Ethernet shield, and of course the NRF24L01. I use the same code for both the NRF24L01 and the Ethernet shield in other projects and they work fine, but this is the first time I've tried to mesh the networks.
Any ideas?
Code:
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>
#include <Ethernet.h>
#define ethernet_cs 10
#define nrf24_ce 6
#define nrf24_csn 7
RF24 radio(nrf24_ce, nrf24_csn);
EthernetServer server(80); //server port
byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEF, 0x01 }; //physical mac address
byte ip[] = { 192, 168, 1, 13 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
const int light_off = 0;
const int light_on = 1;
String readString;
void setup(){
const byte addresses[][6] = {"00001", "00002"};
radio.begin();
radio.openWritingPipe(addresses[1]); // 00001
radio.openReadingPipe(1, addresses[0]); // 00002
radio.setPALevel(RF24_PA_MIN); // MIN, LOW, HIGH, or MAX
radio.stopListening();
radio.enableDynamicAck();
//start Ethernet
Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
//enable serial data print
Serial.begin(9600);
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Command Module Test Page</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Light Control</H1>");
client.print("<input type=submit value=ON style=width:100px;height:45px onClick=location.href='/?on2'>");
client.print("<input type=submit value=OFF style=width:100px;height:45px onClick=location.href='/?off3'>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
// control arduino
if(readString.indexOf('2') >0)//checks for 2
{
radio.writeFast(&light_on,sizeof(light_on),0);
Serial.println("Light ON sent");
}
if(readString.indexOf('3') >0)//checks for 3
{
radio.writeFast(&light_off,sizeof(light_off),0);
Serial.println("Light OFF sent");
}
//clearing string for next read
readString="";
}
}
}
}
}
I put together a test module with an Arduino Nano and another NRF24L01 and use this very simple code (nothing is ever printed to the monitor):
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>
#define nrf24_ce 19
#define nrf24_csn 3
RF24 radio(nrf24_ce, nrf24_csn);
int data_packet = 0;
void setup() {
const byte addresses[][6] = {"00001", "00002"};
radio.begin();
radio.openWritingPipe(addresses[0]); // 00001
radio.openReadingPipe(1, addresses[1]); // 00002
radio.setPALevel(RF24_PA_MIN); // MIN, LOW, HIGH, or MAX
radio.startListening();
radio.enableDynamicAck();
Serial.begin(9600);
Serial.println(data_packet);
}
void loop() {
if (radio.available()){
radio.read(&data_packet,sizeof(data_packet));
Serial.println(data_packet);
}
}