Go Down

Topic: Problem using nRF24l01+ and sd card reader (Read 8426 times) previous topic - next topic

Eternyt

Yeah, another time. But before telling me that there are many topics on this forum about that, read all the post.
I have an Arduino Nano connected to an nRF24l01+ and an SD card reader in this way:

SD --> Nano
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 4

Now the problem. I try to upload just the CardInfo example in the SD library and all work fine, but if I try to upload a sketch that uses only the nRF24 the module doesn't receive the value, but if I remove the 5V pin from the SD card reader and I reboot the Nano, keeping all the other wires untouched, the reception work fine. So I suppose that is a hardware problem and not the software problem that I read many times on another post.
Did I make some mistakes? Any fix?
Many thanks!

The SD code:
Code: [Select]

/*
  SD card test

 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.

 The circuit:
  * SD card attached to SPI bus as follows:
 ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
 ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
 ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
 ** CS - depends on your SD card shield or module.
  Pin 4 used here for consistency with other Arduino examples


 created  28 Mar 2011
 by Limor Fried
 modified 9 Apr 2012
 by Tom Igoe
 */
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_QUARTER_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);


  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {

}

The nRF24l01+ code:
Code: [Select]

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

RF24 radio(7,8);

unsigned long payload;
int var[2] = {};
bool temp_hum = true;
byte pipe;
float prova[2] = {1,6.9765};

// RX address (address of this module)
byte addresses[][6] = {"1Node", "2Node"};

void setup() {
Serial.begin(115200);
Serial.println("Boot OK");
Serial.println("MODE: Receiver");

radio.begin();

// Settings
radio.setPALevel(RF24_PA_MIN);// RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH RF24_PA_MAX

radio.setChannel(108);
radio.setDataRate(RF24_250KBPS); // Probably not working

// Reading pipe with the address of this module
radio.openReadingPipe(1,addresses[0]);

    radio.startListening();


}

void loop() {
if(radio.available(&pipe)) {
                                                                   
      while (radio.available()) {                                   // While there is data ready
      radio.read( &payload, sizeof(unsigned long) );             // Get the payload
      }
      if(temp_hum == true){
          var[0] = payload;
          Serial.print("Temperatura: ");
          Serial.print("Var[0]: ");
        Serial.println(var[0]);
      }
      if(temp_hum == false){
          var[1] = payload;
          Serial.print("Umidità: ");
          Serial.print("Var[1]: ");
        Serial.println(var[1]);
      }
      temp_hum = !temp_hum;
      Serial.print("Var[0]: ");
      Serial.println(var[0]);
      Serial.print("Var[1]: ");
      Serial.println(var[1]);
     

}
}

NewStudent

I had a problem like this before i think this problem appears while using multiple SPI devices. I solved my problem by placing a diode between mosi pin of arduino and one of the modules mosi pin. You can try this and tell us wheter it works or not
When life gives you lemons...
              Demand to see life's manager.

Robin2

Yeah, another time. But before telling me that there are many topics on this forum about that,
And what have you gleaned from all those Topics?

You have not posted the combined code that is causing a problem so it is a bit difficult to know what to say.

I got my SDCard working alongside an nRF24L01+ without any difficulty. I posted my demo program here.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

6v6gt

The 3.3 volt output on the Nano is often very poor, with some Chinese clones supplying only about 50mA and then only when powered via the USB socket.

Also, you are using pin 4 as CS (Chip Select) pin for the NRF24L01. What pin are you using for CS on the SD card? It cannot be the same.

Eternyt

Quote
I had a problem like this before i think this problem appears while using multiple SPI devices. I solved my problem by placing a diode between mosi pin of arduino and one of the modules mosi pin. You can try this and tell us wheter it works or not
I don't understand where I must place it and in what direction I must interrupt the current.

Quote
You have not posted the combined code that is causing a problem so it is a bit difficult to know what to say.
I don't have a combined code when I upload the nRF24 code simply the things don't work

Quote
Also, you are using pin 4 as CS (Chip Select) pin for the NRF24L01. What pin are you using for CS on the SD card? It cannot be the same.
I don't use CS pin 4 for the nRF24, it's not connected to that pin and I don't specify any pin 4 on the nRF24 code.

Thanks!

Robin2

I don't have a combined code when I upload the nRF24 code simply the things don't work
That sounds as if you cannot get the nRF24 code to work on its own without any reference to the SD Card. Is that correct?

I have been under the impression that you can get the nRF24 to work on its own and get the SD Card to work on its own but that when you tried a combined version it would not work.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

6v6gt

#6
Feb 03, 2017, 09:37 pm Last Edit: Feb 03, 2017, 09:41 pm by 6v6gt
OK. But you have this statement in your code for the NRF24L01:
Code: [Select]
RF24 radio(7,8);
Your Fritzing diagram does not show any such connections to the Nano on pins 7 and 8. The text under the diagram mentions pin 4 as CS.

Eternyt

Quote
That sounds as if you cannot get the nRF24 code to work on its own without any reference to the SD Card. Is that correct?
Yes, it is correct! When I try to use JUST the nRF24, using the code that I put in my first post under The nRF24l01+ code: the nRF24 doesn't work. If I remove the SD card reader or just the 5V pin from the circuit, (and I reboot) the nRF24 works well.

Quote
Your Fritzing diagram does not show any such connections to the Nano on pins 7 and 8. The text under the diagram mentions pin 4 as CS.
I'm sorry about my error. The image diagram shows that I connect pin 3 and 4 to D9 and D10 of the Nano, but I instead connect they to D7 and D8, as code RF24 radio(7,8); shows. Also, under the diagram, there are the wiring of the Nano and the SD, "SD --> Nano", in fact I use the cs pin 4 for the SD card.

Robin2

#8
Feb 05, 2017, 04:54 pm Last Edit: Feb 05, 2017, 04:55 pm by Robin2
Quote
That sounds as if you cannot get the nRF24 code to work on its own without any reference to the SD Card. Is that correct?
Yes, it is correct! When I try to use JUST the nRF24, using the code that I put in my first post under The nRF24l01+ code: the nRF24 doesn't work. If I remove the SD card reader or just the 5V pin from the circuit, (and I reboot) the nRF24 works well.
This is very confusing.

I asked if you had a problem getting the nRF24 to work on its own and you said that you have. Then in the next sentence you say that you have not. Which is correct?

Have you looked at the demo in my link in Reply #2

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Eternyt

I have no problem to use the nRF24, if it's the only thing connect to SPI bus. If it is connect with the SD card reader, also if I don't use the SD card reader at all, the nRF24 doesn't work.
Sorry for the misunderstanding.

Robin2

I have no problem to use the nRF24, if it's the only thing connect to SPI bus. If it is connect with the SD card reader, also if I don't use the SD card reader at all, the nRF24 doesn't work.
Sorry for the misunderstanding.
OK. Now that that is clear, did you study my link?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

6v6gt

The instruction for the Ethernet card (also SPI)  give a warning about possible conflicts with the (inbuilt) SD card and a possible solution. I'm not sure how relevant it is here, but the solution seems simpe enough to be worth a try.:

Quote
Warning

This example doesn't require an SD card. If an SD card is inserted but not used, it is possbile for the sketch to hang, because pin 4 is used as SS (active low) of the SD and when not used it is configured as INPUT by default. Two possible solutions:

    remove the SD card;
    add these lines of code in the setup()

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

Quote
from https://www.arduino.cc/en/Tutorial/WiFiWebServer

Eternyt

Quote
The instruction for the Ethernet card (also SPI)  give a warning about possible conflicts with the (inbuilt) SD card and a possible solution. I'm not sure how relevant it is here, but the solution seems simpe enough to be worth a try.:
I try this fix, that is in line with the SPI protocol theory, but unfortunately doesn't work.

Quote
OK. Now that that is clear, did you study my link?
Yes, but before going to the software, it is better to make to work the two devices separately, is it?

Robin2

Yes, but before going to the software, it is better to make to work the two devices separately, is it?
Now you are confusing me again.

Based on what you said in Reply #9 I thought you could already use the devices separately.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Eternyt

If the two modules are FISICALY separately(so, for example, I use in a first moment the SD card, then I remove it from the breadboard and I wire the nRF24) with the two sketch I uploaded in my first post the two module work fine. If I wire all TOGETHER(so in the same breadboard there are the SD and the nRF24 module, both connected to the SPI busses), and I try to use the same two sketch, the nRF24 sketch doesn't work anymore. Then I suppose that is a hardware problem because I don't modify the sketch but just add the SD card reader to the electric circuit.

Go Up