Nano Every + SD card

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 !

My (wild) guess is a wiring error. As you didn't provide a wiring diagram that's the best assumption I can make.

BTW, it's bad style to write an error message with wrong content (test.txt <-> DATA.txt).

The connections are as follows:

sd breakout - Nano every :
5V to the 5V pin of the Arduino.
GND to the GND pin of the Arduino.
CLK to pin 13
DO to pin 12
DI to pin 11
CS to pin 10

and BMP280 - Nano Every :
5V to the 5V pin of the Arduino
GND to the GND pin of the Arduino
SCL to A5 pin
SDA to A4 pin

If it is a wiring error, the program of the BMP and the ReadWrite of the SD library would not work, right? But it does.

Concerning the error message, I forgot to modify it :wink:
Thanks

It does work with exactly that hardware setup? So you just changed the code and left the hardware exactly as described above?

Yes, exactly. I don't touch the connections, I just change the code.
Also, the bmp+sd code works with an arduino uno or a nano.
The problem would come from the nano every ?

Try a pinMode(8, OUTPUT) in setup() (at the beginning) and report results. D8 is SS and may influence the behavior in certain situations. The Arduino SPI library doesn't set the corresponding bit explicitly and by default it has a rather problematic setting.

1 Like

Thank you !

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