hello,
i am working on a project and i am using 2 arduinos one to trigger a relay at a specific time and when the relay is on i want to send the following parameters to the second arduino (minute,hour,day,month and year) in my project i am using a GLCD with the following library
the problem i had is the type of data used by the glcd which is uint8_t
and when i want to send the time parameters (minute , hour,day,month and year) i have random values
and to solve this problem i put them in a char using the following command sprintf as follow:
when the relay is on i use this code to send my parameters
char value[20];
sprintf(value,“1z%d:%dz%d/%d/%di”,minute(),hour(),day(),month(),year());
Serial.write(value);
delay(10);
and in the second arduino i am using the following code :
#include <SPI.h>
#include <SD.h>
File myFile;
char mystr[22]; //Initialized variable to store recieve
int a=0;
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print(“Initializing SD card…”);
if (!SD.begin(10)) {
Serial.println(“initialization failed!”);
while (1);
}
Serial.println(“initialization done.”);
}
void loop() {
}
void serialEvent() {
if(Serial.available()>0){
SD.begin(10);
Serial.readBytes(mystr,17); //Read the serial data and
Serial.readStringUntil(‘i’);
Serial.println(mystr);
Serial.println(“RECEIVER”);
myFile = SD.open(“saa.txt”);
if (myFile) {
myFile = SD.open(“saa.txt”, FILE_WRITE);
myFile.print(mystr);
myFile.println(a);
a=a+1;
myFile.close();
} else {
// if the file didn’t open, print an error:
Serial.println(“error opening test.txt”);
}
}
}
the problem i had is when the arduino saves only 20 times and the when the relay is on more than 20 times the values are not saved in my sd card
help me please