1108 views|0 replies

1452

Posts

1

Resources
The OP
 

【Portable environmental status detector】Temperature and atmospheric pressure detection [Copy link]

 

BMP085 is an ambient temperature and atmospheric pressure detection device. It also works with an I2C interface. Its processing method is very similar to that of the BH1750 light intensity sensor. The temperature and atmospheric pressure detection display is shown in the figure below.

Detection effect display diagram

The pins used by BMP0850 are:

GPIO13---SDA

GPIO11---SCL

The initialization function of BMP085 is:

voidInit_BMP085(void)
{
 ac1 = Multiple_read(0xAA);
 ac2 = Multiple_read(0xAC);
 ac3 = Multiple_read(0xAE);
 ac4 = Multiple_read(0xB0);
 ac5 = Multiple_read(0xB2);
 ac6 = Multiple_read(0xB4);
 b1 = Multiple_read(0xB6);
 b2 = Multiple_read(0xB8);
 mb = Multiple_read(0xBA);
 mc = Multiple_read(0xBC);
 md = Multiple_read(0xBE);
}

The function to read the temperature is:

long bmp085ReadTemp(void)
{
 BMP085_Start();
 BMP085_Send_Byte(BMP085_SlaveAddress);
 while(BMP085_Wait_Ack());
 BMP085_Send_Byte(0xF4);
 while(BMP085_Wait_Ack());
 BMP085_Send_Byte(0x2E);
 while(BMP085_Wait_Ack());
 BMP085_Stop();
 vTaskDelay(1);
 return (long) Multiple_read(0xF6);
}

The function to read the atmospheric pressure is:

long bmp085ReadPressure(void)
{
 long pressure = 0;
 BMP085_Start();
 BMP085_Send_Byte(BMP085_SlaveAddress);
 while(BMP085_Wait_Ack()){}
 BMP085_Send_Byte(0xF4);
 while(BMP085_Wait_Ack()){}
 BMP085_Send_Byte(0x34);
 while(BMP085_Wait_Ack()){}
 BMP085_Stop();
 vTaskDelay(1);
 pressure = Multiple_read(0xF6);
 pressure&= 0x0000FFFF;
 return pressure;
}

The BMP085 numerical conversion function is:

void bmp085Convert(void)
{
 unsigned int ut;
 unsigned long up;
 long x1, x2, b5, b6, x3, b3, p;
 unsigned long b4, b7;
 ut = bmp085ReadTemp();
 up = bmp085ReadPressure();
 x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
 x2 = ((long) mc << 11) / (x1 + md);
 b5 = x1 + x2;
 temperature1 = ((b5 + 8) >> 4);
 b6 = b5 - 4000;
 x1 = (b2 * (b6 * b6)>>12)>>11;
 x2 = (ac2 * b6)>>11;
 x3 = x1 + x2;
 b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
 x1 = (ac3 * b6)>>13;
 x2 = (b1 * ((b6 * b6)>>12))>>16;
 x3 = ((x1 + x2) + 2)>>2;
 b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
 b7 = ((unsigned long)(up - b3) * (50000>>OSS));
 if (b7 < 0x80000000)
 p = (b7<<1)/b4;
 else
 p = (b7/b4)<<1;
 x1 = (p>>8) * (p>>8);
 x1 = (x1 * 3038)>>16;
 x2 = (-7357 * p)>>16;
 pressure = p+((x1 + x2 + 3791)>>4);
}

The main procedure for temperature and atmospheric pressure detection is:

void app_main(void)
{
 configure_led();
 configure_Oled();
 OLED_Init();
 OLED_Clear();
 OLED_ShowString(0,0,"ESP32-S2-Kaluga",16);
 OLED_ShowString(16,2,"OLED & BMP085",16);
 BMP085_Init();
 Init_BMP085();
 OLED_ShowString(0,4,"t= C",16);
 OLED_ShowString(0,6,"p= KPa",16);
 while (1) {
 blink_led();
 s_led_state = !s_led_state;
 vTaskDelay(CONFIG_BLINK_PERIOD / portTICK_PERIOD_MS);
 bmp085Convert();
 OLED_ShowNum(24,4,temperature1/10,3,16);
 OLED_ShowNum(24,6,pressure/100,5,16);
 }
}

This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list