SPI on different pins for nRF24L01

Hello everyone!

I am really new to the forum and also to Arduino at all. I am also a beginner in programming.
I have searched the net for solutions, even looked in to the forums, but I could not find anything that would help. I am currently in the planning phase (only the Arduino have arrived, other components are on the way).

What I (will) have:
Arduino UNO
nRF24L01
2 DC motors
3 Servo motors
L293D

I would like to operate 5 motors with the UNO and I want it to communicate via nRF24L01.

As I learned a DC motor needs 2 digital pins (Enable on L293D) and a PWM (to set voltage level for 293D) and the a Servo motor needs 1 PWM (for PWM control).
I plan to supply the motors (and the 293D) from a different battery source.

But this means I will need 4 digital pins (2 DC) and 5 PWM pins (2 DC and 3 PWM).

To use nRF24L01 I would need 5 pins: 9-10-11-12-13 on default. But with the motors set up I will only have 2 digital and 1 PWM pin. This means I will not be able to use nRF24L01 as I seen in examples.

Is it possible to use SPI communication on different pins?

I see that my UNO board have soldered connections for ICSP-s which have MISO, MOSI and SCK pins.
Is it possible to use these pins for SPI communication with the nRF24L01?

I am attaching pictures to clarify.

I hope my problem is understandable!

Thank you very much for your help in advance!

Zancot

Yes, you can use ICSP-pins as NRF24L01 SPI-pins and use those 13-11 pins for something else.

TommiP

Thank you very much, I am truly relieved! :slight_smile:

Would you kindly help me how to redefine the necessary pins? All I could find is that they include the corresponding libraries:

/-----( Import needed libraries )-----/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/-----( Declare Constants and Pin Numbers )-----/
#define CE_PIN 9
#define CSN_PIN 10

I understand the define part, but how can I refer to the ICSP pins?
What are the required parameters (like CE_PIN)?

Thank you so much!

Zancot

I understand the define part, but how can I refer to the ICSP pins?

You've done that in your SPI.h -file, you don't have to code it anymore in "your code".. Just use'em..
Someone could explain it more c++-wise but I can't, so in this case I just use libraries written by the others.. :o

What are the required parameters (like CE_PIN)?

All you need to #define are CE and CSN pins and you could do it by

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

RF24 radio(9,10);

or

/*-----( Import needed libraries )-----*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

/*-----( Declare Constants and Pin Numbers )-----*/
#define CE_PIN   9
#define CSN_PIN 10

RF24 radio(CE_PIN, CSN_PIN);

Reference: http://tmrh20.github.io/RF24

I've used it like in attachment, with external power supply. I have had difficulties to get it work with Arduino board's own 3.3 volt regulator, even with the capacitor..

Thank you very much!

I am curious, is there a way to use other pins as CE and CSN pins? Like the second ICSP pins?

But I can use your method already, thanks!

Sure, just #define those for example

#define CE_PIN 7
#define CSN_PIN 8

RF24 radio(CE_PIN, CSN_PIN);

TommiP

Hi!

Its me again :).

I have all the hardware (nRF modules, servos etc) and they are working nice. But, I ran out of digital pins, because the SPI uses the 9-10-11-12-13 pins. (I know, that I can put anywhery the CE and CSN, but I want to move the others too.)

I hoped that I can reallocate the CE, CSN, MOSI, MISO, SCLK to the analog outputs. (A4-A0).

I dig through the headers and included libraries a little and I found the definitions in "pins_arduino.h":

static const uint8_t SS = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK = 13;

But, as I feared, simply changing the numbers to the analog pin numbers did not work. (14-15-16-17-18)

Is it even possible to use the analog pins for SPI? (I know they can be used as digital in- and outputs.)
What else shall I modify to make it work?

//Unfortunately, I need 6 PWM pins for servo's, and as far as I know the analog pins can not be used to drive servos not even with the softPWM library.

Thank you very much in advance!

But, as I feared, simply changing the numbers to the analog pin numbers did not work. (14-15-16-17-18

You have two options: either use the built in SPI module, and the pins dedicated to it, or use "bit-bang" (software) SPI, in which case you can use any pins.

Google "arduino software spi" for several libraries or code examples. It is very simple.