本帖最后由 小马哥-1650185 于 2018-11-20 21:46 编辑
气压传感器顾名思义就是测量大气压强的,应该是比较常见的传感器。
模块使用BM1383AGLV,BM1383AGLV是压阻式压力传感器。BM1383AGLV负责温度补偿MEMS内部芯片,所以很容易得到压力信息。测量范围是 300hPa to 1100hPa。
实物图:
参考电路:
封装及引脚信息
模块电路及pcb
寄存器介绍
控制寄存器
初始化配置寄存器
代码:
- byte BM1383AGLV::init(void)
- {
- byte rc;
- unsigned char reg;
- rc = read(BM1383AGLV_ID, ®, sizeof(reg));
- if (rc != 0) {
- Serial.println(F("Can't access BM1383AGLV"));
- return (rc);
- }
- Serial.print(F("BM1383AGLV ID Register Value = 0x"));
- Serial.println(reg, HEX);
- if (reg != BM1383AGLV_ID_VAL) {
- Serial.println(F("Can't find BM1383AGLV"));
- return (rc);
- }
- reg = BM1383AGLV_POWER_DOWN_VAL;
- rc = write(BM1383AGLV_POWER_DOWN, ®, sizeof(reg));
- if (rc != 0) {
- Serial.println(F("Can't write BM1383AGLV POWER_DOWN register"));
- return (rc);
- }
- delay(WAIT_BETWEEN_POWER_DOWN_AND_RESET);
- reg = BM1383AGLV_RESET_VAL;
- rc = write(BM1383AGLV_RESET, ®, sizeof(reg));
- if (rc != 0) {
- Serial.println(F("Can't write BM1383AGLV RESET register"));
- return (rc);
- }
- reg = BM1383AGLV_MODE_CONTROL_VAL;
- rc = write(BM1383AGLV_MODE_CONTROL, ®, sizeof(reg));
- if (rc != 0) {
- Serial.println(F("Can't write BM1383AGLV MODE_CONTROL register"));
- return (rc);
- }
- delay(WAIT_TMT_MAX);
- return (rc);
- }
压力数据寄存器
转换公式:
0x1A~0x1C中的压力数据必须连续读取,否则会产生数据混淆。
温度寄存器:
转换公式:
温度数据同样需要连续读取。
代码:
- byte BM1383AGLV::get_rawval(unsigned char *data)
- {
- byte rc;
- rc = read(BM1383AGLV_PRESSURE_MSB, data, GET_BYTE_PRESS_TEMP);
- if (rc != 0) {
- Serial.println(F("Can't get BM1383AGLV PRESS and TEMP value"));
- }
- return (rc);
- }
- byte BM1383AGLV::get_val(float *press, float *temp)
- {
- byte rc;
- unsigned char val[GET_BYTE_PRESS_TEMP];
- unsigned long rawpress;
- short rawtemp;
- rc = get_rawval(val);
- if (rc != 0) {
- return (rc);
- }
- rawpress = (((unsigned long)val[0] << 16) | ((unsigned long)val[1] << 8) | (val[2]&0xFC)) >> 2;
- if (rawpress == 0) {
- return (-1);
- }
- *press = (float)rawpress / HPA_PER_COUNT;
- rawtemp = ((short)val[3] << 8) | val[4];
- if (rawtemp == 0) {
- return (-1);
- }
- *temp = (float)rawtemp / DEGREES_CELSIUS_PER_COUNT;
- return (rc);
- }
最后我们看到串口打印结果:
波形数据