I have been working on a project that requires the use of both a wiznet-type w5100 Ethernet shield like this and an nrf24l01 radio at the same time. The problem I ran into was that both of these peripherals use the SPI protocol, and I could not get them both working simultaneously (the Ethernet shield has it’s pins hardwired to the hardware SPI, of course). After doing some reading on the SPI protocol, I found out that there seems to be some kind of issue that, according to the freetronics website, causes the w5100 chip to maintain control of the SPI bus even when another device has been selected.
After much searching, and much experimenting, I finally found a workaround that seems to be working reliably for me. The solution was to use ‘software’ or ‘bit-banged’ SPI. This allows the Ethernet shield to happily commandeer the hardware SPI pins, while the nrf24l01 (or any other peripheral, I suppose) to operate on a separate, emulated SPI bus.
The credit for this goes to a user on the Arduino forums, nicoverduin, who suggested using some software SPI libraries already available and modifying maniacbug’s nrf24 library to use the software spi interface.
Here is the step by step:
1.) Download the modified maniacbug library and softSPI libraries here.
2.) Copy the libraries to your Arduino libraries folder.
3.) Configure your Arduino/Ethernet-shield/nrf24l01 like this (you can also modify the pin configuration if needed. Instructions are in the readme file on the linked github repository):
If you would like to download the fritzing file, here you go:
Once you have completed the above steps, you can upload your sketch to the Arduino and you should be able to browse to the IP of your Arduino with Ethernet shield and you will see a web page that tells you the last message received over the nrf24l01.
There is one major caveat to all of this, however. I have found that sometimes when I am working with the softSPI version of the nrf24 library and then I switch back to the regular/hardware version (e.g. when I work on the sending device, which in this case has no ethernet shield, after I upload a sketch to the one with the ethernet shield), the hardware-based SPI nrf24l01 breaks. This seems to be happening because the Arduino IDE is holding on to the softSPI version of the rf24 library. I am just speculating on that, but it kind of makes sense since the internal naming is identical between the libraries.
The fix for this problem is simple, if a bit inconvenient. I have been removing my modified version of the rf24 library from the Arduino libraries folder before working with the hardware-SPI version. I am sure there is a smarter way of fixing this, and if someone could point it out to me, I would be glad to post the solution here.