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);
}

