Example Code for Raspberry Pi-Data Pooling
Last revision 2025/12/18
Run the sample code to get the sensor data (sensor status, AQI level, TVOC and eCO2 concentration) on Raspberry Pi.
Hardware Preparation
- Name: Raspberry Pi 4 Model B - 4GB, Model/SKU: product-1986, Quantity: 1, Purchase Link: Raspberry Pi 4 Model B - 4GB
- Name: Gravity: NS160 Air Quality Sensor, Quantity: 1
- Name: Wires, Quantity: 1
Software Preparation
- Development tools: RASPBIAN Official OS
- Library: ENS160 Air Quality Sensor Python Library
Wiring Diagram
Connect the module to the Raspberry Pi according to the wiring diagram. The I2C address is the same as the address where the DIP switch is dialed to.

Other Preparation Work
- Please let the sensor run for 1 hour first to ensure the accuracy of the data when using it for the first time, and then run (warm up) for 3 minute each time it is used. You also need to set the current ambient temperature and humidity to assist in detecting result.
- Enable Raspberry Pi I2C.(Skip this step if it is already enabled) Open terminal and input the following commands and press "Enter":
pi@raspberrypi:~ $ sudo raspi-config
Then use the UP/Down keys to select "Interfacing Options", press Enter, select "P5 I2C" and press Enter to comfirm "Yes". Restart the Pi board.
- To install Python dependency library and git, the Raspberry Pi needs to be connected to the Internet. Skip this step if already installed. In the terminal, input the following commands and press Enter:
pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git
- Download the ENS160 driver library. In the terminal, type the following commands and press Enter:
pi@raspberrypi:~ $ cd Desktop/ pi@raspberrypi:~/Desktop $ git clone https://github.com/DFRobot/DFRobot_ENS160
Sample Code
- In the terminal, input the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_ENS160/python/raspberrypi/examples/get_measure_data
pi@raspberrypi:~/Desktop/DFRobot_ENS160/python/raspberrypi/examples/get_measure_data $python get_measure_data.py
Result

Was this article helpful?
