Trouble with BMP280 sensor and SD Card logger

Hello all,

I am trying to set up and Uno to sense pressure and temp via the BMP280 board and then log it to an Adadfruit micro SD card breakout. I managed to get sensor working but when I try to incorporate code to log the data to the SD card I’m told that the ‘File does not name a type’ for the line ‘File mySensorData’ I thought I was identifying an object for the data to be written to with this command.

I have allocated the chip select pins as pin 9 to the BMP280 and pin 4 to the SD Card reader/writer.

I know the SD Card reader/writer works as I’ve tested that independantly with a test sketch.

I’m confident the wiring is accurate given both the sensor and the SD card have functioned usingother sketches.

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 9

//Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI

int chipSelect = 4; //chipSelect pin for the SD card Reader
File mySensorData; //Data object you will write your sesnor data to

void setup() {

Serial.println(F(“BMP280 test”));

pinMode(10, OUTPUT); //Must declare 10 an output and reserve it
SD.begin(chipSelect); //Initialize the SD card reader

if (!bmp.begin()) {
Serial.println(F(“Could not find a valid BMP280 sensor, check wiring!”));
while (1);

void loop() {

mySensorData =“PTData.txt”, FILE_WRITE);
if (mySensorData) {

Serial.print(F(“Temperature = “));
Serial.println(” *C”);

Serial.print(F(“Pressure = “));
Serial.println(” Pa”);

Serial.print(F(“Approx altitude = “));
Serial.print(bmp.readAltitude(1013.25)); // this should be adjusted to your local forcase
Serial.println(” m”);

delay(250); //pause between readings

mySensorData.print(tempF); //write temperature data to card
mySensorData.print(","); //write a commma
mySensorData.println(pressure); //write pressure and end the line (println)
mySensorData.close(); //close the file

Any help you are able to give would be greatly appreciated, I am a total novice at this. The finished result will be going to the stratosphere under a weather balloon…hopefully!

Thank you in advance.

Best wishes


You may have met this problem:

That's great, thanks for your help I will have a look at this.

Best wishes


Can your BMP be wires as I2C (TWI)? (solves the problem) Adafruits shield uses 4050 buffer..? MI-line cannot be rerouted.