Example Code for Raspberry Pi-Polling for Data

Last revision 2026/01/21

In the terminal, input the following command and press Enter to run the sample code to get sensor data.

Hardware Preparation

Software Preparation

Wiring Diagram

Connect the module to the Raspberry Pi according to the wiring diagram.

Other Preparation Work

Note: 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 minutes later before use. And the ambient temperature and humidity are required for compensating measured data.

  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 Raspeberry Pi board.
  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
  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

Was this article helpful?

TOP