B4R Code Snippet BME280 with ESP8266 (Wemos mini)...

I was able to interface the Bosch BME 280 sensor with ESP8266 via inline C code and the Arduino library attached herewith:
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Public TEMPERATURE, PRESSURE,HUMIDITY As Double
    Private Timer1 As Timer
   
End Sub

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


Private Sub Timer1_Tick
  
    RunNative("read",Null)
   
    Log("Temperature:",NumberFormat(TEMPERATURE,1,1))
    Log("Pressure:",NumberFormat(PRESSURE,1,2))
    Log("Humidity:",NumberFormat(HUMIDITY,1,2))
   
End Sub



#if C
#include <Wire.h>
#include "cactus_io_BME280_I2C.h"
BME280_I2C bme(0x76);

void setup(B4R::Object* o){
bme.begin();
  bme.setTempCal(-1);
}
  
void read (B4R::Object* o) {
   
  bme.readSensor();
 
  
   
    b4r_main::_temperature=bme.getTemperature_C();
    b4r_main::_pressure=bme.getPressure_MB();
    b4r_main::_humidity=bme.getHumidity();
}

#End if

Hope this helps someone.
 

Attachments

  • cactus_io_BME280_I2C.zip
    5.1 KB · Views: 581
Top