Go Down

Topic: How to use NRF24 and USB Host Shield at the same time together, at Arduino?tyvm. (Read 102 times) previous topic - next topic

MEKACI

I am making a robotic project to control my robot with logitech extreme 3d pro joystick ( it has a wire ) with nrf24 wireless communication. I managed to use and work successfully with my joystick and nrf24  separately. After that I decided to combine them but They are not working at the same time because thy share the same SPI ( I learned it after long tries and failures, I was opened this thread before: https://forum.arduino.cc/index.php?topic=512771.0 ).

I checked internet so much and I cannot find a solid tutorial that shows everything step by step for what kind of changes do we need to make to use NRF24 and Arduino USB Host Shield at the same time at Arduino.

If it is possible and if you know how to do it, would you help me please ?

Note:
I found a thread here: https://github.com/greiman/DigitalIO but I didn't understand most of parts. Shortly, it says this:
Quote
Install the digitalIO library
Reinstall the RF24 library from Updates
Open RF24_config.h in a text editor. Uncomment the line #define SOFTSPI
In your sketch, add #include DigitalIO.h
Note: Pins are listed as follows and can be modified in the RF24_config.h file

This is for Arduino Mega with latest version of nrf24 library: http://www.arduinolibraries.info/libraries/rf24
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;

An other nRF24L01 Library for Arduino & Raspberry Pi/Linux Devices ( for Arduino UNO ): https://github.com/nRF24/RF24
#define SOFT_SPI_MISO_PIN 9
      #endif

      #ifndef SOFT_SPI_MOSI_PIN
      #define SOFT_SPI_MOSI_PIN 8
      #endif

      #ifndef SOFT_SPI_SCK_PIN
      #define SOFT_SPI_SCK_PIN 7

But there is conflict here really. Look at this screenshot please and it says which pins we need for nrf24 communication with arduino.



So the pins we see in these screenshots are not the pins are defined in the quote I gave from the RF24_config.h itself already. However, as tmrh20 is saying us here too https://tmrh20.github.io/RF24/Arduino.html
https://tmrh20.github.io/RF24/Arduino.html

Alternate SPI Support

RF24 supports alternate SPI methods, in case the standard hardware SPI pins are otherwise unavailable.


Software Driven SPI

Software driven SPI is provided by the DigitalIO library

Setup:
Install the digitalIO library
Open RF24_config.h in a text editor. Uncomment the line #define SOFTSPI
In your sketch, add #include DigitalIO.h
Note
Note: Pins are listed as follows and can be modified by editing the RF24_config.h file
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;

I might seem like I am repeating but I tried to explain myself. It is so confusing. When I change/assign the SOFT_SPI pins to different pins then nrf24 doesn't start/work.

I don't have a deep knowledge about this issue so I don't know how to fix this problem. If I cannot solve this then I need to find an other wireless device ( start doing from zero again with a different device and then I might come and ask many questions again^^ ). I will be happy if someone would help me, I cannot go further with my robotic project right now because of it. If you explain me everything step by step I will be very happy ( for example, which which nrf24 library I need to solve this  problem, and what parts do I need to change in the cpp, h files and in my arduino sketch; what kind of changes do I need to make for arduino usb host shield part too etc. ) ? I look forward your replies to me. See you, that's all.

Delta_G

Quote
They are not working at the same time because thy share the same SPI
SPI is meant to be shared.  They only need different CS lines.  There shouldn't be any need to much around with software SPI for that. 
If at first you don't succeed, up - home - sudo - enter.

MEKACI

SPI is meant to be shared.  They only need different CS lines.  There shouldn't be any need to much around with software SPI for that. 
what do I need to make to use nrf24 and usb host shield to work together at the same time ? I really don't know how to solve this problem, nothing on internet about it unfortunately :/

From the readings, what I understand is "nrf24 and usb shield are using the pin 10 as SS ( slave select )"; so how can I change and assign that pin 10 to another pin which will make these two modules to work together ? thank you.

Delta_G

From the readings, what I understand is "nrf24 and usb shield are using the pin 10 as SS ( slave select )"; so how can I change and assign that pin 10 to another pin which will make these two modules to work together ? thank you.
Pull one of the pins out of the header and wire it to a different pin.  Get a nRF24 that isn't on a shield and you can wire it any way you want.  Mount the shield somewhere other than on top of the board and wire it to whatever pins.  There are myriad different ways to change how a shield connects to a board. 

You'll probably want to also have a look in the library code for the one you change and make sure you change what pin it refers to there as well. 
If at first you don't succeed, up - home - sudo - enter.

MEKACI

Pull one of the pins out of the header and wire it to a different pin.  Get a nRF24 that isn't on a shield and you can wire it any way you want.  Mount the shield somewhere other than on top of the board and wire it to whatever pins.  There are myriad different ways to change how a shield connects to a board. 

You'll probably want to also have a look in the library code for the one you change and make sure you change what pin it refers to there as well. 
at nrf24 config header , there are only these lines that makes you the change from coding part :
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;

In addition, I found in an article which says SS pin's other name is CSN too.

For the SS pin which is pin 10 in arduino uno and mega, what kind of code do I need to add in the nrf24 config header file ? thank you very much.

Something like const uint8_t SOFT_SS_PIN = 11; // instead of the default pin 10 .

However once I do these changes that it only affects for nrf24, right ? because when I do a change like that it doesn't change the whole default SS pin 10 for other boards too ,like usb host shield when I write codes in the Arduino sketch,  right ( but it only changes for nrf24 ) ? thank you very much.

MEKACI


avr_fred

You should not be using software based SPI. Based on the most common library defaults, the two should work together without changes. Since they do not, you have not posted enough information to make a determination of the conflict. The only thing we know is that you're using an Arduino USB host shield.

1) Please post links to the specific libraries you are using.
2) Please post photos or links to your NRF24 hardware.
3) State specifically which Arduino board you are using.
4) Please post your full code using code tags. Use </> icon.


Go Up