Hi,
I am trying to include a SD card and nrf24 module in my project (using an Arduino nano old bootloader). I test the SD card module and the nrf24 separately and they work fine. However when I connect both modules at the same time only the SD card module works; the nrf24 doesn't.
Hardware connections:
nrf24:
-CE pin 7
-CSN pin 8
SD module:
-CS pin 10
The rest of the connections are the standard SPI hookup. The wiring is verified by the fact that the modules work when tested individually.
test SD:
#include <SPI.h>
#include <SD.h>
#define sd_chip_select 10
struct Settings
{
struct Trimmings
{
int ch1 = 0;
int ch2 = 0;
int ch3 = 0;
int ch4 = 0;
} trim;
struct DualRates
{
unsigned ch1 = 100;
unsigned ch2 = 100;
unsigned ch3 = 100;
unsigned ch4 = 100;
} dualrates;
} settings;
void sd_setup();
void save_dualrates();
void sd_read_duals();
void sd_setup()
{
SD.begin(sd_chip_select);
}
void save_dualrates()
{
SD.remove("dual.txt");
File sd = SD.open("dual.txt", FILE_WRITE);
if (sd)
{
sd.write((unsigned char *)&settings.dualrates, sizeof(settings.dualrates));
sd.close();
}
}
void sd_read_duals()
{
File sd = SD.open("dual.txt", FILE_READ);
if (sd)
{
sd.read((unsigned char *)&settings.dualrates, sizeof(settings.dualrates));
sd.close();
}
}
void print_dual()
{
Serial.print(settings.dualrates.ch1);
Serial.print(" ");
Serial.print(settings.dualrates.ch2);
Serial.print(" ");
Serial.print(settings.dualrates.ch3);
Serial.print(" ");
Serial.println(settings.dualrates.ch4);
}
void setup()
{
Serial.begin(9600);
sd_setup();
//simulate editing dual rates
settings.dualrates.ch1 = 56;
settings.dualrates.ch2 = 78;
settings.dualrates.ch3 = 90;
settings.dualrates.ch4 = 23;
print_dual();
save_dualrates(); //check SD card on PC after this.
//simulate power down and up again
settings.dualrates.ch1 = 100;
settings.dualrates.ch2 = 100;
settings.dualrates.ch3 = 100;
settings.dualrates.ch4 = 100;
print_dual();
sd_read_duals();
print_dual();
//print dualrates
}
void loop() {
// put your main code here, to run repeatedly:
}
test nrf24 (using the tmrh20 library):
#include <SPI.h>
#include "RF24.h"
#define RECEIVER
RF24 radio(7, 8);
uint8_t address[][6] = {"Node1"};
struct Data
{
unsigned char ch1;
unsigned char ch2;
} data;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setAutoAck(false);
radio.setRetries(0, 0);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.setPayloadSize(sizeof(data));
#ifdef RECEIVER
radio.startListening();
radio.openReadingPipe(1, address[0]);
#else
radio.stopListening();
radio.openWritingPipe(address[0]);
#endif
}
void loop()
{
#ifdef RECEIVER
if (radio.available())
{
radio.read(&data, sizeof(data));
Serial.print(data.ch1);
Serial.print(" ");
Serial.println(data.ch2);
}
#else
radio.write(&data, sizeof(data));
data.ch1 += 1;
data.ch2 += 2;
delay(500);
#endif
}
note that for the test nrf24 code there is another Arduino acting as a transmitter (by uploading the same sketch but without defining RECEIVER).
When I upload the test nrf24 sketch with the SD card module connected I get a continuous stream of "0 0" separated by a newline. When I upload the test SD sketch the output is as expected with both the nrf24 connected or disconnected.
