I'm trying to get the nRF24L01+ module to work on different pins other than the SPI pins (50-52) on the Arduino Mega. Using the RF24 library, I discovered that I should be able to do this if I follow these steps:
- Uncomment the
#define SOFTSPI
line in theRF24_config.h
file. -
#include <DigitalIO.h>
in the sketch. - Define new pins (40-42) for MOSI, MISO and SCK using the same macros used in the library.
This, in theory should work however it doesnt with me. Am I missing a step?
This module works normally on hardware SPI pins
Receiver code:
#define SOFT_SPI_MISO_PIN 42
#define SOFT_SPI_MOSI_PIN 41
#define SOFT_SPI_SCK_PIN 40
#include <SPI.h>
#include <RF24.h>
#include <DigitalIO.h>
#include <nRF24L01.h>
RF24 radio(2, 3); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[32] = "";
radio.read(&text, sizeof(text));
Serial.println(text);
}
}