Skip to content

begin()

Arnd edited this page Aug 4, 2017 · 11 revisions

[success=] begin(); // 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.
  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.


Example:

BME280_Class BME280;  // Instantiate class    
...    
while (!BME280.begin()) {                          // 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