I cannot get a reading with my code. I have the SCK on the 688 connected to the SCL on the boron and the SDI to SDA. Do I need to add some pullup resistors?
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_BME680.h>
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
double temperatureInC = 0;
double relativeHumidity = 0;
double pressureHpa = 0;
double gasResistanceKOhms = 0;
double approxAltitudeInM = 0;
void setup() {
if (!bme.begin(0x76)) {
Particle.publish("Log", "Could not find a valid BME680 sensor, check wiring!");
} else {
Particle.publish("Log", "bme.begin() success =)");
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
Particle.variable("temperature", temperatureInC);
Particle.variable("humidity", relativeHumidity);
Particle.variable("pressure", pressureHpa);
Particle.variable("gas", gasResistanceKOhms);
Particle.variable("altitude", approxAltitudeInM);
}
}
void loop() {
if (! bme.performReading()) {
Particle.publish("Log", "Failed to perform reading :(");
} else {
temperatureInC = bme.temperature;
relativeHumidity = bme.humidity;
pressureHpa = bme.pressure / 100.0;
gasResistanceKOhms = bme.gas_resistance / 1000.0;
approxAltitudeInM = bme.readAltitude(SEALEVELPRESSURE_HPA);
String data = String::format(
"{"
"\"temperatureInC\":%.2f,"
"\"humidityPercentage\":%.2f,"
"\"pressureHpa\":%.2f,"
"\"gasResistanceKOhms\":%.2f,"
"\"approxAltitudeInM\":%.2f,"
"\"key\":\"%s\""
"}",
temperatureInC,
relativeHumidity,
pressureHpa,
gasResistanceKOhms,
approxAltitudeInM);
Particle.publish("Sensor", data, 60, PRIVATE, NO_ACK);
}
delay(60000);
}
I would try running an I2C scanner to see if any device can be seen.
I think the default is 0x77, not 0x76.
By default, the i2c address is 0x77. If you add a jumper from SDO to GND, the address will change to 0x76.
dalepa
November 29, 2021, 7:55pm
3
This worked on my BME680 and BME688. Had to flip the SLC/SDA wires, won’t work if backwards
//BME680
/*
* Project BME680
* Description:
* Author:
* Date:
*/
#if defined(__AVR__) || defined(ESP8266)
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (WHITE wire)
// Set up the serial port to use softwareserial..
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, -1);
#else
// On Leonardo/M0/etc, others with hardware serial, use hardware serial!
// #0 is white wire, data input
#define mySerial Serial1
#endif
String myID;
//BME680
#include "Adafruit_BME680.h"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1022.25)
Adafruit_BME680 bme; // I2C
double temperatureInC = 0;
double relativeHumidity = 0;
double pressureHpa = 0;
double gasResistanceKOhms = 0;
double approxAltitudeInM = 0;
int led = D7;
void setup() {
Particle.publish("hello", "world");
Serial.println("Hello World " + myID);
Serial.begin(115200);
while (!Serial) {
delay(10); // wait for serial port to connect. Needed for native USB port only
}
myID = System.deviceID();
if (!bme.begin())
{
Particle.publish("Log", "Could not find a valid BME680 sensor, check wiring!");
}
else
{
Particle.publish("Log", "bme.begin() ID=" + myID);
Serial.println("BME SUCCESS");
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
Particle.variable("temperature", &temperatureInC, DOUBLE);
Particle.variable("humidity", &relativeHumidity, DOUBLE);
Particle.variable("pressure", &pressureHpa, DOUBLE);
Particle.variable("gas", &gasResistanceKOhms, DOUBLE);
Particle.variable("altitude", &approxAltitudeInM, DOUBLE);
}
}
void getBME680()
{
if (! bme.performReading())
{
Particle.publish("Log", "Failed to perform reading of BME :(");
Serial.print("Failed to perform reading on BME: ");
}
else
{
temperatureInC = bme.temperature;
relativeHumidity = bme.humidity;
pressureHpa = bme.pressure / 100.0;
gasResistanceKOhms = bme.gas_resistance / 1000.0;
approxAltitudeInM = bme.readAltitude(SEALEVELPRESSURE_HPA);
String data = String::format(
"{"
"\"temperatureInC\":%.2f,"
"\"humidityPercentage\":%.2f,"
"\"pressureHpa\":%.2f,"
"\"gasResistanceKOhms\":%.2f"
"\"approxAltitudeInM\":%.2f"
"}",
temperatureInC,
relativeHumidity,
pressureHpa,
gasResistanceKOhms,
approxAltitudeInM);
}
}
void loop() {
digitalWrite(led,HIGH);
getBME680();
digitalWrite(led,LOW);
delay(1000*30);
}
Got it. I had the wrong address. Thanks @rickkas7
system
Closed
June 1, 2022, 4:20am
5
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.