how to connect sd card module and NRF24L01 in arduino UNO

hi everyone, please help me, i try and search many website but still no idea about it, i using arduino UNO and using nrf24L01 for transmit and receive the data, after receive the data need to store in sd card which is using sd card module, but the nrf24L01 and sd card module using same SPI which is pin 11,12,13 they are MOSI, MISO,SCK pin, i search got someone say need to change something in sd card library, i no clear about it, anyone can help me? i want receive the data by nrf24L01 and direct store to sd card and keep repeat, Please guide me to do this, thank you very much for helping, have a nice day^^

There is a chip select pin that you put low before doing the access to the SPI device. If you have two devices you need two separate pins to act as chip select. Therefore you need to wire each device to a separate pin and change the software to reflect this. Normally a library will allow you to specify the select pin.

Grumpy_Mike:
There is a chip select pin that you put low before doing the access to the SPI device. If you have two devices you need two separate pins to act as chip select. Therefore you need to wire each device to a separate pin and change the software to reflect this. Normally a library will allow you to specify the select pin.

Thank you very much for reply and help me, i worry about this.

so the chip select for sd card module i use is D4 and for nrf24L01 is use RF24 radio(9, 10) , so mean sd card module and nrf24L01 can share same MISO, MOSI and SCK pin which is 11, 12 and 13 in arduino UNO? the problem is in the library of sd card of chip select?? sorry cause i confused about this, hope u can help me, or sir has some tutorial can let me refer? thank you very much^^

UnoWatt:
Yes: SPI is a bus, and you use the /SS Slave Select to nominate which slave the master is taking to.

in nrf24L01
CE-9
CSN-10
SCK-13
MOSI-11
MISO-12

in sd card module
CS-4
SCK-13
MOSI-11
MISO-12

this connection is correct right?

so i need change something in sd card library so the system can receive the data and store into sd card? i try search google and youtube, no clear explain about this, feel worry

I got an SD Card and an nRF24 working and I posted my code here

Please don't double post - it just wastes time.

...R

i feel sorry because i first time post in arduino forum,So how can i delete the first post? sorry for any disturb.
thank you for help,

WILLIAM38:
i feel sorry because i first time post in arduino forum,So how can i delete the first post? sorry for any disturb.
thank you for help,

You can click Report to Moderator on the Thread you want deleted. However in this case I have already done it.

...R

thank you, but after i study the post you given, so the connection is same sd card and nrf24l01 share same MISO,MOSI and SCK but need to set the chip select high after used right? is possible i send my coding then u take sometime help me check? i just use sd card and nrf24L01 to receive the data from transmit only. really hope u can help give me some guide, really appreciate ^^

here is my code, i compile it is success, but i test with my hardware than no reponse

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <SD.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9, 10);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

const int chipSelect = 4;
File SensorFile;
// Structure of our payload
struct payload_t
{
  unsigned long currentflow;
  unsigned long totalflow;
  unsigned long counter;
};

void setup(void)
{
  Serial.begin(9600);
  Serial.println("RF24Network/examples/helloworld_rx/");
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 94, /*node address*/ this_node);
  while (!Serial) ; // wait for serial
  delay(200);

  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");
  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("Initialization failed!");
    return;
  }
  Serial.println("Initialization done.");
}


void loop(void)
{
  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    tmElements_t tm;
    SensorFile = SD.open("LDR4.txt", FILE_WRITE); //change here
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header, &payload, sizeof(payload));
    if (SensorFile) {
      Serial.println("Writing to file...");
      // write time and LDR value
      if (RTC.read(tm)) {
        SensorFile.print("Received packet #");
        SensorFile.println(payload.counter);
        SensorFile.print("Ok, Time = ");
        SensorFile.print(tm.Hour);
        SensorFile.write(':');
        SensorFile.print(tm.Minute);
        SensorFile.write(':');
        SensorFile.print(tm.Second);
        SensorFile.println();
        SensorFile.print("Date (D/M/Y) = ");
        SensorFile.print(tm.Day);
        SensorFile.write('/');
        SensorFile.print(tm.Month);
        SensorFile.write('/');
        SensorFile.print(tmYearToCalendar(tm.Year));
        SensorFile.println();
        SensorFile.print("Current Liquid Flowing: ");
        SensorFile.print(payload.currentflow);
        SensorFile.print("mL/Sec");
        SensorFile.println();
        SensorFile.print("Output Liquid Quantity: ");
        SensorFile.print(payload.totalflow);
        SensorFile.print("mL");
        SensorFile.println();
        Serial.print("Received packet #");
        Serial.println(payload.counter);
        Serial.print("Ok, Time = ");
        Serial.print(tm.Hour);
        Serial.write(':');
        Serial.print(tm.Minute);
        Serial.write(':');
        Serial.print(tm.Second);
        Serial.println();
        Serial.print("Date (D/M/Y) = ");
        Serial.print(tm.Day);
        Serial.write('/');
        Serial.print(tm.Month);
        Serial.write('/');
        Serial.print(tmYearToCalendar(tm.Year));
        Serial.println();
        Serial.print("Current Liquid Flowing: ");
        Serial.print(payload.currentflow);
        Serial.println(" mL/s ");
        Serial.print("Output Liquid Quantity: ");
        Serial.print(payload.totalflow);
        Serial.println(" mL");
        SensorFile.close();
        Serial.println("done.");
        delay(1000);
      }
      else {
        if (RTC.chipPresent()) {
          Serial.println("The DS1307 is stopped.  Please run the SetTime");
          Serial.println("example to initialize the time and begin running.");
          Serial.println();
        } else {
          Serial.println("DS1307 read error!  Please check the circuitry.");
          Serial.println();
        }
      }
    }
    else {
      // if the file didn't open, print an error:
      Serial.println("Error opening LDR4.txt");
    }
    delay(1000);
    //re-open file and print results
    SensorFile = SD.open("LDR4.txt"); //change here
    // if the file opened okay, write to it:
    // if the file is available, write to it:
    if (SensorFile) {
      while (SensorFile.available()) {
        Serial.write(SensorFile.read());
      }
      SensorFile.close();
      delay(1000);
    }
    // if the file isn't open, pop up an error:
    else {
      Serial.println("error opening LDR4.txt");
    }
  }
}

WILLIAM38:
thank you, but after i study the post you given, .... is possible i send my coding then u take sometime help me check?

Your code has a number of libraries in addition to the SD Card and the nRF24 and I am not familiar with them.

One way to proceed is to take my example and when you have it working add your other parts one at a time checking that it works at each stage.

Another approach might be to get your own code working with the SD Card only and and then with the nRF24 only before trying to do the two at the same time.

My guess is that it is important to initialize the SD Card (or the nRF24) when switching from one to the other rather than to do the initialization in setup().

...R

Thank you help me check the code, yup, i also use RTC to mark real time, i receive the two data from transmit side and mark with real time with real time clock and plan write to the sd card, i can get data from nrf24L01 and mark with real time print on serial monitor, since i cannot receive data and write to sd card, so i no have chance to try sd card, i only try install sd card in transmit part which is before transmit data store in sd card than it function well.

so mean intialize sd card first and then nrf24?? no need change something in library?? i quite confused actually what is the problem cause it cannot work, i study the post maybe SPI and chip select part and other post say need change the sd library, i no idea about it. by the way, thank you very much help me.

since i cannot receive data and write to sd card, so i no have chance to try sd card,

You are not getting the idea of testing. The data doesn't have to come from the nrf24L01 in order for you to test your SD card. It can just be a constant that you feed into the SD part of the code..

i quite confused actually what is the problem cause it cannot work,

That is why you have to break it down into its component parts and TEST each part independently.

thanks Grumpy_mike reply me

yup, if i try without the sd card, sure the nrf24l01 can receive the data from the transmitter, but the coding i use is without sd card code,

i has try before that attach the sd card on the transmitter side which is when transmitter get the data and it can store in sd card. but i cannot try to transmit this data to receive since in transmitter side i use sd card and nrf24l01 which is conflict about SPI and chip select port problem.

i stuck in this problem few week already, since the nrf24l01 got many type of library and coding, so i use library of RF24 network-master, so far this library i has success figure out to transmit the data.

Or i need to use other library of nrf24l01 to try? since Robin2 give me some guide about this but beause the library is different, so i no quite understand the coding used.

MY desired system performance is the transmitter only send the data to the receive, and the receive can receive the data and store this data in sd card and keep repeat this process because the transmitter always send data to receive, So, this idea actually can work or not??

thank for everyone reply and help me^^

This Simple nRF24L01+ Tutorial may help. It has the same nFR24 code that I used with my SD Card.

In Reply #13 you said

yup, if i try without the sd card, sure the nrf24l01 can receive the data from the transmitter, but the coding i use is without sd card code,

but you have not told us if you can get it to work WITH the SDCard and WITHOUT the nRF24?

...R

Thank reply me Robin2

but you have not told us if you can get it to work WITH the SDCard and WITHOUT the nRF24?

yup, i success work with the sd card and without the nrf24 when i just simply attach sd card at the transmitter side, so it function just like take data store in sd card only.

next i also success work when transmitter take data and send it to receiver through nrf24, it can function well.. good.

so, now i want attach the sd card in receiver side, when transmitter take data and send to receiver through nrf24, the nrf24 able to receive the data and write to the sd card.. but since got problem for nrf24l01 and sd card, so i dunno the problem is my coding or i need to change something in sd card library??

(data)-->transmitter&nrf24 -------------------------> nrf24&receiver-->data store in sd card

send wirelessly

So basically this can work right??

WILLIAM38:
yup, i success work with the sd card and without the nrf24 when i just simply attach sd card at the transmitter side,

I thought you want the SD Card on the receiver side? Have you tried it on the receiver side WITHOUT the nRF24 code?

...R

actually i want sdcard in receive side, but i cannot try the SDcard in receive side without nrf24L01 since if receive side no has nrf24L01 to accept the data, how can i try to save the data into sd card in receive side?? so i just can try sd card in transmitter side without nrf24L01.

Now i try other solution is in receive side using 2 arduino, one for receive the data from transmitter, and the other one arduino will save this data into sd card with just connect this 2 arduino wtith TX----->Rx, but still got problem, no i need open new post for this situation.

WILLIAM38:
actually i want sdcard in receive side, but i cannot try the SDcard in receive side without nrf24L01 since if receive side no has nrf24L01 to accept the data, how can i try to save the data into sd card in receive side?? so i just can try sd card in transmitter side without nrf24L01.

Of course you can. Just get it to save some fictitious data ! (THINK)

...R

as i know, if no using nrf24l01, so that is no term of transmitter or receiver right? since no need to transmit and receive anything, so if i just using sd card connect to arduino without connect nrf24l01, it just a simple project in the example of arduino IDE,

since nrf24l01 and sd card cannot use in one arduino, i try to use 2 arduino with serial communication between 2 arduino, but still got problem , haizz,, really tired about this, but the way ,thanks for reply and help

I want you to prove to yourself and to me when you use your RX code WITH the SD Card and WITHOUT the nRF24 that the program works properly and stores data to the SD Card.

Then we can consider why it might not work when the code for the nRF24 is added.

...R