Go Down

Topic: Arduino Based altimeter (Read 542 times) previous topic - next topic

M4K3R_4_M4R5

Feb 16, 2020, 09:09 pm Last Edit: Feb 16, 2020, 09:34 pm by M4K3R_4_M4R5
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.

/*
Pin configuration
BMP180
  VIN 3,3V
  GND GND
  SCL A5
  SDA A4
 
 SD Card
   CS 4
   SCK 13
   MOSI 11
   MISO 12
   VCC 5V
   GND GND
*/

#include <SD.h>           //Including SD library
#include <SPI.h>          //Including SPI library
#include <Wire.h>         //Including wire library
#include <Adafruit_BMP085.h>

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 testing()
{
  if (!bmp.begin())
    {
      error = true;
    }
  else
    {
      if (!SD.begin())
        {
          error = true;
        }
       else
        { 
          error = false;
        }
    }
}

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) {
     
     myFile.print("Altuino : ");
     myFile.print("\t");   
     myFile.print(altitude);
     myFile.print("\t");
     myFile.print(" Meters");
     myFile.close();
    }   
     
  delay(500);
}

arduarn

Code: [Select]
error = testing(); // don't forget the brackets!

M4K3R_4_M4R5

it gives me the error ''void value not ignored as it ought to be''

arduarn

it gives me the error ''void value not ignored as it ought to be''
Your function testing() needs to return a "bool" and I would move the global "error" variable into testing() as a local variable.

M4K3R_4_M4R5

my arduino is still blinking, what should i do?

arduarn

my arduino is still blinking, what should i do?
Post your updated sketch, this time in code tags (using the </> button in the post editor toolbar).

M4K3R_4_M4R5

Code: [Select]

/*
Pin configuration
BMP180
  VIN 3,3V
  GND GND
  SCL A5
  SDA A4
 
 SD Card
   CS 4
   SCK 13
   MOSI 11
   MISO 12
   VCC 5V
   GND GND
*/

#include <SD.h>           //Including SD library
#include <SPI.h>          //Including SPI library
#include <Wire.h>         //Including wire library
#include <Adafruit_BMP085.h>

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;

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;
 
  if (!bmp.begin())
    {
      error = true;
    }
  else
    {
      if (!myFile)
        {
          error = true;
        }
       else
        { 
          error = false;
        }
    }


    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) {
     
     myFile.print("Altuino : ");
     myFile.print("\t");   
     myFile.print(altitude);
     myFile.print("\t");
     myFile.print(" Meters");
     myFile.close();
    }   
     
  delay(500);
}

arduarn

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:

Code: [Select]
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);
}

M4K3R_4_M4R5

#8
Feb 16, 2020, 11:52 pm Last Edit: Feb 16, 2020, 11:52 pm by M4K3R_4_M4R5
thanks for helpig me, i've solved the problem!

Go Up