I am trying to get raw data from the BME688 sensor on a Sparkfun board on the Arduino MRK WiFi 1010 board using Arduino IDE 2.0.3 and I2C protocol. I have installed both BME68x and BSEC2 from GitHub. I am not sure if I actually need BSEC2 if I only need raw data and not iaq.
I can compile and upload the parallel_mode, sequential_mode and forced_mode examples and I get the same error in the Serial monitor:
Sensor error:Communication failure
I guess that the error comes from the code below:
#ifndef PIN_CS
#define PIN_CS SS
#endif
/* initializes the sensor based on SPI library */
bme.begin(PIN_CS, Wire);
I modified the line: " bme.begin(PIN_CS, SPI); " to " bme.begin(PIN_CS, Wire); " such that I2C protocol is used instead of SPI.
The device to device wiring is completely different for the SPI and I2C protocols. Different pins, different number of wires.
In the getting started guides, Sparkfun usually shows the wiring for both options on their modules (if both are available), but of course not for every possible Arduino board.
Also, carefully check the device library you are using to make absolutely sure that this line is correct:
bme.begin(PIN_CS, Wire);
Other libraries use other ways of passing that information, for example, this one is common (note the '&'):
I am pretty sure that the hardware connections for I2C protocol are correct because I have used the Bosch BSEC2 with the basic.ino example and I can get readings. The problem occurs when I use the parallel_mode.ino from the BME68x library.
I searched for "bme.begin" in both BSEC and BME68x libraries folders and it only appears in the parallel_mode, sequential_mode and forced_mode examples, which is odd because I download the latest version of the libraries from GitHub.
I am trying to use the BME688 sensors using Sparkfun breakout boardand BSEC2 library on Arduino IDE 1.8.19 and esp32 pico d4 dev kit with I2C protocol. I followed the instructions on GitHub for the BSEC2 library. I can get the generic_examples > basic.ino to work on MKR Wifi 1010 board but on the esp32 pico d4 dev kit I get the following error when compiling:
undefined reference to `bsec_sensor_control'
collect2: error: ld returned 1 exit status
exit status 1
/**
* Copyright (C) 2021 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
/* If compiling this examples leads to an 'undefined reference error', refer to the README
* at https://github.com/BoschSensortec/Bosch-BSEC2-Library
*/
/* The new sensor needs to be conditioned before the example can work reliably. You may run this
* example for 24hrs to let the sensor stabilize.
*/
/**
* basic.ino sketch :
* This is an example for illustrating the BSEC virtual outputs and
* which has been designed to work with Adafruit ESP8266 Board
*/
#include <bsec2.h>
/* Macros used */
#define PANIC_LED LED_BUILTIN
#define ERROR_DUR 1000
/* Helper functions declarations */
/**
* @brief : This function toggles the led when a fault was detected
*/
void errLeds(void);
/**
* @brief : This function checks the BSEC status, prints the respective error code. Halts in case of error
* @param[in] bsec : Bsec2 class object
*/
void checkBsecStatus(Bsec2 bsec);
/**
* @brief : This function is called by the BSEC library when a new output is available
* @param[in] input : BME68X sensor data before processing
* @param[in] outputs : Processed BSEC BSEC output data
* @param[in] bsec : Instance of BSEC2 calling the callback
*/
void newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec);
/* Create an object of the class Bsec2 */
Bsec2 envSensor;
/* Entry point for the example */
void setup(void)
{
/* Desired subscription list of BSEC2 outputs */
bsecSensor sensorList[] = {
BSEC_OUTPUT_IAQ,
BSEC_OUTPUT_RAW_TEMPERATURE,
BSEC_OUTPUT_RAW_PRESSURE,
BSEC_OUTPUT_RAW_HUMIDITY,
BSEC_OUTPUT_RAW_GAS,
BSEC_OUTPUT_STABILIZATION_STATUS,
BSEC_OUTPUT_RUN_IN_STATUS
};
/* Initialize the communication interfaces */
Serial.begin(115200);
Wire.begin();
pinMode(PANIC_LED, OUTPUT);
/* Valid for boards with USB-COM. Wait until the port is open */
while(!Serial) delay(10);
/* Initialize the library and interfaces */
if (!envSensor.begin(BME68X_I2C_ADDR_LOW, Wire))
{
checkBsecStatus(envSensor);
}
/* Subsribe to the desired BSEC2 outputs */
if (!envSensor.updateSubscription(sensorList, ARRAY_LEN(sensorList), BSEC_SAMPLE_RATE_LP))
{
checkBsecStatus(envSensor);
}
/* Whenever new data is available call the newDataCallback function */
envSensor.attachCallback(newDataCallback);
Serial.println("BSEC library version " + \
String(envSensor.version.major) + "." \
+ String(envSensor.version.minor) + "." \
+ String(envSensor.version.major_bugfix) + "." \
+ String(envSensor.version.minor_bugfix));
}
/* Function that is looped forever */
void loop(void)
{
/* Call the run function often so that the library can
* check if it is time to read new data from the sensor
* and process it.
*/
if (!envSensor.run())
{
checkBsecStatus(envSensor);
}
}
void errLeds(void)
{
while(1)
{
digitalWrite(PANIC_LED, HIGH);
delay(ERROR_DUR);
digitalWrite(PANIC_LED, LOW);
delay(ERROR_DUR);
}
}
void newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec)
{
if (!outputs.nOutputs)
{
return;
}
Serial.println("BSEC outputs:\n\ttimestamp = " + String((int) (outputs.output[0].time_stamp / INT64_C(1000000))));
for (uint8_t i = 0; i < outputs.nOutputs; i++)
{
const bsecData output = outputs.output[i];
switch (output.sensor_id)
{
case BSEC_OUTPUT_IAQ:
Serial.println("\tiaq = " + String(output.signal));
Serial.println("\tiaq accuracy = " + String((int) output.accuracy));
break;
case BSEC_OUTPUT_RAW_TEMPERATURE:
Serial.println("\ttemperature = " + String(output.signal));
break;
case BSEC_OUTPUT_RAW_PRESSURE:
Serial.println("\tpressure = " + String(output.signal));
break;
case BSEC_OUTPUT_RAW_HUMIDITY:
Serial.println("\thumidity = " + String(output.signal));
break;
case BSEC_OUTPUT_RAW_GAS:
Serial.println("\tgas resistance = " + String(output.signal));
break;
case BSEC_OUTPUT_STABILIZATION_STATUS:
Serial.println("\tstabilization status = " + String(output.signal));
break;
case BSEC_OUTPUT_RUN_IN_STATUS:
Serial.println("\trun in status = " + String(output.signal));
break;
default:
break;
}
}
}
void checkBsecStatus(Bsec2 bsec)
{
if (bsec.status < BSEC_OK)
{
Serial.println("BSEC error code : " + String(bsec.status));
errLeds(); /* Halt in case of failure */
}
else if (bsec.status > BSEC_OK)
{
Serial.println("BSEC warning code : " + String(bsec.status));
}
if (bsec.sensor.status < BME68X_OK)
{
Serial.println("BME68X error code : " + String(bsec.sensor.status));
errLeds(); /* Halt in case of failure */
}
else if (bsec.sensor.status > BME68X_OK)
{
Serial.println("BME68X warning code : " + String(bsec.sensor.status));
}
}
I cannot upload the full error message because there are too many characters. Here is the last part of the error message:
/Users/christoforospanteli/Documents/Arduino/libraries/Bosch_BSEC2_Library/src/bsec2.cpp:138: undefined reference to `bsec_sensor_control'
collect2: error: ld returned 1 exit status
Using library BSEC2 Software Library at version 1.1.2200 in folder: /Users/christoforospanteli/Documents/Arduino/libraries/Bosch_BSEC2_Library
Using library Wire at version 2.0.0 in folder: /Users/christoforospanteli/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0/libraries/Wire
Using library SPI at version 2.0.0 in folder: /Users/christoforospanteli/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0/libraries/SPI
Using library BME68x Sensor library at version 1.1.40407 in folder: /Users/christoforospanteli/Documents/Arduino/libraries/BME68x_Sensor_library
exit status 1
Compilation error: exit status 1
In reference to the code posted in post#3, why does the OP put the instantaition so far down the list? Put the code near the top so ALL references to the envSensor are valid instead of being out of scope.
/* Create an object of the class Bsec2 */
Bsec2 envSensor;
Dear Idahowalker,
Thanks for your reply.
The example sketch is what I am using. The basic example works for MRK WiFi 1010 but doesn't compile for esp32.
The code in post#3 is unchanged from the example from BSEC2 library. I am not sure if I even need BSEC2 since I only want raw data from the BME688 sensor. When I try to upload the BME68x parallel_mode.ino example, I get the following error from both MKR and esp32:
I am trying to use the BME688 sensor from Bosch to detect VOCs. I am using the Sparkfun 19096 breakout board, Arduino IDE 1.8.19 and SV-Zanshin library, as recommended. I can read the Temperature, Humidity and Pressure data on the serial monitor but the altitude and gas resistance data are wrong. They show negative numbers (-41.73 and -999.35 for alt and gas, respectively), which I assume it’s variable overflow, and the values don’t change. I can fix the issue with the negative number by modifying the data types and scaling the reading down. However, the fact that the sensor gas resistance reading doesn’t change at all even after 48 hours burn in and exposure to acetone and IPA is worrisome. Here is the full list of the specifications I am using.
System:
macOS Monterey 12.6.2
Arduino IDE version 1.8.19
Sensor:
Bosch BME688
Breakout board:
Sparkfun 19096
Libraries:
Adafruit - github > adafruit/Adafruit_BME680 - This doesn’t find the sensor.
SV-Zanshin - github > Zanduino/BME680
Bosch - github > BoschSensortec/Bosch-BME68x-Library - This doesn’t find the sensor.
Now, for 3: Yes, there are examples and I am using the I2C Demo from the SV-Zanshin library (attached), the only one that gives me some data, so far. I tried the Adafruit and BOSCH but they can't find the sensor. I guess this is because the Adafruit and BOSCH libraries use SPI communication and I need to either change the code for I2C or change the Sparkfun board for SPI.
What do you think?
Your two or more topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Dear Idahowalker,
Thanks for the tip!
Here is what the I2C scanner report said:
> --- Scan started ---
> I2C device found at address 0x60 !
> I2C device found at address 0x6B !
> I2C device found at address 0x76 !
> --- Scan finished ---
Apologies! This is my first time using the Arduino forum. I thought by asking more specific questions on different topics would be easier.
Which device are you referring to? The BME688 sensor breakout or the Arduino MRK or esp32 boards?
Disconnect everything else from the MCU, except for the BME688. Run the scanner. Note the address. Look up on the internet the I2C address range of the BME688, does your address match? Get the example working with just the BME connected to the MCU.
Do you need pull up resistors?
Quite trying to edit libraries.
Go to the BME git hub site that makes the library you are using and ask them why it don't work.
Thanks a lot for the tips!
I attach a PDF with the schematics and photo of my circuit. The only thing connected to the MKR is the BME688 board.
The default address of the BME688 board is 0x76. BME688_circuit.pdf (3.2 MB)