hello,
im very new to the arduino world and i seem to have a coding problem.
im trying to log the sensor output of a SPI adafruit bmp183 pressure sensor onto a SD card.
Im able to do so only when loop() is executed for the first time, after that the logged data is just nonsense.
It seems that the sensor and the SD card are not playing nice over SPI. I have read that it might have something to do with SPI modes ? any help would be appreciated.
//import all needed libaries.
#include <Adafruit_BMP183.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <SD.h>
Adafruit_BMP183 altimeter = Adafruit_BMP183(13,12,11,10);
//create integer that will hold groundpressure data gathered in setup() and used in loop().
float groundpressure = 0;
void setup(void)
{
//start altimeter and get groundpressure.
altimeter.begin();
groundpressure=altimeter.getPressure() / 100.00;
}
//create integer that holds time just before loop() starts.
unsigned long time=millis();
void loop()
{
//read BMP183 sensor data.
float temperature = altimeter.getTemperature();
float pressure = altimeter.getPressure();
float altitude = altimeter.getAltitude(groundpressure);
//open data file and write data.
SD.begin(9);
File datafile = SD.open("data.txt",FILE_WRITE);
datafile.println(pressure);
datafile.println(temperature);
datafile.println(altitude);
datafile.println(groundpressure);
datafile.close();
delay(2000);
altimeter.begin();
}
this is the data im getting (Pressure,Temperature,altitude):
101432.00
25.16
0.58
240289.00
225.83
-7907.45
240289.00
225.83
-7907.45
240289.00
225.83
-7907.45