Example Code for Raspberry Pi-Data Pooling
Last revision 2025/12/17
This guide offers detailed instructions for setting up a Raspberry Pi with an ENS160 Air Quality Sensor, including hardware and software requirements, necessary wiring diagrams, and step-by-step sample code execution for effective data pooling and analysis.
Hardware Preparation
- Raspberry Pi 4 Model B - 4GB (or similar) x 1
- Fermion: NS160 Air Quality Sensor x1
- Wires
Software Preparation
Wiring Diagram

The left is connection for I2C, the right is for SPI.
Other Preparation Work
Step 1. 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.
Step 2. 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
Step 3. 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

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 perheat for 3 minute each time it is used. You also need to set the current ambient temperature and humidity to assist in detecting result.
Was this article helpful?
