This example program communicates with I2C via the lgpio library on Raspberry Pi OS
The MPL3115A2 barometric sensor can measure the barometric pressure and temperature by the I2C (Inter-Integrated-Circuit) to allow many devices to be read and written with through same two-wires that are connected to other devices. This sensor works well with the Raspberry Pi because it works well with the 3.3-volt power supplied by the motherboard. There are two buttons on this project, which the first button is used to calibrate the altitude and the second pushbutton calculates the altitude and reads the pressure and surrounding temperature. The following screen grab shows the output when calibrating the altimeter.
The lgpio library can be installed Raspberry Pi OS (6 July 2023) and instructions are available at http://abyz.me.uk/lg/download.html
Install instructions are:
- sudo apt install swig python3-dev
- sudo apt install python3-setuptools
- wget http://abyz.me.uk/lg/lg.zip
- unzip lg.zip
- cd lg
- make
- sudo make install
- create a Blink example program and copy the program and libraries to the RaspberryPi Desktop
- give the executable permission to run with something like: 'sudo chmod +x HelloWorldBlink'
- run the program with something like: 'sudo ./libGPIODinput'