BME280 Sensor and Particle photon

Can anyone direct me to a SIMPLE tutorial to do this?

I have spent more than enough time on it with no actionable results and am pretty demotivated by this makerspace stuff.

I have the sensor working fine, but if you toss in a bunch of new additions to the firmware to get it into blynk for me straight off the bat, I can tell you it is gonna throw me for a loop.

Is their any solution that does not require me to alter ANY VARIABLE or function of my firmware?

With BME280 sensor? I think - no.

Well then why is this advertised as plug and play?

If my particle published events have to be altered.

/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO,  BME_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BME280 test"));

  if (!bme.begin()) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}

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);
}

I would really love to see the ease of all these software libraries and apps, but I am not seeing it

First person to help without SNARK gets $20 in Bitcoin tipped to their wallet.

Cause that’s true for some projects. However hardware is very different. All of it has it’s own libraries, drivers, bugs and problems and every hardware works in different way. We are working on to make it even more easier.

Have you tried googling? I just copied the name of this topic…

This is the first link I get: https://community.particle.io/t/adafruit-bme280-library-ported/15826

So now you need to connect this and Blynk… and it’s almost plug and play

Looks like you just earned yourself $20 haha

Considering my question was to “visualize” the data your answer amounts to the snark I’ve received in this venture since starting it in a nutshell.

Good luck with your app!

I’m sure alot more than that eventually from someone with more money than sense, but no sadly he earned zero becsuse his reading comprehension is about equal.

I think the issue is your hardware.
buy yourself a NodeMCU variant of the ESP8266 and you won’t have these problems.
I’ve heard only bad things from people who have purchased Photon products.

And I just ordered a BME280 sensor and will be happy to share any info I gather along the way.

ive been using multiple BME280’s for a while, they work fine with Blynk.

if @Cloud could articulate the issue more coherently, perhaps i could offer some assistance?

am i missing something?

**snark**
snɑːk
_noun_
an imaginary animal (used typically with reference to a task or goal that is elusive or impossible to achieve).

wft is SNARK?

Also confused here…

@Cloud I tried to use the Adafruit library with the BME280 sensor but had no luck. Somehow I had a timing problem which I gave up on. I switched to the CE_BME280.h library and it worked perfectly with their sample code example. I am using it to get environment variables back to my Blynk app. The simple code I am using can be seen here: http://pastebin.com/iK2R8Md6
There may be a few extra variables in the code which are not needed but you can delete them.

1 Like

I think you are having problems getting this working because you are not explaining yourself very well. Prior to this comment where did you make reference to “visualize” and what does the term mean in plain English?

Have you looked through the details in the link provided by @Pavel? It is certainly something I would study if I had your problem.

Can you “see” the data from the sensor anywhere? If yes, I’ll guide you on how to get it to Blynk for $0.00

Yes, I see the correct json data in the particle dashboard, my problem is visualizing the data, getting it out and usable anywhere.

too broad, narrow it down a bit.

Let’s put it differently, can you print out sensor data to serial monitor?

Also, share your full code that you flash to photon

I am using that firmware with this .ino

// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// BME280
// This code is designed to work with the BME280_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Humidity?sku=BME280_I2CS#tabs-0-product_tabset-2

#include <application.h>
#include <spark_wiring_i2c.h>


// BME280 I2C address is 0x76(108)
#define Addr 0x77

double cTemp = 0, fTemp = 0, pressure = 0, humidity = 0;
void setup()
{
    // Set variable
    Particle.variable("i2cdevice", "BME280");
    Particle.variable("cTemp", cTemp);
    Particle.variable("fTemp", fTemp);
    Particle.variable("pressure", pressure);
    Particle.variable("humidity", humidity);

    // Initialise I2C communication as MASTER
    Wire.begin();
    // Initialise Serial communication, set baud rate = 9600
    Serial.begin(9600);
    delay(300);
}

void loop()
{
    unsigned int b1[24];
    unsigned int data[8];
    int dig_H1 = 0;
    for(int i = 0; i < 24; i++)
    {
        // Start I2C Transmission
        Wire.beginTransmission(Addr);
        // Select data register
        Wire.write((136+i));
        // Stop I2C Transmission
        Wire.endTransmission();

        // Request 1 byte of data
        Wire.requestFrom(Addr, 1);

        // Read 24 bytes of data
        if(Wire.available() == 1)
        {
        b1[i] = Wire.read();
        }
    }

    // Convert the data
    // temp coefficents
    int dig_T1 = (b1[0] & 0xff) + ((b1[1] & 0xff) * 256);
    int dig_T2 = b1[2] + (b1[3] * 256);
    int dig_T3 = b1[4] + (b1[5] * 256);

    // pressure coefficents
    int dig_P1 = (b1[6] & 0xff) + ((b1[7] & 0xff ) * 256);
    int dig_P2 = b1[8] + (b1[9] * 256);
    int dig_P3 = b1[10] + (b1[11] * 256);
    int dig_P4 = b1[12] + (b1[13] * 256);
    int dig_P5 = b1[14] + (b1[15] * 256);
    int dig_P6 = b1[16] + (b1[17] * 256);
    int dig_P7 = b1[18] + (b1[19] * 256);
    int dig_P8 = b1[20] + (b1[21] * 256);
    int dig_P9 = b1[22] + (b1[23] * 256);

    for(int i = 0; i < 7; i++)
    {
        // Start I2C Transmission
        Wire.beginTransmission(Addr);
        // Select data register
        Wire.write((225+i));
        // Stop I2C Transmission
        Wire.endTransmission();

        // Request 1 byte of data
        Wire.requestFrom(Addr, 1);

        // Read 7 bytes of data
        if(Wire.available() == 1)
        {
            b1[i] = Wire.read();
        }
    }

    // Convert the data
    // humidity coefficents
    int dig_H2 = b1[0] + (b1[1] * 256);
    int dig_H3 = b1[2] & 0xFF ;
    int dig_H4 = (b1[3] * 16) + (b1[4] & 0xF);
    int dig_H5 = (b1[4] / 16) + (b1[5] * 16);
    int dig_H6 = b1[6];

    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select data register
    Wire.write(161);
    // Stop I2C Transmission
    Wire.endTransmission();

    // Request 1 byte of data
    Wire.requestFrom(Addr, 1);

    // Read 1 byte of data
    if(Wire.available() == 1)
    {
        dig_H1 = Wire.read();
    }

    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select control humidity register
    Wire.write(0xF2);
    // Humidity over sampling rate = 1
    Wire.write(0x01);
    // Stop I2C Transmission
    Wire.endTransmission();

    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select control measurement register
    Wire.write(0xF4);
    // Normal mode, temp and pressure over sampling rate = 1
    Wire.write(0x27);
    // Stop I2C Transmission
    Wire.endTransmission();

    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select config register
    Wire.write(0xF5);
    // Stand_by time = 1000ms
    Wire.write(0xA0);
    // Stop I2C Transmission
    Wire.endTransmission();

    for(int i = 0; i < 8; i++)
    {
        // Start I2C Transmission
        Wire.beginTransmission(Addr);
        // Select data register
        Wire.write((247+i));
        // Stop I2C Transmission
        Wire.endTransmission();

        // Request 1 byte of data
        Wire.requestFrom(Addr, 1);

        // Read 8 bytes of data
        if(Wire.available() == 1)
        {
            data[i] = Wire.read();
        }
    }

    // Convert pressure and temperature data to 19-bits
    long adc_p = (((long)(data[0] & 0xFF) * 65536) + ((long)(data[1] & 0xFF) * 256) + (long)(data[2] & 0xF0)) / 16;
    long adc_t = (((long)(data[3] & 0xFF) * 65536) + ((long)(data[4] & 0xFF) * 256) + (long)(data[5] & 0xF0)) / 16;
    // Convert the humidity data
    long adc_h = ((long)(data[6] & 0xFF) * 256 + (long)(data[7] & 0xFF));

    // Temperature offset calculations
    double var1 = (((double)adc_t) / 16384.0 - ((double)dig_T1) / 1024.0) * ((double)dig_T2);
    double var2 = ((((double)adc_t) / 131072.0 - ((double)dig_T1) / 8192.0) *
    (((double)adc_t)/131072.0 - ((double)dig_T1)/8192.0)) * ((double)dig_T3);
    double t_fine = (long)(var1 + var2);
    double cTemp = (var1 + var2) / 5120.0;
    double fTemp = cTemp * 1.8 + 32;

    // Pressure offset calculations
    var1 = ((double)t_fine / 2.0) - 64000.0;
    var2 = var1 * var1 * ((double)dig_P6) / 32768.0;
    var2 = var2 + var1 * ((double)dig_P5) * 2.0;
    var2 = (var2 / 4.0) + (((double)dig_P4) * 65536.0);
    var1 = (((double) dig_P3) * var1 * var1 / 524288.0 + ((double) dig_P2) * var1) / 524288.0;
    var1 = (1.0 + var1 / 32768.0) * ((double)dig_P1);
    double p = 1048576.0 - (double)adc_p;
    p = (p - (var2 / 4096.0)) * 6250.0 / var1;
    var1 = ((double) dig_P9) * p * p / 2147483648.0;
    var2 = p * ((double) dig_P8) / 32768.0;
    double pressure = (p + (var1 + var2 + ((double)dig_P7)) / 16.0) / 100 ;

    // Humidity offset calculations
    double var_H = (((double)t_fine) - 76800.0);
    var_H = (adc_h - (dig_H4 * 64.0 + dig_H5 / 16384.0 * var_H)) * (dig_H2 / 65536.0 * (1.0 + dig_H6 / 67108864.0 * var_H * (1.0 + dig_H3 / 67108864.0 * var_H)));
    double humidity = var_H * (1.0 -  dig_H1 * var_H / 524288.0);
    if(humidity > 100.0)
    {
        humidity = 100.0;
    }
    else if(humidity < 0.0)
    {
        humidity = 0.0;
    }

    // Output data to dashboard
    Particle.publish("Temperature in Celsius : ", String(cTemp));
    Particle.publish("Temperature in Fahrenheit : ", String(fTemp));
    Particle.publish("Pressure : ", String(pressure));
    Particle.publish("Relative Humidity : ", String(humidity));
    delay(10000);
}

Is this code working for you? It’s compiling and you can see the temperature and humidity in the serial monitor, right?