Ethernet, nRF24L01, SD problem

Hi. Please How i connect Ethernet, nRF24L01 and SD to mega 2560 when each part needs MISO, MOSI, SCK pins? :~ pls help

Those three devices share the MISO, MOSI, and SCK lines. The ethernet shield uses D10 for the w5100 slave select and D4 for the SD slave select. The nRF24L01 must use another pin for its slave select.

All slave select pins should be set to OUTPUT and HIGH before starting any of those devices.

hmm.. so please how I wire it? How i share miso, mosi and sck :~ I use this SD module: Ehernet Module: And nRF24L01:

Before I say anything, I will warn you about that SD card reader. SD cards are 3.3v data lines. The Mega is 5v data lines. This causes problems with some SD cards, and can damage the card or the Mega. Just so you know.

Connect all MOSI, MISO and SCK lines to the Mega's SPI pins. MISO = D50 MOSI = D51 SCK = D52

Connect the ethernet card slave select to D10. Connect the SD card reader slave select to D4 Connect the nRF24L01 CE and CS pins to any other unused digital pins.

Thank you for your warning... I try it :) Thanks

Ok, I wired it. I try ethernet but not works :~ … eth. module blinking, but when i pinging, the packets is´t receive…

This my code:

#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[] = {192,168,1,10};
byte Ethernet::buffer[700];
static byte staticmask[] = {255,255,255,128};
void setup () {
 pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.begin(57600);
  Serial.println("PING Demo");
 
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) 
    Serial.println( "Failed to access Ethernet controller");
 
  if (!ether.staticSetup(myip))
    Serial.println("Failed to set IP address");
}
 
void loop() {
 
  ether.packetLoop(ether.packetReceive());  
}

Thanks for your help

I think the library EtherCard uses pin 8 for CS.

// VCC - 3.3V // GND - GND // SCK - Pin 13 // SO - Pin 12 // SI - Pin 11 // CS - Pin 8

Try pin 8 for the ethernet card

but when i use mega 2560

Can i rewrite library for pins which I use?

Well my answer was wrong, sorry dude. I had double check that and the library has this method:

uint8_t EtherCard::begin (const uint16_t size, const uint8_t* macaddr, uint8_t csPin) {

In your code you have this:

if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)

So the third argument accept the CSN pin and since you are passing 10 you are ok to use pin 10 in MEGA. Try to run the program just with the ethernetcard connected to see what happens.

not works :/ ping still not received, i try CMD, or ChcekIp program I try digitalWrite(10,LOW); .. but nothing

I try it with arduino pro mini, but still nothing :/

Any help? :~

Hello, I'm having the same problem. I read that nRF24L01 can't realy work with the ethernet shield ( especially the one with the ENC28J60) . The only solution that can be used is to connect the nRF24L01 to another pins and use a softSPI library. I tried multiple SoftSPI and RF24 and I managet to get one or two working but when I added the EtherCard code in the project my arduino just crashes (Windows says: USB device not recognized and I have to manual reset it when uploading new code). The code for the softSPI and NRF is here: https://github.com/shnae/rf24_plus_softSPI. I then foud out about this: http://imall.iteadstudio.com/im120410001.html. It's an arduino clone that has a library for NRF24L01 that can be used with soft SPI, but this code does not compile on my computer, I get some errors like: error: 'digitalWriteFast2' was not declared in this scope I'm out of energy and I have no other idea on how to make this work, If you manage to make this work please share your solution or code with us.

Most of us discover that the 3.3v power supply is the culprit and putting a 10mF or so electrolytic across the supply, close to the rf24 module makes it all work as it should.

So if you have not tried that, please do.

I don't know if this is helpful but I use the ETHERNET - the NRF24L01 and the SD together - remember however that the NRF24L01 needs 3v3 power - the data lines don't need special treatment. I did come across something however in the early days...

Now this might be absolute rot - but when I first tried to run them together - I could never get reliable operation. I then read something about the SD library and ended up - after any access to the SD library, I manually reset the SD enable..

} dataFile.close(); digitalWrite(MEMORYCHIP,HIGH);

As above... and since I started to do that - I have never had any problems running them together. I think at the time I just assumed it was some silly mistake in the library. But it works for me.

Now this might be absolute rot - but when I first tried to run them together - I could never get reliable operation. I then read something about the SD library and ended up - after any access to the SD library, I manually reset the SD enable..

This makes sense because if the library wont release the CSN PIN the module remains active and the SPI interface is occupied. One way of debugging that is to look the voltage level of the CSN pin and see if the library is releasing the pin after using the SD card.

Hello,

I don’t think that what Mr. Peter Scargill said applies to me, because I use software SPI for the nRF24L01 module, and hardware SPI for the ENC28J60, so basically I don’t need to release any CSN pin or SPI interface, each one being independent.
I think what happens in my case is thant the RAM memory of my arduino is not enough for both the EtherCard and soft SPI/RF24 library to run together.
I will post here my code, maybe someone could help me.
This is the RF24 with softSPI example that works for me

#include <SPI.h>
#include <EEPROM.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(6,7);

const int role_pin = 8;

const uint64_t talking_pipes[5] = { 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL, 0xF0F0F0F0B4LL, 0xF0F0F0F0A5LL, 0xF0F0F0F096LL };
const uint64_t listening_pipes[5] = { 0x3A3A3A3AD2LL, 0x3A3A3A3AC3LL, 0x3A3A3A3AB4LL, 0x3A3A3A3AA5LL, 0x3A3A3A3A96LL };

typedef enum { role_invalid = 0, role_ping_out, role_pong_back } role_e;

// The debug-friendly names of those roles
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};

// The role of the current running sketch
role_e role;

//
// Address management
//

// Where in EEPROM is the address stored?
const uint8_t address_at_eeprom_location = 0;

// What is our address (SRAM cache of the address from EEPROM)
// Note that zero is an INVALID address.  The pong back unit takes address
// 1, and the rest are 2-6
uint8_t node_address;

void setup(void)
{
  //
  // Role
  //

  // set up the role pin
  pinMode(role_pin, INPUT);
  digitalWrite(role_pin,HIGH);
  delay(20); // Just to get a solid reading on the role pin

  // read the address pin, establish our role
  if ( digitalRead(role_pin) )
    role = role_ping_out;
  else
    role = role_pong_back;

  //
  // Address
  //

  if ( role == role_pong_back )
    node_address = 1;
  else
  {
    // Read the address from EEPROM
    uint8_t reading = EEPROM.read(address_at_eeprom_location);

    // If it is in a valid range for node addresses, it is our
    // address.
    if ( reading >= 2 && reading <= 6 )
      node_address = reading;

    // Otherwise, it is invalid, so set our address AND ROLE to 'invalid'
    else
    {
      node_address = 0;
      role = role_invalid;
    }
  }

  //
  // Print preamble
  //

  Serial.begin(57600);
  printf_begin();
  printf("\n\rRF24/examples/starping/\n\r");
  printf("ROLE: %s\n\r",role_friendly_name[role]);
  printf("ADDRESS: %i\n\r",node_address);

  //
  // Setup and configure rf radio
  //

  radio.begin();

  //
  // Open pipes to other nodes for communication
  //

  // The pong node listens on all the ping node talking pipes
  // and sends the pong back on the sending node's specific listening pipe.
  if ( role == role_pong_back )
  {
    radio.openReadingPipe(1,talking_pipes[0]);
    radio.openReadingPipe(2,talking_pipes[1]);
    radio.openReadingPipe(3,talking_pipes[2]);
    radio.openReadingPipe(4,talking_pipes[3]);
    radio.openReadingPipe(5,talking_pipes[4]);
  }

  // Each ping node has a talking pipe that it will ping into, and a listening
  // pipe that it will listen for the pong.
  if ( role == role_ping_out )
  {
    // Write on our talking pipe
    radio.openWritingPipe(talking_pipes[node_address-2]);
    // Listen on our listening pipe
    radio.openReadingPipe(1,listening_pipes[node_address-2]);
  }

  //
  // Start listening
  //

  radio.startListening();

  //
  // Dump the configuration of the rf unit for debugging
  //

  radio.printDetails();

  //
  // Prompt the user to assign a node address if we don't have one
  //

  if ( role == role_invalid )
  {
    printf("\n\r*** NO NODE ADDRESS ASSIGNED *** Send 1 through 6 to assign an address\n\r");
  }
}

void loop(void)
{
  //
  // Ping out role.  Repeatedly send the current time
  //

  if (role == role_ping_out)
  {
    // First, stop listening so we can talk.
    radio.stopListening();

    // Take the time, and send it.  This will block until complete
    unsigned long time = millis();
    printf("Now sending %lu...",time);
    radio.write( &time, sizeof(unsigned long) );

    // Now, continue listening
    radio.startListening();

    // Wait here until we get a response, or timeout (250ms)
    unsigned long started_waiting_at = millis();
    bool timeout = false;
    while ( ! radio.available() && ! timeout )
      if (millis() - started_waiting_at > 250 )
        timeout = true;

    // Describe the results
    if ( timeout )
    {
      printf("Failed, response timed out.\n\r");
    }
    else
    {
      // Grab the response, compare, and send to debugging spew
      unsigned long got_time;
      radio.read( &got_time, sizeof(unsigned long) );

      // Spew it
      printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time);
    }

    // Try again 1s later
    delay(1000);
  }

  //
  // Pong back role.  Receive each packet, dump it out, and send it back
  //

  if ( role == role_pong_back )
  {
    // if there is data ready
    uint8_t pipe_num;
    if ( radio.available(&pipe_num) )
    {
      // Dump the payloads until we've gotten everything
      unsigned long got_time;
      bool done = false;
      while (!done)
      {
        // Fetch the payload, and see if this was the last one.
        done = radio.read( &got_time, sizeof(unsigned long) );

        // Spew it
        printf("Got payload %lu from node %i...",got_time,pipe_num+1);
      }

      // First, stop listening so we can talk
      radio.stopListening();

      // Open the correct pipe for writing
      radio.openWritingPipe(listening_pipes[pipe_num-1]);

      // Retain the low 2 bytes to identify the pipe for the spew
      uint16_t pipe_id = listening_pipes[pipe_num-1] & 0xffff;

      // Send the final one back.
      radio.write( &got_time, sizeof(unsigned long) );
      printf("Sent response to %04x.\n\r",pipe_id);

      // Now, resume listening so we catch the next packets.
      radio.startListening();
    }
  }

  if (Serial.available())
  {
    // If the character on serial input is in a valid range...
    char c = Serial.read();
    if ( c >= '1' && c <= '6' )
    {
      EEPROM.write(address_at_eeprom_location,c-'0');

      printf("\n\rManually reset address to: %c\n\rPress RESET to continue!",c);
      while(1) ;
    }
  }
}

This is the ethernet code that works for me

#include <EtherCard.h>

#define RELAY_PIN	5

static byte mymac[]  = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[]   = {192,168,1,2};
byte Ethernet::buffer[700];

char* on  = "ON";
char* off = "OFF";

boolean relayStatus;
char* relayLabel;
char* linkLabel;

void setup () {
 
  Serial.begin(57600);
  Serial.println("WebRelay Demo");

  if(!ether.begin(sizeof Ethernet::buffer, mymac, 10))
    Serial.println( "Failed to access Ethernet controller");
  else
    Serial.println("Ethernet controller initialized");

  if(!ether.staticSetup(myip))
    Serial.println("Failed to set IP address");

  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);  
  relayStatus = false;
  relayLabel = off;
  linkLabel = on;
}
  
void loop() {
 
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  
  if(pos) {
        
    if(strstr((char *)Ethernet::buffer + pos, "GET /?ON") != 0) {
      relayStatus = true;
      relayLabel = on;
      linkLabel = off;
    } else if(strstr((char *)Ethernet::buffer + pos, "GET /?OFF") != 0) {
      relayStatus = false;
      relayLabel = off;
      linkLabel = on;
    }
    digitalWrite(RELAY_PIN, relayStatus); 
		
    BufferFiller bfill = ether.tcpOffset();
    bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
      "Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
      "<html><head><meta name='viewport' content='width=200px'/></head><body>"
      "<div style='position:absolute;width:200px;height:200px;top:50%;left:50%;margin:-100px 0 0 -100px'>"
      "<div style='font:bold 14px verdana;text-align:center'>Relay is $S</div>"
      "
<div style='text-align:center'>"
      "<a href='/?$S'><img src='http://www.lucadentella.it/files/bt_$S.png'></a>"
      "</div></div></body></html>"
      ), relayLabel, linkLabel, linkLabel);

      ether.httpServerReply(bfill.position());
    }
}

These programs work independently with both the nrf24l01 and ECN28j60 modules connected but when I combine the code, on my console I receive just one part of the nrf24l01 configuration status then it stops and does nothing.

The RF24 code uses this library https://github.com/shnae/rf24_plus_softSPI/tree/master/RF24Soft
The ENC28J60 code it’s an example code from here: http://www.lucadentella.it/en/category/enc28j60-arduino/ and uses the EtherCard library by JeeLabs Café.