Cannot open text file in SD card using SD.open function

Hello, Arduino users

I am having a trouble demonstrating the writing temperature values in a text file saved in SD card.
According to my code as shown in the below, the lightblue bean+ (Arduino Code compatible) cannot even open the log.txt file and keeps showing "error opening log.txt" error message with blinking red LED.

I am currently using a lightblue bean+, SD card shield, and a 2GB SD card as shown in the following pictures.
I used 3.3V pin from bean+ to the SD card shield for the power input and connected two GNDs on SD card shield to the GND on the bean+.
Other settings are exactly same with the one shown in the following link.

Any help will be very much appreciated. Thank you very much!

Best regards,

Sunghun


/*
This example shows how to get the ambient temperature
in degrees Celsius from the Bean's built-in temperature sensor
and log it on an SD card using the SD library.

Please note that you have to modify the SD library to use
it with the Bean.

In Sd2PinMap.h, line 278-281, change the pins to the following:
SS_PIN = 2;
MOSI_PIN = 3;
MISO_PIN = 4;
SCK_PIN= 5;

This example code is in the public domain.
*/

#include
#include

const int chipSelect = 2;
uint8_t temp;

void setup()
{
Serial.begin();
// Check if the card is present and can be initialized
if (!SD.begin(chipSelect)) {
Serial.println("SD fail");
return;
}
}

void loop()
{
// Get the ambient temperature with a range of -40C to 87.5C
temp = Bean.getTemperature();

// Open the data file
File dataFile = SD.open("log.txt", FILE_WRITE);

// If the file is available, write to it:
if (dataFile) {
dataFile.println(String(temp));
dataFile.close();

// If the file is open, send a message over serial
Serial.println("ok opening log.txt");
Bean.setLed(0, 255, 0); // green
delay(1000);
Bean.setLed(0, 0, 0);
}

// If the file isn't open, send an error message over serial
else {
Serial.println("error opening log.txt");
Bean.setLed(255, 0, 0); // red
delay(1000);
Bean.setLed(0, 0, 0);
}

// Sleep for a minute before we read the temperature again
Bean.sleep(1000);
}

jungx148:
I am having a trouble demonstrating the writing temperature values in a text file saved in SD card.

It would help if you properly explained what actually happens. Do you see any of the serial.prints, and if so which?

Assuming you have properly edited the SD library and the SD is properly identified, have you properly formatted the SD? There is a sticky about this at the head of the forum. I believe Arduino can see and identify a card that isn't kosher, but still not be able to write to it.

Thank you very much for the response, Nick.

If I run the above code, I get an error message showing "error opening log.txt" with blinking red LED.

Yes, I edited Sd2PinMap.h file as shown in the below and it should be okay since it is recommended by Lightblue Bean website (or, they might be wrong..).

SDA_PIN = 18
SCL_PIN = 19

SS_PIN = 2
MOSI_PIN = 3
MISO_PIN = 4
SCK_PIN = 5

Yes, I also formatted the SD card as FAT16 as other users recommend.

Lastly, yes, I think my problem is exactly what you said. Lightblue Bean+ (or, Arduino) can recognize the SD card, but it still could not write values in the .txt file.

Anyone has other tips which I could try?

jungx148:
Yes, I edited Sd2PinMap.h file as shown in the below and it should be okay since it is recommended by Lightblue Bean website (or, they might be wrong..).

They are probably not wrong

Yes, I also formatted the SD card as FAT16 as other users recommend.

That is only half an answer. The card needs to be formatted with the proper software

I formatted the SD card into FAT16 using the SD Card Formatter (SD Memory Card Formatter | SD Association), but it still cannot write temperature values in the log.txt file...

No one could guess what the cause of this issue..?