Hi, i'm working on a altimeter and somethonh dosen't work well. I want the uno to be able to see if there is no sd card or that the bmp 180 isn't well connected. if it happens, i want the built-in light to blink. sadly i've try a lot of things and the light dosen't stop blinking.
Adafruit_BMP085 bmp;
Sd2Card card; //Creating an object for the SD card
File myFile; //Preparing the files
int pinCS = 4; //Pin for the sd card
float Po = 1013.0;
char filename[] = "LOGGER00.CSV";
int altitude;
bool error;
void setup()
{
pinMode(pinCS, OUTPUT); //initialize digital pin pinCS as an output
pinMode(LED_BUILTIN, OUTPUT); //initialize digital pin LED_BUILTIN as an output
// create a new file
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
break; // leave the loop!
}
}
}
void loop()
{
bool error;
error = testing;
if (error == true)
{
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
//SD Card setup
myFile = SD.open(filename, FILE_WRITE);
if (myFile) {
If you press Ctrl-T in your Arduino IDE it will tidy up the indentation of your code.
Have you already tried an example sketch for the the SD reader to ensure that it works? (File->Examples->SD->CardInfo)
To trace the execution of your sketch and see what error conditions occur, you can write debugging information out to serial and view it in the serial monitor. (Serial.println("...") don't forget the Serial.begin(9600) in setup() )
You already, wisely, check for the success of myFile when it is opened. There is no point in testing again at the beginning of loop() as the file is closed and will always return false.
Something like this loop() might work for you:
void loop() {
bool error = false;
if (bmp.begin()) {
//SD Card setup
myFile = SD.open(filename, FILE_WRITE);
if (myFile) {
myFile.print("Altuino : ");
myFile.print("\t");
myFile.print(altitude);
myFile.print("\t");
myFile.print(" Meters");
myFile.close();
} else {
error = true;
}
} else {
error = true;
}
if (error) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
delay(500);
}