Skip to content

begin()

Arnd edited this page Jun 30, 2018 · 11 revisions

[success=] begin([I2CSpeed]); // for I2C
[success=] begin(SS); // SS (Slave Select) Pin for HW SPI
[success=] begin(SS,MISO,MOSI,SCK); // SW SPI


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

  1. I2C
    By default the I2C address of the BME280 is hard-wired to 0x76 or 0x77 although the address might something completely different when using an I2C expander. The library will search all possible I2C addresses until it finds the first BME280 and will use that device.
  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.
  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 BME280;  // Instantiate class    
...    
while (!BME280.begin(I2C_FAST_MODE_PLUS)) {        // Find on I2C bus
  Serial.println("Error, unable to find BME280."); // Show error message
  delay(5000);                                     // Wait 5 seconds 
} // of if-then we can't initialize or find the device
Clone this wiki locally