Tom No, It can't be connected. I'm using the SD card.
Hi!
I'm having some trouble to make the nRF24l01 work with the micro card SD.
After the line lcd.print("Iniciando..."); my lcd just freezes and nothing happens.
Before I included the micro card SD it was working pretty fine.
I put the chipSelect for both and made it HIGH an LOW when using them.
PIN 13 - SCK , 12 - MISO and 11 - MOSI the same for both. PIN 9 for nRF CS and PIN 10 to SD CS.
Give me some advice please!
Thanks.
#include <SD.h>
#include <SPI.h>
#include <RF24.h>
#include <LiquidCrystal.h>
RF24 radio (8, 9);
byte enderecos[][6] = {"1node"};
const int chipSelectnRF = 9;
const int chipSelectSD = 10;
File dataFile;
LiquidCrystal lcd(3, 2, 7, 6, 5, 4);
String dadosrecebidos[2];
void setup ()
{
SPI.begin();
pinMode(chipSelectnRF, OUTPUT);
radio.begin();
radio.openReadingPipe(1, enderecos[0]);
radio.startListening();
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Teste 1.6");
delay(5000);
lcd.setCursor(3, 2);
lcd.print("Carregando...");
delay(5000);
lcd.clear();
digitalWrite(chipSelectnRF, HIGH);
pinMode(chipSelectSD, OUTPUT);
if (SD.begin(chipSelectSD))
{
lcd.setCursor(0, 0);
lcd.print("Cartao presente!");
lcd.setCursor(0, 1);
lcd.print("Pronto para gravar.");
delay(5000);
lcd.setCursor(3, 3);
lcd.print("Iniciando...");
delay(5000);
}
else
{
lcd.setCursor(0, 0);
lcd.print("Insira o cartao!");
lcd.setCursor(0, 1);
lcd.print("Se ja inseriu,");
lcd.setCursor(0, 2);
lcd.print("verifique o");
lcd.setCursor(0, 3);
lcd.print("cartao");
delay(5000);
}
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (dataFile)
{ // if the file is available, write to it:
dataFile.println("Tensão e velocidade");
//I often print many extra lines of text in file headers, identifying details about the hardware being used, the code version that was running, etc
dataFile.close();
}
else
{
dataFile.println("Erro");
}
digitalWrite(chipSelectSD, HIGH);
digitalWrite(chipSelectnRF, HIGH);
}
void recebido ()
{
digitalWrite(chipSelectnRF, LOW);
if (radio.available())
{
while (radio.available())
{
radio.read(&dadosrecebidos, sizeof(dadosrecebidos));
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TENSAO");
lcd.setCursor(7, 0);
lcd.print(dadosrecebidos[0]);
lcd.print("VOLTS");
lcd.setCursor(0, 1);
lcd.print("VELOCIDADE");
lcd.setCursor(11, 1);
lcd.print(dadosrecebidos[1]);
lcd.print("KM/H");
}
digitalWrite(chipSelectnRF, HIGH);
}
void gravar()
{
digitalWrite(chipSelectSD, LOW);
// make a string for assembling the data to log:
String dataString = ""; //this line simply erases the string
dataString += "Tensao ";
dataString += (dadosrecebidos[0]);
dataString += " VOLTS";
dataString += " / "; //puts a comma between the two bits of data
dataString += "Velocidade ";
dataString += (dadosrecebidos[1]);
dataString += " KM/H";
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
}
// if the file isn't open, pop up an error:
else
{
dataFile.println("Erro");
}
digitalWrite(chipSelectSD, HIGH);
}
void loop ()
{
recebido();
gravar();
}