0

I have connected an UNO with BMP280 and it sends reading through ESP-01 to thingspeak, and all seems working fine, but my pressure readings seem a bit odd.

To be clear any unchanged pressure reading is around 35.000 value.

As i understood that is in pascal, which is a bit strange, because the expected pascal value should be around 100.000

Code used is below, what am i missing ? Or are the readings ok?

Connection diagram and code used below: connection diagram

    //ThingSpeak channel Key
String statusChWriteKey = "asd";

//Basic icludes
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(6, 7); // Rx,  Tx
#define HARDWARE_RESET 8

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

Adafruit_BMP280 bme; // I2C


int temperature = 0;
int pressure = 0;
int altitude = 0;


// Variables to be used with timers
long writeTimingSeconds = 17; // ==> Define Sample time in seconds to send data
long startWriteTiming = 0;
long elapsedWriteTime = 0;

int spare = 0;
boolean error;

void setup()
{
  Serial.begin(9600);

  pinMode(HARDWARE_RESET,OUTPUT);

  digitalWrite(HARDWARE_RESET, HIGH);

  Serial.println(F("BMP280 test"));

  if (!bme.begin()) {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }

  EspSerial.begin(9600); // Comunicacao com Modulo WiFi
  EspHardwareReset(); //Reset do Modulo WiFi
  startWriteTiming = millis(); // starting the "program clock"


}

void loop()
{

  start: //label 
  error=0;

  elapsedWriteTime = millis()-startWriteTiming; 

  if (elapsedWriteTime > (writeTimingSeconds*1000)) 
  {
    readSensors();
    writeThingSpeak();
    startWriteTiming = millis();   
  }

  if (error==1) //Resend if transmission is not completed 
  {       
    Serial.println(" <<<< ERROR >>>>");
    delay (2000);  
    goto start; //go to label "start"
  }
}

/********* Read Sensors value *************/
void readSensors(void)
{
  temperature = bme.readTemperature();
  pressure = bme.readPressure();
  altitude = bme.readAltitude(1013.25);

}

/********* Conexao com TCP com Thingspeak *******/
void writeThingSpeak(void)
{

  startThingSpeakCmd();

  String getStr = "GET /update?api_key=";
  getStr += statusChWriteKey;
  getStr +="&field1=";
  getStr += String(temperature);
  getStr +="&field2=";
  getStr += String(pressure);
  getStr +="&field3=";
  getStr += String(altitude);
  getStr +="&field4=";
  getStr += String(spare);
  getStr += "\r\n\r\n";

  sendThingSpeakGetCmd(getStr); 
}

/********* Reset ESP *************/
void EspHardwareReset(void)
{
  Serial.println("Reseting......."); 
  digitalWrite(HARDWARE_RESET, LOW); 
  delay(500);
  digitalWrite(HARDWARE_RESET, HIGH);
  delay(8000);//Tempo necessário para começar a ler 
  Serial.println("RESET"); 
}

/********* Start communication with ThingSpeak*************/
void startThingSpeakCmd(void)
{
  EspSerial.flush();//limpa o buffer antes de começar a gravar

  String cmd = "AT+CIPSTART=\"TCP\",\"";
  cmd += "184.106.153.149"; // Endereco IP de api.thingspeak.com
  cmd += "\",80";
  EspSerial.println(cmd);
  Serial.print("sent ==> Start cmd: ");
  Serial.println(cmd);

  if(EspSerial.find("Error"))
  {
    Serial.println("AT+CIPSTART error");
    return;
  }
}

/********* send a GET cmd to ThingSpeak *************/
String sendThingSpeakGetCmd(String getStr)
{
  String cmd = "AT+CIPSEND=";
  cmd += String(getStr.length());
  EspSerial.println(cmd);
  Serial.print("sent ==> lenght cmd: ");
  Serial.println(cmd);

  if(EspSerial.find((char *)">"))
  {
    EspSerial.print(getStr);
    Serial.print("sent ==> getStr: ");
    Serial.println(getStr);
    delay(500);//tempo para processar o GET, sem este delay apresenta busy no próximo comando

    String messageBody = "";
    while (EspSerial.available()) 
    {
      String line = EspSerial.readStringUntil('\n');
      if (line.length() == 1) 
      { //actual content starts after empty line (that has length 1)
        messageBody = EspSerial.readStringUntil('\n');
      }
    }
    Serial.print("MessageBody received: ");
    Serial.println(messageBody);
    return messageBody;
  }
  else
  {
    EspSerial.println("AT+CIPCLOSE");     // alert user
    Serial.println("ESP8266 CIPSEND ERROR: RESENDING"); //Resend...
    spare = spare + 1;
    error=1;
    return "error";
  } 
}
  • the data sheet says that it reports the value in hPa (hectopascal) ...... note: i just checked wunderground.com and it reports the atmospheric pressure in my area to be 950.9 hPa (which is 95090 Pa) – jsotola Jun 24 '18 at 18:21
  • to start, test the sensor by removing all the code that has nothing to do with reading the sensor and print out the raw reading from the sensor – jsotola Jun 24 '18 at 18:24
  • i have done that, loaded the basig example sketch onto the uno that comes with the BMP280 lib, with out any convesion it outputs the measured data, and it gives values inbetween 34.000 and 35.000. so it is not a wiring issue i believe, but suspect a faulty chip – mee Jun 26 '18 at 4:41
1

It appears that you might be looking at a field 3 in Thingspeak instead of field 2...Here is why:

Do you live at a low elevation? Here is why I ask that question.

This statement:

pressure = bmp.readPressure();

returns the pressure in pascals (sea level is 101325 pascals) from the BMP280 and assigns it to the variable pressure.

To get pressure in mb you would divide by 100 (a mb is = to 1 hPa or 100 Pascals). If you were expecting a value of 100 (kPa?) perhaps that means you would be living near sea level.. perhaps about 100 feet (35m) or so.

If that is the case then the statement:

altitude = bmp.readAltitude(1013.25);

which ultimately feeds the Thingspeak field 3 the calculated altitude in meters (in this case about 35 meters). Check and make sure you are looking at Thingspeak field 2 and not field 3 for pressure readings.

If you want to see pressure in mb change the line that reads pressure from the BME280 to the following:

pressure = bmp.readPressure()/100;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.