Hello,
I would like the temperature and pressure data received from the BMP280 on my arduino card to be saved on an SD card in addition to appearing in the IDE serial monitor. With the code I'm currently using this doesn't work.
The motherboard used is an arduino nano every.
Here is the program:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <SD.h>
Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
File myFile;
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(10)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println(F("BMP280 test"));
//if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
}
void loop() {
// open the file. note that only one file can be open at a time,
File myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
myFile.print(bmp.readTemperature());
myFile.print(",");
myFile.print(bmp.readPressure());
myFile.print(",");
myFile.println(bmp.readAltitude(1013.25));
Serial.print(bmp.readTemperature());
Serial.print(",");
Serial.print(bmp.readPressure());
Serial.print(",");
Serial.println(bmp.readAltitude(1013.25)); /* Adjusted to local forecast! */
myFile.close();
delay(1000);
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
And this is the message received on the serial monitor:
The complete program (posted above) works with an arduino uno or nano board. But I need a nano every for my project and the program does not work with this type of board.
The SD library programs (like readwrite) also work on the nano every.
Would you have a suggestion for my program to work with the nano every?
Thank you very much for your advice !