B4R Question Wrapping Library for BMP180 sensor

rwblinn

Well-Known Member
Licensed User
Hi,

still struggling how to wrap an Arduino Library. So many variations around ... means would be great (just) to import in B4R without wrapping.

One of the B4R HowTo Experiments working upon, is a mini weather station.
Temperature + Humidity
The DHT11 sensor is now working fine (with wrapped library rDHT11 based on DHT11 lib).

Airpressure
Next is the BMP180 sensor with library SFE_BMP180 to be wrapped as rBMP180.
... but (again) :( got stuck in how to wrap a base type SFE_BMP180 as defined in the SFE_BMP180.h.
The methods like begin() etc. seems straight forward to convert.
B4X:
class SFE_BMP180
{
    public:
        SFE_BMP180(); // base type
    char begin();
       // call pressure.begin() to initialize BMP180 before use
       // returns 1 if success, 0 if failure (bad component or I2C bus shorted?)
Any help appreciated.
 

Attachments

Erel

Administrator
Staff member
Licensed User
It is a constructor with no arguments. You don't need to wrap it.
 

Erel

Administrator
Staff member
Licensed User
It was not a simple library to wrap. Please try version 1.00.
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private sfe As SFE_BMP180
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   Log("Initialize: ", sfe.Initialize)
   If sfe.GetTemperature Then
     Log("Temperature: ", sfe.LastResult)
   End If
End Sub
 

Attachments

rwblinn

Well-Known Member
Licensed User
Thanks a lot - this is really great - will revert back by cob tomorrow.
 

rwblinn

Well-Known Member
Licensed User
Hi,

confirmed working fine - again many thanks for fantastic support = will write up a B4R BMP180 tutorial.
B4X:
Sub Process_Globals
    Public Serial1 As Serial
    Private bmp180 As SFE_BMP180
    Private Temperature, Pressure, PressureSeaLevel, Altitude As Double
    Private ALTITUDEHAMBURG As Double = 27.0    'in meters
    Private Timer1 As Timer
End Sub

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

Private Sub Timer1_Tick
    If Not(bmp180.GetTemperature) Then
        Log("Error retrieving the temperature.")
        Return
    End If
    Temperature = bmp180.LastResult
    bmp180.GetPressure(0, Temperature)
    Pressure = bmp180.LastResult
    Log("Pressure [mBar]:", Pressure)
    PressureSeaLevel = bmp180.Sealevel(Pressure, ALTITUDEHAMBURG)
    Log("PressureSeaLevel [mBar]:",PressureSeaLevel)   
    Altitude = bmp180.Altitude(Pressure, PressureSeaLevel)
    Log("Altitude [m]:", Altitude)
    Log("---")
End Sub
with output
B4X:
AppStart
Temperature [C]:22.6287
Pressure [mBar]:1017.1806
PressureSeaLevel [mBar]:1020.4424
Altitude [m]:27.0014
---
Temperature [C]:22.6045
Pressure [mBar]:1017.1388
PressureSeaLevel [mBar]:1020.4004
Altitude [m]:27.0014
---
 

monki

Active Member
Licensed User
Hello,
I have a problem with the SFE_BMP180 libary.
it works fine on a uno board, on a Wemos d1 Board it delivers wrong values.
Is there a solution ?

monki
 
Last edited:

Erel

Administrator
Staff member
Licensed User
I've ordered a sensor. It will take several weeks for it to arrive. I will then check it...
 
Top