Go Down

Topic: Problema sensor SparkfunBME280 (Read 57 times) previous topic - next topic

ecabanas

Hola a todos,

Estoy con un MKRFox1200 que se despierta cada 15 minutos para leer de un sensor SparkfunBME280 y un SHt10.

El problema es que cuando se levanta por primera vez, lee bien ambos sensores, pero al cabo de 15 minutos el sht10 lee bien, pero el BME280 da lecturas erroneas o como si estuviera desconectado.

Esto cambiando mil cosas pero ya no se que hacer, a ver si se os ocurre alguna solucion

Mil gracias

Eduard

Code: [Select]
#include "SigFox.h"
#include "ArduinoLowPower.h"
#include <SHT1x.h>
#include <SparkFunBME280.h>
#include <stdint.h>
#include "Wire.h"
#include "SPI.h"

//Global sensor object
BME280 mySensor;

// Specify data and clock connections and instantiate SHT1x object
#define dataPin  11
#define clockPin 12
SHT1x sht1x(dataPin, clockPin);

#define DEBUG         false             // Set DEBUG to false to disable serial prints
#define SLEEPTIME     15 * 60 * 1000   // Set the delay to 15 minutes (15 min x 60 seconds x 1000 milliseconds)
#define UINT16_t_MAX  65536
#define INT16_t_MAX   UINT16_t_MAX/2
#define UINT8_t_MAX  256
#define INT8_t_MAX   UINT8_t_MAX/2
int8_t convertoFloatToInt8(float value, long max, long min);
uint8_t convertoFloatToUInt8(float value, long max, long min);

typedef struct __attribute__ ((packed)) sigfox_message {
  uint8_t status;
  uint8_t vvoltage;
  int8_t bmetemp;
  uint8_t bmepress;
  int8_t soiltemp;
  uint8_t soilhum;
  uint8_t bmehum;
  uint8_t lastMessageStatus;
} SigfoxMessage;


// Stub for message which will be sent
SigfoxMessage msg;



void setup() {



 
  LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE);
        if (DEBUG) {
                // We are using Serial1 instead than Serial because we are going in standby
                // and the USB port could get confused during wakeup. To read the DEBUG prints,
                // connect pins 13-14 (TX-RX) to a 3.3V USB-to-serial converter
                Serial1.begin(115200);
                while (!Serial1) {}
        }

        if (!SigFox.begin()) {
                // Something is really wrong, try rebooting
                // Reboot is useful if we are powering the board using an unreliable power source
                // (eg. solar panels or other energy harvesting methods)
                reboot();
        }

        // Send module to standby until we need to send a message
        SigFox.end();

        if (DEBUG) {
                // Enable DEBUG prints and LED indication if we are testing
                SigFox.debug();
        }

       
}

void loop() {
          mySensor.begin();
    mySensor.settings.commInterface = I2C_MODE;
  mySensor.settings.I2CAddress = 0x77;
  mySensor.settings.runMode = 3; //Normal mode
  mySensor.settings.tStandby = 0;
  mySensor.settings.filter = 0;
  mySensor.settings.tempOverSample = 1;
  mySensor.settings.pressOverSample = 1;
  mySensor.settings.humidOverSample = 1;
  mySensor.calibration.dig_T1;
  mySensor.calibration.dig_T2;
  mySensor.calibration.dig_T3;
  mySensor.calibration.dig_P1;
  mySensor.calibration.dig_P2;
  mySensor.calibration.dig_P3;
  mySensor.calibration.dig_P4;
  mySensor.calibration.dig_P5;
  mySensor.calibration.dig_P6;
  mySensor.calibration.dig_P7;
  mySensor.calibration.dig_P8;
  mySensor.calibration.dig_P9;
  mySensor.calibration.dig_H1;
  mySensor.calibration.dig_H2;
  mySensor.calibration.dig_H3;
  mySensor.calibration.dig_H4;
  mySensor.calibration.dig_H5;
  mySensor.calibration.dig_H6;         
  // Every 15 minutes, read all the sensors and send them
  // Let's try to optimize the data format
  // Only use floats as intermediate representaion, don't send them directly

           ///////////////////////////////////////////////////////////////Lectura BME280///////////////////////////////////////////////////////////////
//digitalWrite(11, HIGH);
//digitalWrite(12, HIGH);
float bmepressure = mySensor.readFloatPressure();
msg.bmepress = convertoFloatToUInt8(bmepressure, 2000, 0);
delay(1000);
float bmetemperature = mySensor.readTempC();
msg.bmetemp = convertoFloatToInt8(bmetemperature, 60, -60);
delay(1000);
float bmehumidity = mySensor.readFloatHumidity();
msg.bmehum = convertoFloatToUInt8(bmehumidity, 110, 0);
//digitalWrite(11, LOW);
//digitalWrite(12, LOW);
delay(1000);
///////////////////////////////////////////////////////////////Lectura SHT10///////////////////////////////////////////////////////////////       
//digitalWrite(11, HIGH);
//digitalWrite(12, HIGH);
float shttemp = sht1x.readTemperatureC();
msg.soiltemp = convertoFloatToInt8(shttemp, 60, -60);
float shthum= sht1x.readHumidity();
msg.soilhum = convertoFloatToUInt8(shthum,  110, 0);
//digitalWrite(11, LOW);
//digitalWrite(12, LOW);

///////////////////////////////////////////////////////////////Lectura Bateria///////////////////////////////////////////////////////////////
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
msg.vvoltage = convertoFloatToUInt8(voltage, 5, 0);


        if(DEBUG) {
                Serial.print("Humidity: ");
                Serial.print(shthum);
                Serial.print(" %\t");
                Serial.print("Temperature: ");
                Serial.print(shttemp);
                Serial.print(" *C ");
        }
        // Start the module
        SigFox.begin();
        // Wait at least 30ms after first configuration (100ms before)
        delay(100);

        // We can only read the module temperature before SigFox.end()
//        t = SigFox.internalTemperature();
        //msg.moduleTemperature = convertoFloatToInt16(t, 60, -60);

        // Clears all pending interrupts
        SigFox.status();
        delay(1);

        SigFox.beginPacket();
        SigFox.write((uint8_t*)&msg, 12);

        msg.lastMessageStatus = SigFox.endPacket();

        SigFox.end();
        //Sleep for 15 minutes
        LowPower.sleep(SLEEPTIME);
}

void reboot() {
        NVIC_SystemReset();
        while (1) ;
}

int16_t convertoFloatToInt16(float value, long max, long min) {
        float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min);
        return (int16_t)(value * conversionFactor);
}

uint16_t convertoFloatToUInt16(float value, long max) {
        float conversionFactor = (float) (UINT16_t_MAX) / (float)(max);
        return (uint16_t)(value * conversionFactor);
}

int8_t convertoFloatToInt8(float value, long max, long min) {
  float conversionFactor = (float) (INT8_t_MAX) / (float)(max - min);
  return (int8_t)(value * conversionFactor);
}

uint8_t convertoFloatToUInt8(float value, long max, long min) {
  float conversionFactor = (float) (UINT8_t_MAX) / (float)(max - min);
  return (uint8_t)(value * conversionFactor);
}

void dummy() {
  volatile int aaa=0;
}

Go Up