Noduino BMP180
来自Jack's Lab
(版本间的差异)
(→硬件准备) |
(→代码示例) |
||
| 第99行: | 第99行: | ||
<source lang=cpp> | <source lang=cpp> | ||
| + | #include "noduino.h" | ||
| + | #include "bmp180.h" | ||
| + | irom void setup() | ||
| + | { | ||
| + | serial_begin(115200); | ||
| + | |||
| + | if (!bmp180_begin()) { | ||
| + | serial_print("Could not find a valid BMP180 sensor,\ | ||
| + | check wiring!\r\n"); | ||
| + | |||
| + | while (1) {} | ||
| + | } | ||
| + | } | ||
| + | |||
| + | irom void loop() | ||
| + | { | ||
| + | char obuf[16]; | ||
| + | double t = 0, p = 0; | ||
| + | |||
| + | bmp180_startTemperature(); | ||
| + | delay(15); | ||
| + | bmp180_getTemperature(&t); | ||
| + | |||
| + | dtostrf(t, 16, 2, obuf); | ||
| + | serial_printf("Temperature = \t\t%s C\r\n", obuf); | ||
| + | |||
| + | bmp180_startPressure(1); | ||
| + | delay(15); | ||
| + | bmp180_getPressure(&p, &t); | ||
| + | |||
| + | dtostrf(p, 16, 2, obuf); | ||
| + | serial_printf("Pressure = \t\t%s mbar\r\n", obuf); | ||
| + | |||
| + | dtostrf(bmp180_sealevel(p, 50), 16, 2, obuf); | ||
| + | |||
| + | // Calculate altitude assuming 'standard' barometric | ||
| + | // pressure of 1013.25 millibar = 101325 Pascal | ||
| + | serial_printf("Pressure at sealevel (calculated) = %s mbar\r\n", obuf); | ||
| + | |||
| + | // you can get a more precise measurement of altitude | ||
| + | // if you know the current sea level pressure which will | ||
| + | // vary with weather and such. If it is 1015 millibars | ||
| + | // that is equal to 101500 Pascals. | ||
| + | dtostrf(bmp180_altitude(p, bmp180_sealevel(p, 50)), 16, 2, obuf); | ||
| + | serial_printf("Real altitude = \t%s M\r\n\r\n", obuf); | ||
| + | |||
| + | delay(3000); | ||
| + | } | ||
</source> | </source> | ||
2016年8月28日 (日) 14:23的版本
目录 |
1 开发环境准备
根据您的系统,选择如下快速指南:
- Getting Started with Noduino SDK on Linux
- Getting Started with Noduino SDK on Mac OS X
- Getting Started with Noduino SDK on Windows
2 硬件准备
此传感器为 I2C 接口,接线方式如下:
- SCL --> D9
- SDA --> D8
3.3V 供电
3 编译烧写
进入你的 bmp180 目录:
$ cd /PATH/TO/noduino-sdk/examples/noduino/bmp180
编译、上传一步完成:
$ make flash
不同平台下,你的串口设备号可能不一样,确认一下你的串口设备,Linux 下 Falcon 开发板可能被识别为 /dev/ttyUSB1(dmesg 查看),则:
$ make flash ESPPORT=/dev/ttyUSB1
Windows 下 Falcon 开发板可能被识别为 COM6(控制面板 --> 设备管理器里查看),则:
$ make flash ESPPORT=COM6
4 查看结果
上传完之后,用串口工具,用 115200 的波特率打开串口,即可看到串口在持续输出传感器测得的值:
Windows 下可用串口调试助手这类插看
Linux 下推荐使用 picocom:
$ sudo apt-get install picocom $ picocom -b 115200 /dev/ttyUSB1 picocom v1.7 port is : /dev/ttyUSB2 flowcontrol : none baudrate is : 115200 parity is : none databits are : 8 escape is : C-a local echo is : no noinit is : no noreset is : no nolock is : no send_cmd is : sz -vv receive_cmd is : rz -vv imap is : omap is : emap is : crcrlf,delbs, Terminal ready ...... ......
Ctrl + a q 退出 picocom
5 代码示例
#include "noduino.h"
#include "bmp180.h"
irom void setup()
{
serial_begin(115200);
if (!bmp180_begin()) {
serial_print("Could not find a valid BMP180 sensor,\
check wiring!\r\n");
while (1) {}
}
}
irom void loop()
{
char obuf[16];
double t = 0, p = 0;
bmp180_startTemperature();
delay(15);
bmp180_getTemperature(&t);
dtostrf(t, 16, 2, obuf);
serial_printf("Temperature = \t\t%s C\r\n", obuf);
bmp180_startPressure(1);
delay(15);
bmp180_getPressure(&p, &t);
dtostrf(p, 16, 2, obuf);
serial_printf("Pressure = \t\t%s mbar\r\n", obuf);
dtostrf(bmp180_sealevel(p, 50), 16, 2, obuf);
// Calculate altitude assuming 'standard' barometric
// pressure of 1013.25 millibar = 101325 Pascal
serial_printf("Pressure at sealevel (calculated) = %s mbar\r\n", obuf);
// you can get a more precise measurement of altitude
// if you know the current sea level pressure which will
// vary with weather and such. If it is 1015 millibars
// that is equal to 101500 Pascals.
dtostrf(bmp180_altitude(p, bmp180_sealevel(p, 50)), 16, 2, obuf);
serial_printf("Real altitude = \t%s M\r\n\r\n", obuf);
delay(3000);
}
6 扩展阅读
- 更多问题参考: