last week I got my first Photon and I wanted it to hook up with the (relatively new) Adafruit BME280 humidity, barometric pressure & temp sensor. Since I could not found any library working with Photon in combination with the BME280 sensor I stated looking into the Arduino Adafruit BME280 library. I ported that library to make it work with the Photon.
I tested it with a the Adafruit BME280 and the Watterott BME280 (available in Germany) sensors. Both are working great. Other BME280 breakouts might work as well.
All wiring options supported by the sensor (I2C & SPI) are working with that library. For using theses see the sample app, I2C is used by default the others are commented out in the sample code. I ported the Adafruit library because it has the most flexibility in therms or wiring. If you Google you find other libraries for the BME280 sensor but most of them only support I2C protocol.
just for the fun and because it utilizes some more features of the BME280 sensor I ported the Sparkfun BME280 library as well. It is designed for the Sparkfun BME280 breakout. Since I do not have these I used the Adafruit BME280 which works as well. The library is all read available at the Particle Build Web IDE.
Nice! Just got a board back the other day with a Photon hooked to a 280, and have been looking over the SF library. Will be sure to check it out. Thanks.
And since the address isnât actually stored by the constructor but by bool Adafruit_BME280::begin(uint8_t addr = BME280_ADDRESS) you wouldnât even need to #define an alternative address but only pass it instead of the default value.
Adafruit's library uses (coincidentally) the address for the device they sell.
For me, I'm downloading libraries into project files (I prefer to leave the dependancies static lest someone break its backward compatibility on a published library). Very seldom do I use Build. I was thinking about a newbie that won't know that there may be (somewhere on God's green earth) a BME280 device on another I2C address.
IMHO, with the new library 'system' and for the person simply adding in a library to their project using Build 1) having an awareness of the I2C address dependency and 2) a way to simply pass it in a constructor is beneficial. In Build, it is possible to add a library, create a program and not even see the library behind the scenes.
Even a note in the example header would be friendlier. Again this was just thoughtful consideration... not a selfish desire on my part!
IMHO it is easy to understand the I2C address dependency by looking at the header file of the library.
As written above there are strictly speaking two option of using an alternate I2C address (defining BME280_ADDRESS or passing the address via the begin method like bme.begin(0x76)).
Iâm still not a friend of changing the original library to stay as much as compatible with the Arduino library.
But I enhanced the sample with some notes and an out commented sample in the code. Additionally I added a hint to the README.md. HTH.
You could add a default/optional parameter to the constructor or have a dedicated overload that features that extra parameter.
This way you would still be 100% compatible to âlegacyâ code but also cater for the extra wishes.
But I agree that the already available means should suffice.
Otherwise we could even argue that weâd need more functions (e.g. uint8_t setAddress(uint8_t addr), uint8_t getAddress()) to satisfy the personal preferences of people whoâd rather want to deal with the device addresses that way.
Good day sir.
Firstly thank you for porting the library, it definitely makes interfacing the sensor with the microcontroller easier.
I am new to particle and a newbie in programming microcontrollers. I have worked with the arduino uno on a few basic projects but nothing that involved I2C or SPI connections.
I need some help. Could you please direct me to a link that shows the wiring diagram you used to connect the BME280 to the particle photon for the code found in the BME adafruit library. Also i downloaded the BME280 Adafruit library but i was not able to figure out which lines of the code applied to the SPI configuration in the Void loop. This is the code i am referring to:
@Alli
In loop() you are calling/using the methods for the object bme e.g. bme.readTemperature() returns the temperature. You have instantiated the object with Adafruit_BME280 bme(BME_CS); // hardware SPI. In this case the instance has been created for Arduino and is using the standard SPI pins. To make this work for Particle Photon - you will need to define the hardware SPI pins used on the photon (refer photon datasheets) A5 - SPI MOSI, A4 - SPI MISO, A3 - SPI SCK, A2 - SPI SS/CS. You will need to wire the module pins to these pins on the photon. I suggest you use the bme280test.ino example rather than the advancedsettings.ino and set the #define BME_CS A2 and use the hardware SPI instantiation as in the example you have posted.
Thank you for your response.
Im using the particle dev to program the controller i have made the changed you suggested and in fact i started a new project this is my code: #include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h>
but whenever i attempt to compile the program it keeps returning an error: Adafruit_Sensor.h:No such file directory. I commented it out than the it brings up the same error for the BME280.h. I can seem to figure out why.
I downloaded the Adafruit BME280 library from github and saved it in my program folder: It is in the same directory as the SRC folder. Can you please tell me what im doing wrong
I am not sure what happened but my photon is breathing green which means its unable to connect to the cloud inspite of the fact that its connected to wifi. i have been sitting with this problem for 2 hours after trying to upload the following code to the photon:
@armor
i finally found something useful on another thread.
I used the command prompt to flash the original tinker app onto the photon. The code above is not allowing the photon to connect to the cloud. I then tried uploading the same code as above with the exception of the while loop (which i commented out) but the photon is still going green and nothing appears on the serial monitor.
Also i donât see how the pins we ascribed in this part of the code:
is associated with the rest of the code. The rest of the program does not mention these variables. I uploaded this code Do i need to add additional code to the example above to make it work?
@armor
For some reason now, after what appears to be successfully adding the adafruit bme sensor library to the project the program is returning 63 errors when compiled using the same code above. I am really not sure what is going on.
@armor@ScruffR@mhdevx
i do not mean to burden only armor with my challenges. I would greatly appreciate assistance from any anyone who is willing to assist.
Here is the image showing some of the errors that are being returned.
Create a new app - call it BME280test and save.
Click on the libraries icon, search BME280 and select the Adafruit_BME280 library.
Add library to project, confirm app.
You should now see code with the #include <Adafruit_BME280.h> at the top.
Click on the code icon and then on the library to open the files and then click on the bme280test.ino example. Copy this into your app/project.
This is what I end up with, have removed #include âAdafruit_sensors.hâ as this is already in the other header.
#include <Adafruit_BME280.h>
SYSTEM_MODE(MANUAL); //at this stage no WiFi or Cloud connection is required
#define BME_CS A2 //SPI CS pin
#define SEALEVELPRESSURE_HPA (1013.25) //constant for altitude calculation
Adafruit_BME280 bme(BME_CS); //instantiate object hardware SPI
void setup()
{
Serial.begin(9600);
Serial.println("BME280 test");
if (!bme.begin()) {Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1);} //bme object could not be initialised
}
// Check and print values and wait/delay for 2 seconds
void loop()
{
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
delay(2000);
}
This compiled but I havenât flashed it to a device. Once you do that the device will go offline because of the SYSTEM_MODE(MANUAL);
The above code compiled in the web ide will try to flash it to my photon later today, thank you again.
But how did you end up with the code you showed above?
Since you added this code to the project
SYSTEM_MODE(MANUAL);
do i need to remove it before i flash the code to the project?
Also why did you remove the following: #define BME_SCK #define BME_MISO #define BME_MOSI