Skip to content

Barometer based on the LPS25 MEMS pressure sensor, written in Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

anglerud/lps25_pressure_sensor_demo

Repository files navigation

Barometer with an LCD display

A barometer based on Adafruit's LPS25 breakout board, written in Rust, running on the Blue Pill board and displaying the result on an HD44780 LCD panel.

project photo

Description and parts

This is a barometer, it will display the current atmospheric pressure on an 16x2 alphanumeric LCD panel.

The microcontroller

The Blue Pill is a very affordable STM32 (ARM Cortex M3) microcontroller board. You can read more about the Blue Pill on stm32-base's Blue Pill page. I have programmed this with a clone of the ST-Link V2 USB dongle. I've also used the ST-Link to provide power to the whole setup as it can provide both 5V and 3.3V power.

I use probe-rs and its probe-run component to flash the program onto the microcontroller and to interact with it. In order for that to work, you must make sure the ST-Link V2 debugger runs the latest firmware, which I did wit hthe STSW-LINK007 firmware upgrade application. This is a Java app which works well on Linux.

I program the microcontroller using Rust. I read Circuit4u's Rust on STM32F103 Blue Pill with Probe-run tooling article on using Rust on the Blue Pill. They've also got link to Levi Pearson's blue_pill_base git repo that I cloned as the base for working in Rust with the Blue Pill. This sets up the probe-rs integration and more.

The sensor

The barometer is built with Adafruit's LPS25 breakout board, which contains ST's LPS25H MEMS pressure sensor. It measures ambient pressure between 260-1260 hPa and can be read over I2C.

The lps25hb crate is our Rust driver for this sensor.

The display

The display is an LCD panel displaying 16 characters on each of 2 rows and is addressed over I2C. It has a Hitachi HD44780 LCD controller, and an I2C backpack already soldered on. The device is sold by Handsontec as the I2C Serial Interface 1602 LCD Module. There are many compatible devices like this, sold under different names.

The IC on the backpack is a PCF8574T - an NXP version of a TI port expander chip. It is communicated with over I2C and controls a larger number of pins.

I use the hd44780-driver crate to control the screen. It even includes the ability to use the I2C backpack, making this very simple.

Wiring

You can see the wiring diagram below for how everything is connected.

First you need to connect up your programmer/debugger to the Blue Pill (see connecting your debugger for a pin-out diagram). For more information on the exact programmer I have used - look at the "ST-LINK/V2 Clone" section.

I'm using the first I2C bus on the Blue Pill, which is made up of pins SCL1 and SDA1. These are labeled PB6 and PB7 on the board. You can see the pinout diagram and chart on microcontrollerslab.com's Blue Pill pinout - peripherals programming features article.

These I2C pins are connected to both the pressure sensor and the screen. Both devices have their own I2C address and will happily talk on the same I2C bus.

You can see how to connect the Adafruit LPS25 in the LPS25 pressure sensor pinouts article on adafruit.com, and in the wiring diagram below. Adafruit describes the pins on the LPS25 like this:

  • SCK - I2C clock pin, connect to your microcontroller's I2C clock line. This pin is level-shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.
  • SDI - I2C data pin, connect to your microcontroller's I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.

The equivalent pins on the display board are called SCL (clock) and SDA (data).

For the clock signal, there should be a connection between:

  • PB6 (SCL1) on the Blue Pill.
  • SCK on the LPS25.
  • SCL on the display.

For the I2C data line, there should be a connection between:

  • PB7 (SDA1) on the Blue Pill.
  • SDI on the LPS25.
  • SDA on the display board.

All of the components are tolerant to a wide range of power - the LPS25 can run on either 3.3V or 5V, the Blue Pill can run on 5V USB, 5V pin or a 3.3V pin, and finally the LCD panel needs 5V to run properly. The LCD panel will work at 3.3V, but the characters won't be backlit and will be really hard to read. So, I had a lot of leeway to choose how to power this project. As the Blue Pill was already running off the ST-Link, that's sorted already. I chose to run the LPS25 off 3.3V from the ST-Link, and the LCD panel off one of its 5V outputs. As you can see in the diagram below - I have one rail on the breadboard connected to 3.3V and one to 5V. The 5V rail is then connected to VCC on the display, while the 3.3V rail is connected to VIN on the LPS25.

The diagram below tries to show the different power levels as two different inputs, but they're actually both coming from the ST-Link - just one rail is connected to a 3.3V pin, and the other to a 5V pin. Everything is connected to the same GND pin on the programmer.

Note that the display backpack has a potentiometer for contrast on the back. If you don't see any text displayed - try adjusting that potentiometer.

wiring diagram

Shared-bus

An important part of this build is the shared-bus crate, which let me control multiple I2C devices on one bus, like the pressure sensor and the screen.

This does all the locking and ownership management that makes sure that Rust is happy with me sharing the I2C pins between multiple devices.

Running the barometer

Run the barometer with:

cargo run --bin lps25_barometer --release

About

Barometer based on the LPS25 MEMS pressure sensor, written in Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published