Datalogger GPS - BME280 incompatibilità

Ciao a tutti,

sto provando a costruire come da titolo un datalogger gps + bme280. Il ricevitore gps (un classico neo 6m) è collegato ad un arduino uno in seriale, e un sensore bme collegato in i2c. Oltre a ciò ho collegato anche un lettore SD in SPI.

Lettore SD e GPS sono alimentati a 5V e 3.3V dai pin dedicato su arduino, mentre il bme è alimentato attraverso il pin 2 settatto su high.

Il datalogger legge un po' di dati provenienti dai due sensori, genera una array di array in cui salva i dati e li scrive ogni "n" secondi, per evitare di scrivere ogni secondo più volte la scheda SD

I file vengono poi distribuiti in tre file diversi.

Lo script utilizza le librerie NEOGPS di SlashDevin per il GPS, la libreria BME280I2C di Tyler Glenn per il BME e la libreria SdFat di Bill Greiman per la lettura/scrittura della scheda SD.

Singolarmente sono riuscito a far funzionare tutto, ma mettendo tutto insieme non ottengo risposta dal sensore BME, o meglio ottengo rispettivamente i valori 0.00 per la temperatura e Nan dalla pressione.

Credo che il problema sia la coesistenza di I2C - seriale.

Allego il codice

#include <BME280I2C.h>  // library for the BME280 temp-humidity-pressure sensor
#include <Wire.h>
#include <SdFat.h>            // library to use memory SD card
#include <NMEAGPS.h>          // library to use GPS module
#include <EEPROM.h>           // library to read and write EEPROM memory
#include <SPI.h>              // library to connect in SPI mode (the SD card reader)

NMEAGPS     gps;              // create the gps object
SdFat sd;                     // created an SD object
BME280I2C bme;          //create a BME object connected in I2C mode to arduino

#include <GPSport.h>          // define the port to be used for GPS controller

// initialize the variables,  i as a counter of seconds in the for cylce
//                            dist1 as a counter of the distance from the first track position from the power on
//                            Array as a matrix containing all the information fitted in the 10 seconds cycle
int i = 0;
float dist1 = 0.00;
float Array [5][11];
bool status;

float temp = 0.0;
float hum = 0.0; 
float pres = 0.0;
BME280::TempUnit tempUnit(BME280::TempUnit_Celsius);
BME280::PresUnit presUnit(BME280::PresUnit_Pa);

void setup()
{
  // initialize GPS port
  gpsPort.begin(9600);
  DEBUG_PORT.begin(9600);

  // to power the BME280 sensor
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);

  digitalWrite(2,HIGH);
  digitalWrite(3,LOW);
  
  Wire.begin();
  
  // Verify SD card in the dedicated port
  if (!sd.begin()) {
    // do nothing
    while (1);
  }
  
 
}

void loop()
{
  // verifiy if GPS module is availabe and working, if not do nothing
  if (gps.available( gpsPort )) {
    // save the fix of the first position red from the power on of the system
    gps_fix fix = gps.read();

    // cycle that determine the correct variable for a complete fix of the position
    if (fix.valid.date == true & fix.valid.time == true & (int)fix.latitude() != 0) {

      // verifiy the date from GPS signal and save it in the EEPROM
      if (EEPROM.read(0) != fix.dateTime.date) {
        EEPROM.write(0, fix.dateTime.date);
      }
      if (EEPROM.read(1) != fix.dateTime.month) {
        EEPROM.write(0, fix.dateTime.month);
      }
      if (EEPROM.read(2) != fix.dateTime.year) {
        EEPROM.write(0, fix.dateTime.year);
      }

      bme.read(pres, temp, hum, tempUnit, presUnit);

      Array[i][0] = fix.latitudeL() / 10000000; // Latitude in degree floating point max precision
      Array[i][1] = fix.longitudeL() / 10000000;// Latitude in degree floating point max precision
      Array[i][2] = fix.altitude();             // Altitude taken from GPS in meters in floating point
      Array[i][3] = fix.speed_kph();            // Velocity in km/h
      Array[i][4] = fix.dateTime.hours;         // hours
      Array[i][5] = fix.dateTime.minutes;       // minutes
      Array[i][6] = fix.dateTime.seconds;       // seconds
      Array[i][7] = fix.heading();              // direction in degree
      Array[i][8] = temp;                       // air temperature from bme sensor in °C
      Array[i][9] = pres;                       // air pressure from bme sensor in Pa
      Array[i][10] = hum;                       // humidity from bme sensors in %

      DEBUG_PORT.println(temp);
      DEBUG_PORT.println(pres);

      // create filename from the date where to store daily data
      String fileName;
      if ((fix.dateTime.year / 10U % 10) == 0) fileName.concat("200");
      if ((fix.dateTime.year / 10U % 10) != 0) fileName.concat("20");
      fileName.concat(fix.dateTime.year);
      if ((fix.dateTime.month / 10U % 10) == 0) fileName.concat("0");
      fileName.concat(fix.dateTime.month);
      if ((fix.dateTime.date / 10U % 10) == 0) fileName.concat("0");
      fileName.concat(fix.dateTime.date);

             
      if (i == 4) {

        // firts position coordinate of the array
        const NeoGPS::Location_t firstpoint(Array[0][0], Array[0][1]); 
        
        // calculate the distance run between the last point of the array and the first one
        float dist = fix.location.DistanceKm(firstpoint);
        dist1 = dist1 + dist;

        // open and generate file where to write
        File datafile = sd.open("Summary.txt", FILE_WRITE);

        int x = 0;
        for (x = 0; x <= 4; x++) {

        // if file is open and ready to be written, write it on:
        if (datafile) {
            datafile.print(EEPROM.read(2) + 2000);
            datafile.print("-");
            datafile.print(EEPROM.read(1));
            datafile.print("-");
            datafile.print(EEPROM.read(0));
            datafile.print(";");
            datafile.print((int)Array[x][4]);
            datafile.print("-");
            datafile.print((int)Array[x][5]);
            datafile.print("-");
            datafile.print((int)Array[x][6]);
            datafile.print(";");
            datafile.print(Array[x][3]);
            datafile.print(";");
            if (Array[x][7] <= 22.5 & Array[x][7] > 337.5) datafile.print("N");
            if (Array[x][7] > 22.5 & Array[x][7] <= 67.5) datafile.print("NE");
            if (Array[x][7] > 67.5 & Array[x][7] <= 112.5) datafile.print("E");
            if (Array[x][7] > 122.5 & Array[x][7] <= 167.5) datafile.print("SE");
            if (Array[x][7] > 167.5 & Array[x][7] <= 212.5) datafile.print("S");
            if (Array[x][7] > 212.5 & Array[x][7] <= 257.5) datafile.print("SW");
            if (Array[x][7] > 257.5 & Array[x][7] <= 302.5) datafile.print("W");
            if (Array[x][7] > 302.5 & Array[x][7] <= 337.5) datafile.print("NW");
            datafile.print(";");
            datafile.print(Array[x][0]);
            datafile.print(";");
            datafile.print(Array[x][1]);
            datafile.print(";");
            datafile.print(Array[x][2]);
            datafile.print(";");
            datafile.print(Array[x][8]);
            datafile.print(";");
            datafile.print(Array[x][10]);
            datafile.print(";");
            datafile.print(Array[x][9]);
            datafile.println(";");

            }

            
        }

        //Close the file
        datafile.close();

        // open and generate dayfile file of temperature 
        String temp = fileName;
        temp.concat("Temp.txt");
        File dayfile = sd.open(temp, FILE_WRITE);
        dayfile.print(dist1);
        dayfile.print(";");
        dayfile.print(fix.alt.whole);
        dayfile.print(";");
        dayfile.print(Array[4][8]);
        dayfile.print(";");
        dayfile.print(Array[4][10]);
        dayfile.println(";");
        dayfile.close();

        // open and generate dayfile file of position
        String pos = fileName;
        pos.concat("POS.txt");
        File posfile = sd.open(pos,FILE_WRITE);
        int y = 0;
        for (y=0; y <= 4; y++) {
          posfile.print(Array[y][0]);
          posfile.print(";");
          posfile.print(Array[y][1]);
          posfile.println(";");
        }

        posfile.close();
      }

      i++;

      if (i >= 5) {
          i = 0;
         }
    
    }

    
  }

}

Grazie a chi proverà a darci un occhio

Buongiorno,
essendo il tuo primo post, nel rispetto del regolamento della sezione Italiana del forum (… punto 13, primo capoverso), ti chiedo cortesemente di presentarti IN QUESTO THREAD (spiegando bene quali conoscenze hai di elettronica e di programmazione ... possibilmente evitando di scrivere solo una riga di saluto) e di leggere con MOLTA attenzione il su citato REGOLAMENTO ... Grazie.

Guglielmo

P.S.: Qui una serie di link utili, NON necessariamente inerenti alla tua domanda:
- serie di schede by xxxPighi per i collegamenti elettronici vari: ABC - Arduino Basic Connections
- pinout delle varie schede by xxxPighi: Pinout
- link generali utili: Link Utili