Interface BMP180 Pressure Sensor with STM32 || Temperature || Altitude || CubeIDE
8 views
Aug 5, 2020
Purchase the Products shown in this video from :: https://controllerstech.store ________________________________________________________________________________________ STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd DOWNLOAD THIS PROJECT FROM :::: https://controllerstech.com/interface-bmp180-with-stm32/ ________________________________________________________________________________________ ******* SUPPORT US BY DONATING****** https://paypal.me/controllertech *******Join the Membership******* https://www.youtube.com/channel/UCkdqtSMnhYuMsJkyHOxiPZQ/join Join the Discord Server https://discord.gg/D32JE5wKyD Join the Telegram Group https://t.me/controllerstechdiscuss
View Video Transcript
0:10
[Music]
0:17
hello everyone
0:19
welcome to controllers tech in this
0:22
video
0:23
we will cover the pressure sensor bmp
0:25
180
0:27
and how to measure temperature pressure
0:29
and altitude using it
0:31
i am using cube id for the project
0:35
let's take a look at the data sheet by
0:37
the time id
0:38
gets ready
0:46
here we have the measurement flow for
0:48
the bmp 180.
0:51
it's better explained in the later part
0:53
of this document
0:55
this is the table for the over
0:56
oversampling setting also known as
0:59
oss here you can control what type of
1:03
calculation you want
1:05
i will be using oss0 in my code
1:08
but you are free to choose other values
1:10
too
1:16
now this is the main algorithm for the
1:18
measurement
1:20
we will come back to this let's create
1:23
the project in cube id
1:29
i am using stm32f4 discovery board
1:40
give some name to the project and click
1:42
finish
1:45
[Music]
1:48
here is our cube mx let's clear the pin
1:52
out first
2:01
[Music]
2:06
i am selecting external crystal for the
2:08
main clock
2:16
now as bmp 180 works with i2c
2:19
let's enable the i2c1 in the later part
2:23
of this video
2:24
i will also use the oled display and for
2:27
that i am selecting fast mode
2:30
you can use standard mode also
2:33
let's see the clock setup now
2:37
i have 8 megahertz crystal and the
2:39
system is running at 168 megahertz
2:43
click save to generate the project
3:01
here is our main file let's first
3:05
include the library file for the bmp180
3:10
put the c file in the source and header
3:12
file in the include directory
3:22
include the bmp180.h file in the main
3:27
let's see the bmp180.h file
3:32
here we have these functions available
3:34
to be used in our main
3:36
file start is to start the calibration
3:41
to measure the temperature pressure
3:45
altitude let's see how the code works
3:53
i have defined here the i2c address for
3:56
the bmp 180.
3:59
so why the address is zero cross double
4:01
e
4:03
let's see the data sheet
4:04
[Music]
4:09
here we have the device address
4:15
we will assume that the lsb is 0 then we
4:18
have 1 1 1 here
4:21
which corresponds to e in hexadecimal
4:25
and we have 0 1 1 1 in the higher nibble
4:28
also
4:29
that's make the address 0 cross double e
4:37
next i have defined some variables here
4:41
let's see the first half of them
4:50
these 16-bit variables will be used to
4:53
store the calibration data
4:56
and here are the approximate values for
4:59
these variables
5:00
[Music]
5:05
the rest of them are also mentioned in
5:07
the data sheet
5:08
so i have defined them too
5:10
[Music]
5:18
[Music]
5:25
the mp start calls a function read
5:28
calibration data
5:38
this function reads the calibration
5:40
values from the eep
5:42
rom of the bmp 180 as mentioned in the
5:46
data sheet
5:47
this zero cross double a is the start
5:50
address for these registers
5:52
and starting from this address we need
5:55
to read
5:56
22 registers totally
5:58
[Music]
6:05
i have used hali2c memory read function
6:08
to read the memory address
6:11
third parameter is the start address
6:18
size of the start address
6:25
and how many bytes to read a c1 is a
6:29
16-bit variable
6:30
and the registers are only 8-bit in size
6:34
we need to combine 2 registers to make
6:37
them 16 bit in size
6:39
and we need to do the same for all the
6:41
calibration variables
6:49
next part is to read the uncompensated
6:52
temperature
6:53
to do that we need to write 0 cross 2 e
6:56
into the register 0 cross f
6:58
4 and wait for 4.5 milliseconds
7:05
so this is the data to write i am using
7:09
memory write function
7:11
this is the register and this here is
7:14
the data and wait for 5 milliseconds
7:22
next we need to read starting from 0
7:25
cross f6 register
7:27
and we need to read 2 bytes of the data
7:38
as the manual says we need to read 0
7:41
cross
7:41
f6 and f7 register for the msb and lsb
7:45
and finally convert them to a single
7:47
16-bit value
7:48
to get the uncompensated temperature
8:10
next we need to read the uncompensated
8:12
pressure but i preferred to do the
8:14
calculation for the actual temperature
8:25
these calculations here are as mentioned
8:28
in the data sheet
8:34
now let's read the compensated pressure
8:41
to do so we need to write 0 cross 3 4
8:44
along with the oss in the register 0
8:47
cross f4
8:52
here o s s stands for over sampling
8:56
setting
8:57
it is explained in the table above
9:06
if you choose 0 then the waiting period
9:08
is 4.5 milliseconds
9:12
for any other selection waiting period
9:14
also varies
9:22
this is the data to be written and we
9:25
will write into into this register
9:28
i have covered different cases of oss
9:30
here
9:31
the code will wait according to your
9:34
choice
9:40
then we need to read the three registers
9:42
starting from zero cross
9:44
f six as mentioned in the data sheet
9:48
we need to arrange these register values
9:50
to get the uncompensated pressure
10:09
this here is the calculation for actual
10:12
pressure using the uncompensated value
10:15
this is exactly as mentioned in the
10:17
manual
10:28
we can calculate altitude from sea level
10:30
using the pressure value
10:37
the formula to do so is given here
10:41
here p is our actual pressure and p not
10:44
is the standard pressure at sea level
10:51
standard pressure is defined as 1 0 1
10:54
3 2 5 pascals this is how the library
10:58
was written for the bmp180
11:06
now let's start our program first of all
11:10
let's define the variables
11:12
that we are going to store the values in
11:17
in the main function start the bmp 180
11:21
to read the calibration data
11:24
these calibration values depends on the
11:26
sensor
11:27
and that's why we need to calculate them
11:29
once
11:30
now in the while loop we will calculate
11:33
the temperature first
11:35
then pressure and then altitude
11:40
let's wait for 2 seconds before
11:41
repeating the calculations
11:44
let's build our code all good here
11:48
let's debug it
11:52
i have added all the values in the
11:54
expression on the right
11:55
so that we can compare it with the
11:57
values in the data sheet
11:59
let's run it you can pause the video and
12:03
compare these values
12:05
they all are almost identical except ac1
12:08
and ac2 which have a huge difference
12:12
but that's okay and expected too
12:15
as i mentioned earlier that the
12:17
calibration values depends on the sensor
12:20
and will vary for all
12:25
you can see the temperature pressure and
12:28
altitude values are precise
12:30
and they are updating every two seconds
12:38
as i said during the setup that i will
12:40
use oled also
12:43
let's include the libraries for the
12:44
display
12:50
oled display is also connected to same
12:52
i2c
12:53
that is i2c1 copy c files in the source
12:58
and the header files in the include
13:01
let's include the header file first
13:09
[Music]
13:16
these are the arrays where the
13:18
characters corresponding to the float
13:20
values
13:20
will be stored
13:30
let's initialize the oled and print some
13:33
strings on
13:34
it if you don't understand the oled
13:36
functions
13:37
check out the oled video on the top
13:39
right corner
13:45
now after getting the values of
13:47
temperature pressure and altitude
13:49
we will convert them to characters and
13:52
display them on the oled display
13:54
this is to display temperature pressure
13:59
and altitude as you can see
14:02
we have some error here because we are
14:04
trying to convert the float into the
14:06
character
14:08
the solution is also provided by the id
14:18
so let's go to project properties
14:21
build settings tool setting
14:26
and enable the uprint float
14:33
we also need to include the stdio.h file
14:37
for the s printf to work
14:47
you can see the error is gone now
14:52
let's build it and flash to our board
15:04
you can see all the values are being
15:10
displayed
15:13
this is it for this video i hope you
15:16
understood it
15:18
i could have just shown you the library
15:20
and the working
15:22
but the point was to show you guys how
15:24
easy it is to use the data sheet
15:27
and write the functions yourself you can
15:30
download the code from the link in the
15:32
description
15:34
keep watching and have a nice day ahead
15:44
[Music]
15:45
you