Alexan
October 22, 2017, 2:36pm
1
Hello, Arduino community,
I am working on a project which requires both SD card and wireless communication. For the wireless communication I use these 3Pcs NRF24L01+ SI24R1 2.4G Wireless Power Enhanced Communication Receiver Module Sale - Banggood USA-arrival notice-arrival notice 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
system
October 23, 2017, 9:39am
2
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.
Alexan
October 23, 2017, 12:04pm
3
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!
system
October 23, 2017, 1:04pm
4
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.
Alexan
October 23, 2017, 4:23pm
5
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: SD - Arduino Reference
SPI: SPI - Arduino Reference
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.
system
October 23, 2017, 4:47pm
6
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?
Alexan
October 23, 2017, 6:44pm
7
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.
system
October 23, 2017, 10:02pm
8
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.
Alexan
October 24, 2017, 12:06pm
9
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?
Alexan
October 24, 2017, 4:21pm
10
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);
}
}
```
Robin2
October 24, 2017, 6:36pm
11
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
Alexan
October 24, 2017, 7:29pm
12
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.
Robin2
October 24, 2017, 8:09pm
13
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.
Sorry, but you have just added to the confusion because you say MOSI in Reply #11 and MISO in the updated Reply #9
...R
Alexan
October 24, 2017, 8:32pm
14
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.