3/23/2023 0 Comments Wire library energiaSerial.println("Could not find a valid BME280 sensor, check wiring!") (you can also pass in a Wire library object like &Wire2) Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK) // software SPI After installing the BME280 library, and the Adafruit_Sensor library, open the Arduino IDE and, go to File > Examples > Adafruit BME280 library > bme280 test. Serial.print(bme.readPressure() / 100.0F) Serial.print(1.8 * bme.readTemperature() + 32) Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)) Ĭontinue reading this section to learn how the code works, or skip to the “Demonstration” section. The code starts by including the needed libraries: the wire library to use I2C, and the Adafruit_Sensor and Adafruit_BME280 libraries to interface with the BME280 sensor. #include Īs we’re going to use I2C communication, the following lines that define the SPI pins are commented: /*#define BME_SCK 13Ī variable called SEALEVELPRESSURE_HPA is created. This variable saves the pressure at the sea level in hectopascal (is equivalent to milibar). This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This example uses the default value, but for more accurate results, replace the value with the current sea level pressure at your location. This library is free software you can redistribute it and/or: modify it under the terms of the GNU Lesser General Public: License as published by the Free Software Foundation either: version 2.1 of the License, or (at your option) any later version. At the top of the drop down list, select the option Add Library ). TwoWire.h - TWI/I2C library for Arduino & Wiring: Copyright (c) 2006 Nicholas Zambetti. If you have already downloaded library archive, you can install it via nice GUI (in the Arduino/Energia IDE, navigate to Sketch > Import Library. This example uses I2C communication protocol by default. Arduino and Energia IDEs have built-in lite library manager from a box. As you can see, you just need to create an Adafruit_BME280 object called bme. In the setup(), start a serial communication: Serial.begin(9600) Īnd the sensor is initialized: status = bme.begin() Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK) // software SPI setup() Adafruit_BME280 bme(BME_CS) // hardware SPI To use SPI, you need to comment this previous line and uncomment one of the following lines.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |