Environmental sensor API with a RPi

Use a GY-91 Multi-Sensor Module to have a full Temperature/Gyro/ Accelerometer/Compass/Pressure API using flask and Python 3.


A little project to create an API with a GY-91 multi-sensor module that includes MPU9250 BMP280 modules with

This project is also compatible with the BMP280 module. But this project includes only the GY-91 shematic.

Connect sensor through the GPIO

There is a very little manipulation to connect 4 pins of the sensor on the GPIO.

3v3 is for 3.3v power, got to 3V3POWER[Pin 1] GND is for ground go to GROUND[Pin 6], SCL is for the clock bus I2C go to Pin 5, SDA, data bus IDC go to Pin 3 (See shematic bellow for color exemple)

Prepare Python dependencies

Install python3 on your rapsberry

$ sudo apt-get update$ sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev $ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz$ tar xf Python-3.6.5.tar.xz$ cd Python-3.6.5$ ./configure$ make$ sudo make altinstall

The source code on my gist required some dependencies that you can install with pip3

$ pip3 install flask flask-cors flask-restful


Now, clone the gist

$ git clone https://gist.github.com/wdelenclos/4f0c4b8d564aa5c58f47653fd184eaa7

Little explainations about this code. This code is scoped to display an api fot my personnal site and can be easilly adapt for others requirements.

The bme280 module is in the core of the program. It request BME datas on the GY-91 module and assign them on three variables with this instruction : temperature, pression, humidite = bme280.readBME280All().

Other instructions are simply a basic flask API.

Run it:

To run your api do

$ python3 app.py

To run it in background, deplay your script or do that :

$ sudo nohup python3 app.py &


See this demo status page, the module send a request in Ajax to get status for the module an dispkay it.

Ask me in comments if you want some explainations for this part !

Source: Environmental sensor API with a RPi

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top