SD card and NRF24 [SOLVED]

Hello, Arduino community, I am working on a project which requires both SD card and wireless communication. For the wireless communication I use these https://www.banggood.com/3Pcs-NRF24L01-SI24R1-2_4G-Wireless-Power-Enhanced-Communication-Receiver-Module-p-1057155.html?rmmds=myorder and the SD module is this https://www.banggood.com/Micro-SD-TF-Card-Memory-Shield-Module-SPI-Mciro-SD-Adapter-For-Arduino-p-919914.html?rmmds=myorder . I tried to connect both of them, but only one worked at a time. Both use SPI to communicate with Arduino. Is my project possible? If yes what do I have to do (with details please because I am not that good)? If not, do I have any alternative? Thank you in advance!

EDIT: Go to the end to find the solution! At reply #9

ISP Question

Both use the IPS protocol

Neither of your random collection of letters is right. It's SPI - Serial Peripheral Interface.

It is perfectly possible to get two SPI devices to work together, IF they both follow ALL of the rules. Not all SPI devices do.

However, the code you posted does NOT prove that the devices should play well together.

PaulS: Neither of your random collection of letters is right. It's SPI - Serial Peripheral Interface.

It is perfectly possible to get two SPI devices to work together, IF they both follow ALL of the rules. Not all SPI devices do.

However, the code you posted does NOT prove that the devices should play well together.

Sorry for the wrong name. I typed it from my phone and it got autocorrected. About my project, is it possible with those 2 modules? Libraries used: SD and nrf24. Could you tell me an alternative if not? Like using 2 arduinos or something? Thanks again!

About my project, is it possible with those 2 modules?

It's not usually a hardware issue. It is almost always a software issue - either yours or a library's.

Since you won't post code, and links to non-standard libraries, you can't really expect help.

PaulS:
It’s not usually a hardware issue. It is almost always a software issue - either yours or a library’s.

Since you won’t post code, and links to non-standard libraries, you can’t really expect help.

Yes, you are right, sorry for that. So libraries can be found here:
NRF24: GitHub - maniacbug/RF24: Arduino driver for nRF24L01
SD: Arduino - SD
SPI: Arduino - SPI

About the code its here:

#include <SPI.h>  
#include "RF24.h"
#include <SD.h>
/* SCK -> 13
  MOSI -> 11
  MOSO -> 12
  CS -> 10 */
  File myFile;

int CS = 4;

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};

struct package
{
 int id=1;
 float temperature = 18.3;
 char  text[100] = "Test";
};


typedef struct package Package;
Package data;


void setup()
{
 Serial.begin(115200);

 myRadio.begin();  
 myRadio.setChannel(100); 
 myRadio.setPALevel(RF24_PA_MAX);
 myRadio.setDataRate( RF24_250KBPS ) ; 
 myRadio.openWritingPipe( addresses[0]);

pinMode(CS, OUTPUT);
if(!SD.begin(CS)){
Serial.println("Problem");
return;
}else{
Serial.println("Everything ok");
}
}

void loop()
{

 myRadio.write(&data, sizeof(data)); 

 Serial.print("\nPackage:");
 Serial.print(data.id);
 Serial.print("\n");
 Serial.println(data.temperature);
 Serial.println(data.text);
 data.id = data.id + 1;
 data.temperature = data.temperature+0.1;


 myFile = SD.open("test.txt", FILE_WRITE);
 if (myFile) {
   myFile.println("t");
   myFile.close(); 
  Serial.println("Writing...");
 }

  delay(500);
 }

Please let me know if you can do anything about it and thank you so much for your help. :slight_smile:

struct package
{
 int id=1;
 float temperature = 18.3;
 char  text[100] = "Test";
};

You know that the NRF radios have a 32 byte payload, right? Not a 106 byte payload.

Now, give us a clue what “it doesn’t work” means. What does the code actually do? How does that differ from what you expect?

PaulS: struct package { int id=1; float temperature = 18.3; char  text[100] = "Test"; };

You know that the NRF radios have a 32 byte payload, right? Not a 106 byte payload.

Now, give us a clue what "it doesn't work" means. What does the code actually do? How does that differ from what you expect?

So, it should be sending the data from the structure to my other station/Arduino. Also, it should save the letter "t" in the test.txt file which exists/or it creates it, on the SD card. When the SD card is not connected, the data is successfully sent. As soon as I connect the card, the NRF stops working, SD card data start saving and the microcontroller gets warm. Any idea why is that happening?

EDIT: As soon as I connect the 5v pin of the card module to the 5v of Arduino, it stops transmitting and starts heating.

EDIT: As soon as I connect the 5v pin of the card module to the 5v of Arduino, it stops transmitting and starts heating.

If you just connect the SD card module, and write no code to use the module, does this still happen? If so, you have a hardware problem that you'll need to address before you worry about the software.

PaulS: If you just connect the SD card module, and write no code to use the module, does this still happen? If so, you have a hardware problem that you'll need to address before you worry about the software.

Yes! I tried without any code for the SD module and still, NRF module stops working and microcontroller starts heating! What can I do about it? I think there is a mod for the module but I can not find deeper information about it. Any ideas?

So what I basically did was to add a 2k Ohm resistor between the SD card's MOSO (or MISO, depends on the module) and the Arduino's MISO pin.

Code that worked:

```
#include <SPI.h>  
#include "RF24.h"
#include <SD.h>
/* SCK -> 13
   MOSI -> 11
   MOSO -> 12
   CS -> 4 */
   File myFile;

int CS = 4;

RF24 myRadio (7, 8);
byte addresses[][6] = {"0"};

struct package
{
  int id=1;
};


typedef struct package Package;
Package data;


void setup()
{
  Serial.begin(115200);
SPI.begin();
  myRadio.begin();  
  myRadio.setChannel(100); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openWritingPipe( addresses[0]);

 //pinMode(CS, OUTPUT);
if(!SD.begin(CS)){
Serial.println("Problem");
return;
}else{
Serial.println("Everything ok");
}
}

void loop()
{

  myRadio.write(&data, sizeof(data)); 

  Serial.print("\nPackage:");
  Serial.print(data.id);
  Serial.print("\n");
  data.id = data.id + 1;

delay(500);
 

  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {
    myFile.println(data.id);
    myFile.close(); 
   Serial.println(data.id);
   delay(500);
  }


  
  }
```

Reciever code:

```
#include <SPI.h>  
#include "RF24.h" 

RF24 myRadio (7, 8); 
struct package
{
  int id=0;
  float temperature = 0.0;
  char  text[100] ="empty";
};

byte addresses[][6] = {"0"}; 



typedef struct package Package;
Package data;

void setup() 
{
  Serial.begin(115200);

  myRadio.begin(); 
  myRadio.setChannel(100); 
 myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openReadingPipe(1,addresses[0]);
  myRadio.startListening();
}


void loop()  
{


    while (myRadio.available())
    {
      myRadio.read(&data, sizeof(data));
    Serial.print("\nPackage:");
  Serial.print(data.id);
  Serial.print("\n");
  Serial.println(data.temperature);
  Serial.println(data.text);
    }
   

}
```

Alexan: SOLVED: So what I basically did was to add a 2k Ohm resistor between the SD card's MOSO and the Arduino's MOSO pin.

This is very interesting and could be very useful for others.

HOWEVER you have a typo and I don't know which letter you got wrong. Did you mean MISO or MOSI?

...R

Robin2: This is very interesting and could be very useful for others.

HOWEVER you have a typo and I don't know which letter you got wrong. Did you mean MISO or MOSI?

...R

Actually, not a typo. Should be MISO but the SD card module has it as MOSO. However, I fixed it and made it more understandable. ;)

Alexan:
Actually, not a typo. Should be MOSI but the SD card module has it as MOSO. However, I fixed it and made it more understandable. :wink:

Sorry, but you have just added to the confusion because you say MOSI in Reply #11 and MISO in the updated Reply #9

…R

Robin2:
Sorry, but you have just added to the confusion because you say MOSI in Reply #11 and MISO in the updated Reply #9

…R

You are right. Sorry for that. Writing from phone autocorrects it all time and I just missed it. Hope everything is fine now. :slight_smile:

Thanks

...R

Alexan: Hello, Arduino community, I am working on a project which requires both SD card and wireless communication. For the wireless communication I use these https://www.banggood.com/3Pcs-NRF24L01-SI24R1-2_4G-Wireless-Power-Enhanced-Communication-Receiver-Module-p-1057155.html?rmmds=myorder and the SD module is this https://www.banggood.com/Micro-SD-TF-Card-Memory-Shield-Module-SPI-Mciro-SD-Adapter-For-Arduino-p-919914.html?rmmds=myorder . I tried to connect both of them, but only one worked at a time. Both use SPI to communicate with Arduino. Is my project possible? If yes what do I have to do (with details please because I am not that good)? If not, do I have any alternative? Thank you in advance!

EDIT: Go to the end to find the solution! At reply #9

Is am