In the loop(), the printValues() function reads the values from the BME280 and prints the results in the Serial Monitor. Adafruit Industries, Unique & fun DIY electronics and kits Adafruit ESP32-S3 Reverse TFT Feather 4MB Flash, 2MB PSRAM, STEMMA QT : ID 5691 - Like Missy Elliot, we like to " put our Feather down, flip it and reverse it" and that's exactly what we've done with this new development board. With the BME280 sensor wired to your ESP32, run this I2C scanner sketch to check the address of your sensor. In case you’re not getting sensor readings, check the I2C address of your sensor. We initialize the sensor with the 0x76 address. In the setup(), start a serial communication: Serial.begin(9600) Īnd initialize the sensor: status = bme.begin(0x76) 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 depending on whether you’re using hardware or software SPI (hardware SPI uses the ESP32 default HSPI pins software SPI uses the pins defined on the code). As you can see, you just need to create an Adafruit_BME280 object called bme. This example uses I2C communication protocol by default. This example uses the default value, but for more accurate results, replace the value with the current sea level pressure at your location. This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This variable saves the pressure at the sea level in hectopascal (is equivalent to milibar). SPIĪ variable called SEALEVELPRESSURE_HPA is created. For SPI communication on the ESP32 you can use either the HSPI or VSPI pins, as shown in the following table. Note: if you’re using SPI communication, you use the ESP32 SPI pins. #include Īs we’re going to use I2C communication, the following lines that define the SPI pins are commented: /*#include 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. How the Code WorksĬontinue reading this section to learn how the code works, or skip to the “Demonstration” section. ![]() We’ve made a few modifications to the sketch to make it fully compatible with the ESP32. Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)) Serial.print(bme.readPressure() / 100.0F) Serial.print(1.8 * bme.readTemperature() + 32) Serial.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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |