Problem using nRF24l01+ and sd card reader

Can you monitor the output of the Arduino with the other nRF24 in parallel with the Arduino with the SD Card so that you can see what the Arduino with the SD Card should be receiving.

Sorry, but I don't understand...
Also, pay attention that when the Arduino nano display something on the serial monitor is because the SD card slot is detached, so I suppose that the "initialization failed" is referred to trying to open a connection to the Sd card reader

What I mean by "in parallel" is to have two Serial screens on your PC with the two Arduinos connected to 2 different USB ports so you can see at the same time what both Arduinos are doing.

I haven't investigated the SD Card library code. It seems to be a bit of a labyrinth. My feeling is that some parts of it try to initialize when it is not actually necessary.

...R

What I mean by "in parallel" is to have two Serial screens on your PC with the two Arduinos connected to 2 different USB ports so you can see at the same time what both Arduinos are doing.

How can I do it?

IIRC the message "initialization failed!" pops up but does not mean anything. I believe the system works fine and the message can be ignored.

There is an issue with calling setupSD() which calls SD.begin() within loop. See this post about how to modify the SD.h library to accomodate repeated calls to SD.begin().
http://forum.arduino.cc/index.php?topic=46969.msg339113#msg339113

Eternyt:

What I mean by "in parallel" is to have two Serial screens on your PC with the two Arduinos connected to 2 different USB ports so you can see at the same time what both Arduinos are doing.

How can I do it?

What is it about my suggestion that you don't understand?

I think you need to start two instances of the Arduino IDE so that the Serial Monitor in each of them can connect to a different Arduino. Or you could use another terminal program such as PuTTY

...R

Just do what you says. With your sketch and the SD card reader in the circuit the only messages are there:
"SimpleRxAckPayload Starting" for the receiver and
"Source File /mnt/sdb1/SGT-Prog/Arduino/SDandNRF/testSDnRF24.ino
testSDnRF24 Starting" for the transmitter.
Simply the transmission doesn't work with the sd card reader, why?

I have just tried my examples again and, after I got all the connection correct, they worked.

Post the code for the two programs YOU have uploaded to your Arduinos so there can be no doubt that we are both looking at the same thing.

...R

The two code that I used are:

// python-build-start
// action, verify
// board, arduino:avr:uno
// port, /dev/ttyACM0
// ide, 1.6.3
// python-build-end


// testSDnRF24.ino
// Combination of SimpleTxAckPayload - the master or the transmitter
//   abd ListFiles.ino

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include <SD.h>


#define CE_PIN  9 // for nRF24
#define CSN_PIN 10 // for nRF24

#define csPin 4 // for SDCard

const byte slaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';
int ackData[2] = {-1, -1}; // to hold the two values coming from the slave
bool newData = false;


//===============

void setup() {

    Serial.begin(9600);
    Serial.println(F("Source File /mnt/sdb1/SGT-Prog/Arduino/SDandNRF/testSDnRF24.ino"));
    Serial.println("testSDnRF24 Starting");

}

//=============

void loop() {

    setupNRF();
    send();
    showData();
    delay(1000);

    setupSD();
    listFiles();
    delay(1000);
}

//================
//   These are the nRF24 functions
//================

void setupNRF() {
    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.enableAckPayload();

    radio.setRetries(3,5); // delay, count
}

void send() {

    bool rslt;
    radio.openWritingPipe(slaveAddress);
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        if ( radio.isAckPayloadAvailable() ) {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
        }
        else {
            Serial.println("  Acknowledge but no data ");
        }
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
 }


//=================

void showData() {
    if (newData == true) {
        Serial.print("  Acknowledge data ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

//============
//  And these are the SD Card functions
//============

void setupSD() {
    if (!SD.begin(csPin)) {
    Serial.println("initialization failed!");
    }
    else {
        Serial.println("initialization done.");
    }
}

//===================

void listFiles() {

    File root = SD.open("/");
    printDirectory(root, 0);
    Serial.println("done! ----------");
    Serial.println();
}

//=================

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}
// SimpleRx - the slave or the receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   7
#define CSN_PIN 8

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
int ackData[2] = {109, -4000}; // the two values to be sent to the master
bool newData = false;

//==============

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRxAckPayload Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);

    radio.enableAckPayload();
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data

    radio.startListening();
}

//==========

void loop() {
    getData();
    showData();
}

//============

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        updateReplyData();
        newData = true;
    }
}

//================

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        newData = false;
    }
}

//================

void updateReplyData() {
    ackData[0] -= 1;
    ackData[1] -= 1;
    if (ackData[0] < 100) {
        ackData[0] = 109;
    }
    if (ackData[1] < -4009) {
        ackData[1] = -4000;
    }
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}

Can you post some photos of your sd card reader?

Does the wireless part work if you comment out the calls to setupSD() and listFiles() on lines 55 and 56 (i.e. in loop() )?

This is my DIY sdcard reader - not at all elegant :slight_smile:

DSCF4644small.png

...R

Does the wireless part work if you comment out the calls to setupSD() and listFiles() on lines 55 and 56 (i.e. in loop() )?

Nothing has changed. But I definitely think that is a sd card module problem, see this thread. But I don't have the skill to do such as a small solder. I search online but the only board I see is the one I have...

If it still does not work with the calls for the SD Card commented out (but with the SD Card module connected) it would seem that there is some electrical feature of the module causing the problem. I don't have one of those modules so I can't suggest a solution. It seems like whoever designed the module did not consider that it would be expected to work with other SPI devices.

Another test is whether the code works with the calls to the SD Card included but with the module disconnected?

...R

Yes, in this case the code works (simply doesn't find any sd card).

The newer versions of the Catalex modules have corrected the problem with releasing MISO. It now ties MISO to CS instead of ground. Verify the schematic on an replacement you order.

https://forum.arduino.cc/index.php?topic=360325.0

Many thanks! But it's a bit hard find a related electric schematics when buying one of this module.

Hi I was having the same problem it took me smtime before I solved it so inorder to get the two modules working together use the sdfat library and inside it go for examples it will be somthng calld software spi here u can change the moso miso sck pins to any other pins you like another thing to be noted is that you have to edit a file in the sdfat lib folder in c drive directly editing may be denied so copy the folder and make the change and edit it and then replace the folder the file which has to edited will be specified in the softwarespi program itself I am actually posting this because I have read almost all links related to this topic and never got a correct replay I hope this would be helpful