- Wed Mar 01, 2017 3:00 pm
#193677
Hi all,
I"m working on a data logger project these days.
All components are mounted on a breadboard.
On the breadboard is ,... an Arduino Nano running at 8Mhz, a DS3231 RTC, an SD card,..and the BME280 Atmospheric sensor.
The BME280 is connected to A4 &A5 via I2c,...the rtc (DS3231) and card are connected via SPI.
All components are being powered by the nano at 3.3V.
Here is the issue,..
I do read and write to the serial monitor,...logging to the card works as well.
The temperature and humidity readings are accurate.
The altitude reading is off by roughly double ( I'm at 136 meters, and the card logs 300+ meters).
I suspect a correction factor needs to be included in the code to correct to sea level.
Code is bellow...
Cheers,
Perry
#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"
#include "SD.h"
#include <DS3231.h>
BME280 mySensor;
DS3231 rtc(SDA, SCL);
float tempC; // Variable for holding temp in C
float pressure; // Variable for holding pressure reading
float humidity; // variable for humidity
int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to
void setup()
{
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = 0x77;
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
mySensor.settings.tempOverSample = 1;
mySensor.settings.pressOverSample = 1;
mySensor.settings.humidOverSample = 1;
Serial.begin(9600);
rtc.begin();
pinMode(10, OUTPUT);
SD.begin(4); //initialize the card reader
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
Serial.println(mySensor.begin(), HEX);
uint8_t memCounter = 0x80;
uint8_t tempReadData;
{
{
tempReadData = mySensor.readRegister(memCounter);
memCounter++;
}
}
}
void loop()
{
tempC = mySensor.readTempC(); // Read Temperature from BME280
pressure = mySensor.readFloatAltitudeMeters(); //Read Pressure
humidity = mySensor.readFloatHumidity(); //read humidity
mySensorData = SD.open("Datalog.txt", FILE_WRITE);
Serial.print(mySensor.readTempC(),0);
Serial.print(",");
Serial.print((mySensor.readFloatAltitudeMeters()-125),0);
Serial.print(",");
Serial.print(mySensor.readFloatHumidity(),0);
Serial.print (" ");
Serial.print(rtc.getTimeStr());
Serial.println();
mySensorData.print((tempC),0); //write temperature to card
mySensorData.print(",");
mySensorData.print((pressure),1); //write pressure to the card
mySensorData.print(",");
mySensorData.print((humidity),0); //write humidity to the card
mySensorData.print(" ");
mySensorData.print(rtc.getTimeStr()); //write time to the card
mySensorData.println();
mySensorData.close(); //close the file
delay(1000);
}
I"m working on a data logger project these days.
All components are mounted on a breadboard.
On the breadboard is ,... an Arduino Nano running at 8Mhz, a DS3231 RTC, an SD card,..and the BME280 Atmospheric sensor.
The BME280 is connected to A4 &A5 via I2c,...the rtc (DS3231) and card are connected via SPI.
All components are being powered by the nano at 3.3V.
Here is the issue,..
I do read and write to the serial monitor,...logging to the card works as well.
The temperature and humidity readings are accurate.
The altitude reading is off by roughly double ( I'm at 136 meters, and the card logs 300+ meters).
I suspect a correction factor needs to be included in the code to correct to sea level.
Code is bellow...
Cheers,
Perry
#include "SparkFunBME280.h"
#include "Wire.h"
#include "SPI.h"
#include "SD.h"
#include <DS3231.h>
BME280 mySensor;
DS3231 rtc(SDA, SCL);
float tempC; // Variable for holding temp in C
float pressure; // Variable for holding pressure reading
float humidity; // variable for humidity
int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to
void setup()
{
mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = 0x77;
mySensor.settings.runMode = 3; //Normal mode
mySensor.settings.tStandby = 0;
mySensor.settings.filter = 0;
mySensor.settings.tempOverSample = 1;
mySensor.settings.pressOverSample = 1;
mySensor.settings.humidOverSample = 1;
Serial.begin(9600);
rtc.begin();
pinMode(10, OUTPUT);
SD.begin(4); //initialize the card reader
delay(10); //Make sure sensor had enough time to turn on. BME280 requires 2ms to start up.
Serial.println(mySensor.begin(), HEX);
uint8_t memCounter = 0x80;
uint8_t tempReadData;
{
{
tempReadData = mySensor.readRegister(memCounter);
memCounter++;
}
}
}
void loop()
{
tempC = mySensor.readTempC(); // Read Temperature from BME280
pressure = mySensor.readFloatAltitudeMeters(); //Read Pressure
humidity = mySensor.readFloatHumidity(); //read humidity
mySensorData = SD.open("Datalog.txt", FILE_WRITE);
Serial.print(mySensor.readTempC(),0);
Serial.print(",");
Serial.print((mySensor.readFloatAltitudeMeters()-125),0);
Serial.print(",");
Serial.print(mySensor.readFloatHumidity(),0);
Serial.print (" ");
Serial.print(rtc.getTimeStr());
Serial.println();
mySensorData.print((tempC),0); //write temperature to card
mySensorData.print(",");
mySensorData.print((pressure),1); //write pressure to the card
mySensorData.print(",");
mySensorData.print((humidity),0); //write humidity to the card
mySensorData.print(" ");
mySensorData.print(rtc.getTimeStr()); //write time to the card
mySensorData.println();
mySensorData.close(); //close the file
delay(1000);
}