SD card + BMP280 - Arduino

Bonjour,

J'aimerai que les données de température et de pression reçues du BMP280 sur ma carte arduino uno se sauvegardent sur une SD card en plus d'apparaitre dans le moniteur série de l'IDE.

J'ai fait le programme ci-joint :


#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("DATA.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");
  }
}
 
     

Le hic c'est que ceci s'affiche sur le moniteur série :

Le programme du BMP seul fonctionne parfaitement, les programmes inclus dans la libraire de la SD également.
Je ne vois pas où cela coince...

Merci pour vos conseils et remarques !

Hello,

If you would be more comfortable, there is a french section of the forum.

https://forum.arduino.cc/c/international/francais/49

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.