B4R Library rAdafruitBMP280 - BMP280 temperature & pressure sensor

This is a wrapper for Adafruit BMP280 library: https://github.com/adafruit/Adafruit_BMP280_Library

Usage example:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private bmp As Adafruit_BMP280
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If bmp.Initialize Then
     Log("Successful")
     Log(bmp.ReadAltitude(1013.25))
     Log(bmp.ReadPressure)
     Log(bmp.ReadTemperature)
   Else
     Log("sensor not found!")
   End If
End Sub
 

Attachments

  • rAdafruitBMP280.zip
    7.6 KB · Views: 797

positrom2

Active Member
Licensed User
Longtime User
Thank you very very much. That was fast. Can't follow the posts here with that speed.
 

rbghongade

Active Member
Licensed User
Longtime User
Thank you Erel for this library, but the device does not get initialized, I am using the above mentioned code and library!
 

positrom2

Active Member
Licensed User
Longtime User
For BMP280 on esp8266-01 change in Adafruit_BMP280.cpp:
Wire.begin() to
Wire.begin(2,0); // GPIO2, GPIOO
and connect SCK to GPIO0, SDI to GPIO02.
 

positrom2

Active Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private bmp As Adafruit_BMP280
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If bmp.Initialize Then
       Do While 2=2  '<---------------------  Erel likes that ;)
     Log("Successful")
     Log(bmp.ReadAltitude(1013.25))
     Log(bmp.ReadPressure)
     Log(bmp.ReadTemperature)
     Delay(10000)
     Loop
   Else
     Log("sensor not found!")
   End If
End Sub

Successful
-95.0747
102472.1719
20.7300
 

derez

Expert
Licensed User
Longtime User
I need help to connect this BMP to Arduino UNO.
I tried both ways - connecting SDL and SDA only, connecting 4 pins : 10 to CSB, 11 to SDA , 12 to SD0, 13 to SCL
It does not work, also with Arduino's sketch.
What am I doing wrong ? or the board is faulty...
 

Attachments

  • IMG_20170121_200902.jpg
    IMG_20170121_200902.jpg
    119 KB · Views: 563

derez

Expert
Licensed User
Longtime User
I have found something more interesting to play with so it will wait for a while.
I have checked both cases in the link but maybe I should try it again.
Thank you !
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Have taken the library as in post #1 as wanted make some changes.
Befor doing so, tested if can build the lib from post #1 as-is using the tool b4rh2xml.
BUT receiving error:
B4X:
c:\Daten\b4\b4r\libraries\rAdafruitBMP280>java -jar c:\Daten\b4\b4r\tools\B4Rh2xml\B4Rh2xml.jar Adafruit_BMP280.h ../Adafruit_BMP280.xml
Error parsing: Adafruit_BMP280();
parser._parsemethod (java line: 527)
java.lang.NumberFormatException: For input string: "error"
        at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
        at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
        at java.lang.Double.parseDouble(Unknown Source)
        at b4j.example.parser._parsemethod(parser.java:527)
        at b4j.example.parser._parseline(parser.java:464)
        at b4j.example.parser._parseh(parser.java:422)
        at b4j.example.parser._parse(parser.java:267)
        at b4j.example.main._appstart(main.java:46)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
        at b4j.example.main.main(main.java:29)
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Thanks = How could I overlook that :(.

The reason why making amendments to this library, is that I received a BMP280 from another manufacturer then Adafruit.
The BMP280 worked, I2C connected, with this (very nice) I2C library.
Looked up the sources from both libraries and ... as expected, the only difference was the device I2C address.
Changed the address in the Adafruit_BMP280 library to the one from the I2C library and ... the device worked.

Attached the updated library rAdafruitBMP280:
B4X:
//Initializes the sensor with given address (as int). Returns True if successful.
bool Initialize2(Int addr);

and I2C example attached with output:
B4X:
BMP280 successful initialized
T:20.61, P:1030.80, A:-7
T:20.61, P:1030.81, A:-7
T:20.62, P:1030.84, A:-7
 

Attachments

  • rAdafruitBMP280-1.0.1.zip
    7.8 KB · Views: 679
  • b4rhowtobmp280.zip
    997 bytes · Views: 553

rwblinn

Well-Known Member
Licensed User
Longtime User
BMP280 used:
upload_2017-1-26_11-42-56.png


To help, just scribbled an i2cscanner - check if the device address can be found --- you might need to unplug / plugin the device and scan again if not found first time.
 

Attachments

  • b4rhowtoi2cscanner.zip
    1.5 KB · Views: 509
Top