Home

ESP32 BMP180 Sensor Tutorial | How to Interface BMP180 with ESP32?

在本教程中,我们将学习如何与ESP32 Devkit开发委员会接口BMP180。如果您想使用ESP32构建基于Web的压力和温度监测系统,那么BMP180是最便宜的选择之一(例如,肯定比BMP180更好,例如BME280)。尽管如此,了解ESP32 BMP180压力和温度传感器界面如何工作,设置Arduino IDE,在LCD上显示压力和温度数据。此外,您可以设计一个简单的ESP32 Web服务器,该服务器连续显示BMP180传感器的压力和温度。

ESP32-BMP180-Image-2

BMP180传感器的简短说明

我们已经在Arduino BMP180教程中看到了BMP180传感器。但是,让我们回顾一些有关传感器的重要信息。BMP180是Bosch的数字气压传感器。它是基于压电电阻MEMS设备的超低动力设备。它可以测量300 hPa至1100 hPa的大气压。

除了测量压力外,BMP180传感器还可以测量0的温度0C至650C. Since BMP180 measures the atmospheric pressure, you can easily deduct the altitude of the point (as they both are related).

BMP180-Module-Front

实际的BMP180传感器是一个微型设备,尺寸为3.6mm x 3.8mm。它可在7 PIN LGA包中使用,并通过I与微控制器进行通信2C或SPI(最终传感器中只有一个)。

传感器的一个重要点是其校准。传感器需要正确校准以产生可接受的结果。幸运的是,所有Bosch BMP180气压传感器均已出厂校准,以便它们可以使用。

许多第三方模块和传感器制造商都采用了小型BMP180传感器,并设计了一个小模块,非常适合Arduino和其他DIY项目。今天可用的大多数模块使用i2C Communication. [ESP32 Projects for Beginners这是给予的

Pin Diagram of BMP180

The following image shows the Pins of BMP180 Sensor. The module has labelled the pins on the back.

BMP180模块背

如您所见,BMP180模块上有四个引脚:

  • VIN
  • gnd
  • SCL
  • SDA

ESP32 BMP180接口

现在,我们已经看到了一些有关BMP180压力和温度传感器的信息,现在让我们继续了解如何与ESP32接口BMP180。您要记住的第一件事是BMP180是数字传感器。

要记住的下一个重要的事情是BMP180传感器使用i2C巴士与微控制器通信。如果您还记得ESP32的引脚,则默认2ESP32的C引脚是GPIO 21(SDA)和GPIO 22(SCL)。它们在ESP32 Devkit开发委员会上分别标记为D21和D22。

So, we have to use these pins to interact with BMP180 Sensor.

需要组件

  • ESP32 DevKit Development Board
  • BMP180压力和温度传感器(模块)
  • 16×2 LCD
  • PCF8574 I2C LCD Module
  • Breadboard
  • Connecting Wires
  • 微型USB电缆

电路原理图

The following image shows the connections between ESP32 and BMP180. The BMP180 Module has on-board 3.3V regulator. So, you can power the board with 5V. Connect VBMP180到ESP32板的VIN。还将BMP180的GND引脚连接到ESP32的任何GND引脚。

Now, coming to the I2C Pins, connect SDA to GPIO 21 of ESP32 (which is marked as D21 on Board) and SCL to GPIO22 (which is marked as D22). This finishes all the connections.

ESP32-BMP180-Circuit

准备Arduino IDE

You need to download one library associated with BMP180 Sensor so that ESP32 will properly communicate with the Sensor. Go to Tools -> Manage Libraries… in Arduino IDE.

BMP180-Library-1

In the search bar, enter ‘bmp180’ and install ‘Adafruit BMP085 Library’ by Adafruit.

BMP180-Library-2

Displaying Pressure and Temperature on Serial Monitor

After making the proper connections and installing the necessary libraries as mentioned above, we will now see how to read the Pressure and Temperature data from BMP180 Sensor using ESP32 and display the result on the Serial Monitor.

代码

The BMP180 Sensor uses I2C bus for communication with the Microcontroller. I wrote a simple code which will initialize the BMP180 Sensor and reads the Pressure and Temperature data from the sensor.

To view the result, I simply used the serial monitor to print the pressure values in hPa for and degree Celsius for temperature.

ESP32-BMP180-Image-3

下图显示了串行显示器的屏幕截图,该串行显示器每3秒连续打印压力和温度读数。

ESP32-BMP180串行

ESP32 BMP180 with I2C LCD

Displaying pressure and temperature data from BMP180 Sensor on Serial Monitor is useful just for testing the connections and the code itself. To build a practical “Embedded System” application, you have to use a display module of some kind (OLED, 16×2 Character LCD, Nokia 5110 LCD, graphical LCD etc.) to view the pressure and temperature readings.

I used a regular 16×2 Character LCD Display Module in combination with PCF8574 I2C LCD Module to display the pressure and temperature readings from ESP32 BMP180 Sensor Interface.

我对如何使用i进行了专门的教程2C LCD with ESP32. Check out that tutorial for in-depth information. I also discussed the necessary libraries you have download to successfully connect I2C LCD with ESP32 in that tutorial.

NOTE:I also explained how to get the Slave Address of I2C LCD Module in that tutorial. This step is very important.

电路原理图

您需要的其他组件是16×2 LCD显示屏和I2C LCD模块(基于PCF8574)。插入16×2 LCD显示屏背面的I2C LCD模块。I2C LCD模块仅需要四个连接(其中两个是用于电源,两个用于数据)。

以下电路图显示了ESP32和I2C LCD模块以及ESP32和BMP180压力和温度传感器之间的所有必要连接。

ESP32-BMP180-LCD电路

代码

I2C LCD的ESP32 BMP180传感器接口的代码非常简单。传感器的初始化部分与先前的代码相似。另外仅添加了与LCD相关的代码。

ESP32-BMP180-Image-1

Conclusion

这里实施了有关将BMP180压力传感器与ESP32接口的完整初学者指南。您了解了有关BMP180传感器的一些基本信息,ESP32 BMP180传感器接口如何工作,与BMP180通信的必要库,如何在串行输出上显示压力和温度数据,以及如何将I2C LCD与ESP32连接到ESP32以及显示压力和温度读数。

就使用ESP32和BMP180传感器的基于Web的压力和温度监控系统而言,我将在短期内使用Web服务器代码更新此页面。

One Response

Leave a Reply

您的电子邮件地址不会被公开。

电子豪华粉丝
<\/i>","library":""}}" data-widget_type="nav-menu.default">
Baidu