Skip to content

begin()

Arnd edited this page May 22, 2020 · 10 revisions

begin() call Description
[success=] begin(); Use I2C and auto-search for BME680
[success=] begin( I2CSpeed ); Use I2C and the specified speed (see below)
[success=] begin( I2CSpeed , I2CAddress ); Use I2C with specific address
[success=] begin( I2CAddress ); Use I2C when value is 0x76 or 0x77
[success=] begin( SS ); Use hardware SPI
[success=] begin( SS , MISO , MOSI , SCK ); Use software SPI

This function initializes the BME680 device using one of the 3 available protocols:

  1. I2C
    By default the I2C address of the BME680 is hard-wired to 0x76 or 0x77. When called with no argument, the library will search the 2 possible I2C addresses until it finds a BME680. If given a single argument with a value of 0x76 or 0x77 that will be used as the I2C address to be used. If one argument is used and it is an unsigned 32 bit integer (uint32_t) then it used as the I2C speed.
  2. Hardware SPI
    When called with just one parameter it will use hardware SPI and the pin parameter passed in is the SS pin, or "Slave Select" pin. This parameter must be an unsigned small integer, and pins 0x76 or 0x77 cannot be used, if present; as these two values are used to specify the I2C address when using the I2C communications protocol described above.
  3. Software SPI
    When called with 4 parameters then software SPI is used and the 4 pins are assigned accordingly.

The function has an optional return value which is TRUE when the device has been located and initialized, otherwise a FALSE will be returned.

The I2C bus defaults to the slowest speed, 100KHz. The Bosch sensor can go much faster if desired, specify one of the following Constants in the optional I2CSpeed parameter.

Constant Speed
I2C_STANDARD_MODE 100KHz
I2C_FAST_MODE 400KHz
I2C_FAST_MODE_PLUS 1MHz
I2C_HIGH_SPEED_MODE 3.4MHz

Example:

...    
...    
BME280_Class BME680;  // Instantiate class    
...    
...    
while (!BME680.begin(I2C_FAST_MODE_PLUS)) {        // Find on I2C bus
  Serial.println("Error, unable to find BME680."); // Show error message
  delay(5000);                                     // Wait 5 seconds 
} // of if-then we can't initialize or find the device
...    
...