A code of BMP180 temperature and barometer I2C sensor for supporting Raspberry Pi Pico board
Hello Raspberry PI Pico developers and users, we made a small and simple library BMP180 I2C sensor for Raspberry PI Pico. I didn't find source code of BMP180 sensor for Raspberry Pi Pico board in C/C++, but in python source codes are already exist in internet, so I deciced to write code of BMP180 sensor for supporting Raspberry Pico.
The BMP180 sensor is worked fine with Raspberry Pi Pico board!!!
BMP180 I2C sensor is still popular for Arduino's projects. Moreover, I able buy this sensor freely in current time.
Links of ordering sensor: https://www.amazon.co.uk/UMTMedia%C2%AE-Pressure-Arduino-Precision-Atmospheric/dp/B0983V8115/ref=sr_1_4?crid=13S470NQVCI59&keywords=BMP180+3.3+V&qid=1684018689&sprefix=bmp180+3.3+v%2Caps%2C109&sr=8-4
- BMP180 with support 3.3 V logic and power
- Raspberry Pi Pico OR Raspberry Pi Pico W
- 4 pcs Male-Male breadboard jumper
- Micro USB cable (which we can connect into laptop)
- Putty software or any serial port terminal software
- Breadboard
- Installed PICO C SDK, cmake and visual studio code (In PICO SDK will install automatically visual studio code IDE, cmake and other essential softwares)
A built simplest circuit in breadboard with BMP180 sensor and Raspberry Pi Pico
Graphical represenatation schematic with BMP180 and Raspberry Pi Pico in Breadboard
Minimal schematic diagramm for ablity to work BMP180 sensor in any projects
Assume: Use minimal circuit diagramm to able work with BMP180 sensor
Sensor: Raspberry Pi Pico
VIN -------> 3.3 V OUT
GND -------> GND
SDA -------> GP4
SCL -------> GP5
Minimum amount of code that able work with BMP180 sensor in Raspberry Pi Pico.
Main code of usage example with BMP180 sensor for Raspberry PI Pico board. (You can look in main.c code file)
#include <stdio.h> /* Standard libary for printing the UART console */
#include "pico/stdlib.h" /* Libary of PICO SDK C/C++ for support function for RPI PICO */
#include "bmp180.h" /* Own header of BMP180 */
int main() {
stdio_init_all(); /* Initialize that supporting printf standard function via UART interface */
i2c_init_bmp180(); /* Initialize I2C interface for BMP180 sensor */
for (;;) /* Infinite loops */
{
data_from_bmp180 current_data = get_bmp180_sensor_data(3); /* Get data from BMP180 sensor */
printf("T: %.1f oC | Pressure: %.1f Pa \r\n",
current_data.air_temperature_in_celisus,
current_data.atmospheric_pressure_in_Pa); /* Print about data of BMP180 in UART console*/
sleep_ms(1000); /* Delay for 1000 ms */
}
}
-
Download own repository by using command
git clone https://github.com/misha-dig/pico-bmp180.git
-
Go to direcitory
pico-bmp180
by commandcd pico-bmp180
-
Set enviroment path of PICO_SDK_PATH with your pico-sdk directory path by command
export PICO_SDK_PATH=/your_sdk_path/pico-sdk
-
Create directory
build
by commandmkdir build
-
Go to
build
directory by commandcd build
-
Hit command
cmake ..
-
Hit command
make
and wait until building code finished -
Flash into your Raspberry Pi Pico file
pico_bmp180.uf2
frombuild
directory (You need first hold a button BOOTSEL until file manager appeared for Raspberry Pi Pico drive) -
Enjoy your project !!! :) :) :)
If you don't have doxygen package in your Linux PC
Please run two simple command (for debian based Linux OS users)
sudo apt-get update
sudo apt-get install doxygen
And genrate doxygen HTML documentation by invoking command in this directory
doxygen
Open your documentation by path html/index.html
We use Pico's setting default speed of UART
The default parameter for Raspberry Pico is
- Baudrate:
115200
bit/s - Data bit:
8
bit - Stopbit:
1
bit - Parity:
NONE
- Flow control:
XON/XOFF
So we enter 115200 and select serial port in main page of Putty software
We used with instruction how create any project with using Pico C SDK.
-
Clone by hitting command
git clone https://github.com/misha-dig/pico-bmp180.git
-
Go to direcitory
pico-bmp180
by commandcd pico-bmp180
-
Set enviroment path of
PICO_SDK_PATH
with your pico-sdk directory path by commandexport PICO_SDK_PATH=/your_sdk_path/pico-sdk
-
Modify project name in
CMakeLists.txt
file by using text editor (seach and replace all text frompico_bmp180
into your name of project (for examplemeteostation
) and save this text file) -
Create directory
build
by commandmkdir build
-
Go to
build
directory by entering commandcd build
-
Hit command
cmake ..
-
Build your source of code for your project by hitting command
make
inbuild
directory path
Just you need to follow few step ...
-
Download and unzip own this repository from github OR using
git clone https://github.com/misha-dig/pico-bmp180.git
-
Go to directory
pico-bmp180
-
Copy
bmp180.c
andbmp180.h
into your existing project directory -
You may be need to modify your
CMakeLists.txt
(Such adding file bmp180.c code in sectionadd_executable
and add dependencieshardware_i2c
in sectiontarget_link_libraries
) -
Enjoy your coding!!! :) Good Luck!!!
Controllerstech. Interface BMP180 with STM32. Controllerstech. https://controllerstech.com/interface-bmp180-with-stm32/ (Tutorial + video training how write code BMP180 I2C sensor stm32)
Bosch Sensortec. (2022, August 15th). Data Sheet BMP180 Digital pressure sensor. https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf (Datasheets of sensor BMP180)
Raspberry Pi Ltd. hardware_i2c. https://www.raspberrypi.com/documentation/pico-sdk/hardware.html#hardware_i2c (API Documentation of Raspberry PI Pico C SDK)
Raspberry Pi Ltd. The C/C++ SDK. https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html#say-hello-world (How create new project with Raspberry Pico)