Hi, i have this project which accessing a text from SD card and then use that as a value.
But some error happen and i try to fix and googling for the solution but still failed.
Can you guys help me why this is happen?
Here is my sketch :
#include <Wire.h>
/* Include the Hobby Components RTC library */
#include <HCRTC.h>
/* Include the standard SD card library */
#include <SD.h>
/* The RTC has a fixed addresses of 0x68 */
#define I2CDS1307Add 0x68
/* DIO pin used to control the SD card CS pin */
#define SD_CS_DIO 10
/* Create an instance of HCRTC library */
HCRTC HCRTC;
/* Create an instance of the standard SD card library */
File SDFiles;
void setup()
{
/* Initialise the serial port */
Serial.begin(9600);
/* Set the SD card CS pin to an output */
pinMode(SD_CS_DIO, OUTPUT);
/* Use the RTCWrite library function to set the time and date.
Parameters are: I2C address, year, month, date, hour, minute, second,
day of week. You would normally only need to do this once */
HCRTC.RTCWrite(I2CDS1307Add, 15, 2, 24, 14, 21, 0, 2);
/* Initialise the SD card */
if (!SD.begin(SD_CS_DIO))
{
/* If there was an error output this to the serial port and go no further */
Serial.println("ERROR: SD card failed to initialise");
while(1);
}else
{
Serial.println("SD Card OK");
}
// SDFiles = SD.open("hit.txt", FILE_WRITE);
//
// if (SDFiles)
// {
// SDFiles.println("Tomat");
// SDFiles.println(60);
// SDFiles.println(3.14);
// SDFiles.println(3.17);
// SDFiles.println(3.20);
// SDFiles.println(3.16);
//
// SDFiles.close();
// }
}
String nama = "";
int count =0;
int hari = 0;
String dump = "";
double x = 0;
double nilai[] = {};
/* Main Loop */
void loop()
{
SDFiles = SD.open("hit.txt");
if (SDFiles)
{
while (SDFiles.available()) {
if (count == 0)
{
nama = SDFiles.readStringUntil('\n');
Serial.print(count);
Serial.print("\t");
Serial.println(nama);
count++;
}
else if (count == 1)
{
dump = SDFiles.readStringUntil('\n');
hari = dump.toInt()-54;
Serial.print(count);
Serial.print("\t");
Serial.println(hari);
count++;
}
else
{
dump = SDFiles.readStringUntil('\n');
x = dump.toFloat();
Serial.print(count);
Serial.print("\t");
nilai[count-2] = x;
Serial.print(x);
Serial.print("\t");
Serial.print(count);
Serial.print("\t");
Serial.println(nilai[count-2]);
count++;
}
}
SDFiles.close();
}
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
count = 0;
Serial.println();
/* Wait a second before reading again */
delay(1000);
}
I comment the SD card writing cause the text is already in the SD card.
And here is pic of serial result
Thank you,
Really appreciate this forum as a former shadow member ![]()