Writing Duplicate Data to 2nd SD card
new user here... new arduino well. trying write program test apparatus work. need write data 2 sd cards. 1 removed , transferred while other stays on board emergency backup. have far, know doing cs pins way wrong, cant find on how alternate them. of code had removed length. advice...
code: [select]
#include <softwareserial.h>
#include <spi.h>
#include <sd.h>
#define pushbutton 2
#define pushbutton2 3
#define ledpin 5
#define ledpin2 6
#define backsd 7
#define card_0_cs 7
#define card_1_cs 4
#define rx 0
#define tx 1
sdclass sd2;
sdclass *sdcard = &sd;
softwareserial bluetooth(rx,tx);
long int initialtime, elapsedtime; // used on pin 2 measeure start , stop time tell elapsed time
long int initialtime2, elapsedtime2; //used on pin 7
string inputstring = ""; // string hold incoming data
string diapernum = "";
string diapernum2 = "";
char testid[12];
string insultnum = "";
string insultnum2 = "";
boolean stringcomplete = false;
boolean waspreviously = 0;
boolean waspreviously2 = 0;
long minutes;
long seconds;
long minutes2;
long seconds2;
int = 0;
file testtime;
boolean testidok = false;
boolean diapernumok = false;
boolean diapernumok2 = false;
boolean insultnumok = false;
boolean leftdone = false;
boolean rightdone = false;
int insultcount = 0;
int insultcount2 = 0;
int insultcomplete = 0;
boolean sdalreadyini = false;
int cspin = 4;
void setup()
{
// bluetooth.println(sdalreadyini);
diapernum.reserve(20);
diapernum2.reserve(20);
insultnum.reserve(20);
insultnum2.reserve(20);
/*testid.reserve(8);*/
// open bluetooth communications , wait port open:
bluetooth.begin(9600);
pinmode(pushbutton, input);// setup trigger input
pinmode(pushbutton2, input);
pinmode(ledpin,output); // setup indicator light
pinmode(ledpin2,output);
// bluetooth.print("initializing sd card...");
pinmode(4, output);// write sd card
pinmode(7, output); // write 2nd sd card
digitalwrite(4, low);
digitalwrite(7, high);
if ( sdalreadyini == false) {
if (!sd.begin(4)) {
bluetooth.println("initialization failed!");
return;
}
}
void loop()
{
if (int count = 0 >1){
// open file. note 1 file can open @ time,
// have close 1 before opening another.
digitalwrite(4, low);
digitalwrite(7, high);
delay(100);
testtime = sd.open(testid, file_write);
// if file opened okay, write it:
if (testtime == true ) {
bluetooth.print("writing ");
bluetooth.print(testid);
testtime.print("test id:");
testtime.println(testid);
testtime.print("insult count: ");
testtime.print(insultcount);
testtime.print(" of ");
testtime.println(insultnum);
testtime.print("left diaper number: ");
testtime.print(diapernum);
testtime.print(" ");
testtime.print("right diaper number: ");
testtime.println(diapernum2);
testtime.print(minutes);
testtime.print(" minutes ");
testtime.print(seconds);
testtime.print(" seconds");
testtime.print(" ");
testtime.print(minutes2);
testtime.print(" minutes ");
testtime.print(seconds2);
testtime.println(" seconds");
// close file:
testtime.close();
//bluetooth.println("done.");
}
else {
// if file didn't open, print error:
bluetooth.println("error opening 1st time");
}
// re-open file reading:
testtime = sd.open(testid);
if (testtime == true ) {
bluetooth.println(testid);
// read file until there's nothing else in it:
while (testtime.available() > 0) {
bluetooth.write(testtime.read());
}
// close file:
testtime.close();
/*while(i == 0){
// bluetooth.println("waiting reset command");
if (bluetooth.read() == '37' || bluetooth.read() == '%') {
void(* resetfunc) (void) = 0;//declare reset function @ address 0
bluetooth.println("saw command didnt anything");
i = + 1;
}
else bluetooth.flush();
}*/
if (insultcomplete == insultcount){
bluetooth.println("testing complete");
testidok = false;
insultnumok = false;
diapernumok = false;
diapernumok2 = false;
leftdone = false;
rightdone = false;
insultcount = 0;
insultcomplete = 0;
insultnum = "";
sdalreadyini = true;
bluetooth.println("resetting in 5...");
delay(1000);
bluetooth.println("resetting in 4...");
delay(1000);
bluetooth.println("resetting in 3...");
delay(1000);
bluetooth.println("resetting in 2...");
delay(1000);
bluetooth.println("resetting in 1...");
delay(1000);
setup();
}
//bluetooth.println(sdalreadyini);
}
}
else {
// if file didn't open, print :
bluetooth.println("error opening 2nd time");
}
if (int count = 0 >1) {
// open file. note 1 file can open @ time,
// have close 1 before opening another.
digitalwrite(4, high);
digitalwrite(7, low);
delay(100);
testtime = sd2.open(testid, file_write);
// if file opened okay, write it:
if (testtime == true ) {
bluetooth.print("writing ");
bluetooth.print(testid);
testtime.print("test id:");
testtime.println(testid);
testtime.print("insult count: ");
testtime.print(insultcount);
testtime.print(" of ");
testtime.println(insultnum);
testtime.print("left diaper number: ");
testtime.print(diapernum);
testtime.print(" ");
testtime.print("right diaper number: ");
testtime.println(diapernum2);
testtime.print(minutes);
testtime.print(" minutes ");
testtime.print(seconds);
testtime.print(" seconds");
testtime.print(" ");
testtime.print(minutes2);
testtime.print(" minutes ");
testtime.print(seconds2);
testtime.println(" seconds");
// close file:
testtime.close();
//bluetooth.println("done.");
}
else {
// if file didn't open, print error:
bluetooth.println("error opening 1st time");
}
// re-open file reading:
testtime = sd.open(testid);
if (testtime == true ) {
bluetooth.println(testid);
// read file until there's nothing else in it:
while (testtime.available() > 0) {
bluetooth.write(testtime.read());
}
// close file:
testtime.close();
/*while(i == 0){
// bluetooth.println("waiting reset command");
if (bluetooth.read() == '37' || bluetooth.read() == '%') {
void(* resetfunc) (void) = 0;//declare reset function @ address 0
bluetooth.println("saw command didnt anything");
i = + 1;
}
else bluetooth.flush();
}*/
if (insultcomplete == insultcount){
bluetooth.println("testing complete");
testidok = false;
insultnumok = false;
diapernumok = false;
diapernumok2 = false;
leftdone = false;
rightdone = false;
insultcount = 0;
insultcomplete = 0;
insultnum = "";
sdalreadyini = true;
bluetooth.println("resetting in 5...");
delay(1000);
bluetooth.println("resetting in 4...");
delay(1000);
bluetooth.println("resetting in 3...");
delay(1000);
bluetooth.println("resetting in 2...");
delay(1000);
bluetooth.println("resetting in 1...");
delay(1000);
setup();
}
//bluetooth.println(sdalreadyini);
}
}
}
}
}
code: [select]
sdclass sd2;
sdclass *sdcard = &sd;
this won't work sd.h. sd.h wrapper 5 year old version of sdfat supports 1 card.
this version of sdfat supports multiple cards.
see twocard example.
the threecards example uses software spi 1 card , hardware spi other cards.
this version of sdfat can configured multiple cards recommend beta since version no longer supported.
Arduino Forum > Using Arduino > Storage > Writing Duplicate Data to 2nd SD card
arduino
Comments
Post a Comment