B4R Question (Solved)Unable to interface BMP280 sensor to ESP8266...

rbghongade

Active Member
Licensed User
Longtime User
Dear friends,
I tried the following code to interface BMP280 (improved version of BMP180) with Wemos (ESP8266) but am unsuccessful. The attached library for arduino with a sketch works ok.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Public TEMPERATURE, PRESSURE As Double
    Private Timer1 As Timer
  
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
   RunNative("setup",Null)
  
  
    Timer1.Initialize("Timer1_Tick", 500)
    Timer1.Enabled = True
End Sub


Private Sub Timer1_Tick
 
    RunNative("read",Null)
    Log(TEMPERATURE)
    Log(PRESSURE)
End Sub

#if C
#include "BMP280.h"
#include "Wire.h"
#define P0 1013.25
BMP280 bmp;

void setup(B4R::Object* o){
bmp.setOversampling(4);
}
  
void read (B4R::Object* o) {
   char result = bmp.startMeasurment();
    result=bmp.getTemperatureAndPressure(b4r_main::_temperature,b4r_main::_pressure);
}

#End if

Please help.
 

Attachments

  • BMP280-Arduino-Library-master.zip
    7.9 KB · Views: 286

rbghongade

Active Member
Licensed User
Longtime User
Sorry, here is the error log:
B4X:
B4R version: 1.50 BETA #1
Parsing code.    (0.00s)
Compiling code.    (0.01s)
Building project    (0.02s)
Compiling & deploying Ino project (WeMos D1 R2 & mini - COM25)    Error

sketch\b4r_main.cpp: In function 'void read(B4R::Object*)':
b4r_main.cpp:26: error: no matching function for call to 'BMP280::getTemperatureAndPressure(Double&, Double&)'
      result=bmp.getTemperatureAndPressure(b4r_main::_temperature,b4r_main::_pressure);
                                                                                     ^
sketch\b4r_main.cpp:26:85: note: candidate is:
In file included from sketch\b4r_main.cpp:12:0:
C:\Users\RAJESH\Documents\Arduino\libraries\BMP280_Arduino_Library/BMP280.h:74:8: note: char BMP280::getTemperatureAndPressure(double&, double&)
   char getTemperatureAndPressure(double& T,double& P);
        ^
C:\Users\RAJESH\Documents\Arduino\libraries\BMP280_Arduino_Library/BMP280.h:74:8: note:   no known conversion for argument 1 from 'Double {aka float}' to 'double&'
exit status 1
no matching function for call to 'BMP280::getTemperatureAndPressure(Double&, Double&)'
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Tried this inline code, but am getting wrong values:
B4X:
#if C
#include "BMP280.h"
#include "Wire.h"
#define P0 1013.25
BMP280 bmp;

void setup(B4R::Object* o){
bmp.setOversampling(4);
 
}
   
void read (B4R::Object* o) {
    double T,P;
  char result = bmp.startMeasurment();
  delay(100);
     result=bmp.getTemperatureAndPressure(T,P);
    b4r_main::_temperature=T;
    b4r_main::_pressure=P;
    double A = bmp.altitude(P,P0);
    b4r_main::_altitude=A;
}

#End if


Output:
B4X:
Temperature:nan
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
Temperature:1.9332
Pressure:0
Altitude:44330
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Dear Erel,
Tried the following inline modification but getting all '0' values.
B4X:
#if C
#include "BMP280.h"
#include "Wire.h"
#define P0 1013.25
BMP280 bmp;

void setup(B4R::Object* o){
bmp.setOversampling(4);
 
}
   
void read (B4R::Object* o) {
    double T,P;
  char result = bmp.startMeasurment();
  if (result != 0) {
delay(result);
result = bmp.getTemperatureAndPressure(T,P);
if (result != 0) {
   delay(result);
  
b4r_main::_temperature=T;
b4r_main::_pressure=P;
double A = bmp.altitude(P,P0);
b4r_main::_altitude=A;
}
}
}

#End if

output:
B4X:
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
Temperature:0
Pressure:0
Altitude:0
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Dear Erel,
Found the problem! Forgot to add
bmp.begin(); in setup!
Sooo stupid of me!
Now working great! Thanks
 
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
rbghongade,
Could you post the final library for the BMP280?
I tried to create the library following the tutorial but I get the error
"No shortname for class: ::BMP280"
 
Last edited:
Upvote 0
Top