PiicoDev Air Quality Sensor ENS160 | Getting Started Guide

Michael just shared a new tutorial: “PiicoDev Air Quality Sensor ENS160 | Getting Started Guide”



The PiicoDev® Air Quality Sensor is based on an ENS160 multi-gas sensor that detects Volatile Organic Compounds (VOCs). These measurements are run through some algorithms to produce standardised outputs like Air Quality Index (AQI), Equival…

Read more

I think you have a rather dramatic typo in your main.py code, in that you refer to ppb instead of ppm.
The code states:
print(’ TVOC: ’ + str(tvoc) + ’ ppb’)
yet the sample shown reads:
TVOC: 66 ppm

1 Like

The datasheet lists TVOC as being measured as ppb.
So the program code is correct but the example printout is not.

Regards
JIm

1 Like

Thanks for pointing this out to us Alex.

It is suppose to be parts per billion so that means there’s a typo in the guide rather than the code.
I’ve let the team here know and we will look into it :slight_smile:

1 Like

Hi! Super cool product. I’m considering trying out this air quality sensor for microbiology applications. Would be buying several of these :slight_smile:

It would be great to see more “high resolution” reads of individual VOC classes - similar to a rough chromatogram (saturated hydrocarbons, aromatic hydrocarbons, esters, etc…)

Do you know if the sensor has the sensitivity to differentiate between classes or variegate reads of different types of VOCs?

Thank you so much!

2 Likes

Hi Mike,

Welcome to the forum! I am going off the sensor’s datasheet. From my understanding it can’t distinguish between different VOCs, I believe the assumption is that the compound is known.

My understanding of how this sensor (and similar ones work) is that the amount of compound in the air affects the sensors internal resistance. The sensor remains unaware of what the compound is in this process but will produce different values based on what it reads.

3 Likes

Thank you very much! Great explanation.

1 Like

I am using this sensor in a weather station project, just looking at overall air quality around the sensor. For the sensor to work properly it takes time to warm up, so to speak. It also requires constant power or it falls back to startup mode.

The sensor draws around 30mA when powered up.

@James46717 that’s right - we cover the warm-up behaviour in the Initial Start-Up and Warm-Up section of the guide.

2 Likes

Wonderful guide, but…How on earth (can you hear my frustration…) did you get the plotter to function?

1 Like

Hi Jane,

Under the view tab, click on plotter and that will show the values as they are printed from the examples.

2 Likes

Thanks, Liam. Unfortunately, this is not working, hence my query. I notice in the support video that the plotter only functions after additional conditional code is input ie to sound an alarm. I am on a Mac. The same happens in the RPi Pico video. Is there additional code I need to input?

Posted this on your other post.
The code is modified to get the plotter to display, it needs values not strings.

# Read air quality metrics from the PiicoDev Air Quality Sensor ENS160
# Shows three metrics: AQI, TVOC and eCO2

from PiicoDev_ENS160 import PiicoDev_ENS160 # import the device driver
from PiicoDev_Unified import sleep_ms       # a cross-platform sleep function

sensor = PiicoDev_ENS160()   # Initialise the ENS160 module

while True:
    # Read from the sensor
    aqi = sensor.aqi.value
    tvoc = sensor.tvoc
    eco2 = sensor.eco2.value
    
#    print('AQI : ',aqi,'TVOC: ',tvoc,'eCO2: ',eco2)
    print('TVOC: ',tvoc,'eCO2: ',eco2)
    
    sleep_ms(500)

Cheers
Jim

1 Like

Thanks for all the help so far. We can see the plotter working away displaying eCO2 and TVOC. However, the best I can do at this stage to capture the data for use is to copy and past the shell data into a spreadsheet and visualise, but it lacks a timestamp. Using Microb:it and Thonny, as described on the micro:bit set up, is there a way to extract data as is shown on this web page?

Hi @Jane278324, Not sure if you forgot to add te link to the last post or not.

For saving data outside of thonny, you will need to look at finding ways to write the data to a file.
There’s some good information out there on how to do this. I think Writing to a CSV (comma-separated value) file is the right way for this kind of data.

The only problem I can see if the MicroBit will likely not have a time sync so adding timestamps to the file could prove to be an interesting challenge.

3 Likes

I’ll look into this, just have to get my Micro:Bits out of storage to test a way to save the data and how they interact with Thonny.

Give me a day or two.
Cheers
Jim

PS In the mean time check this link, it uses block code but shows how to use the Miro:Bit to log data to a file.

2 Likes

@Jane278324 The following code has been tested on a V2 Micro:Bit.

It incorporates logging of the data to the Micro:Bit and printing of the data in Thonny.
It deletes any previous log and creates a new one. Comment out line 12 if this is not wanted.
To update the log display it is necessary to remove the Micro:Bit from the USB port and reattach it.

Once you have run it for a while there will be a HTML file My_Data on the Micro:Bit.
Open the file and a web page appears which shows the data, including a visual representation.
It also has the ability to download the data as a CSV file for import into a spreadsheet.

The Micro:bit does not have a clock and only counts seconds from when it was powered up.
These are used as timestamps in the log data. To improve on this a Real Time Clock module would need to be added.

Change the value of ‘s’ in line 18 to change the rate if 5 seconds is too short.

Cheers
Jim

# Read air quality metrics from the PiicoDev Air Quality Sensor ENS160
# Shows three metrics: AQI, TVOC and eCO2

from PiicoDev_ENS160 import PiicoDev_ENS160                # import the device driver
from microbit import *                                     # import microbit libraries
import log                                                 # import log output library

print('Air Quality Sensor - log')
sensor = PiicoDev_ENS160()                                 # Initialise the ENS160 module

print('Deleting previous log ...')
log.delete(full=True)                                     # delete previous logs

log.set_labels('AQI','TVOC','ECO2',timestamp=log.SECONDS)  # set the column labels
log.set_mirroring(True)                                    # print logs as well as saving them 
log.add(AQI=sensor.aqi.value,TVOC=sensor.tvoc,ECO2=sensor.eco2.value)

@run_every(s=5)                                            # log data every 5, timestamp=log.SECONDS seconds
def log_data():
    log.add(AQI=sensor.aqi.value,TVOC=sensor.tvoc,ECO2=sensor.eco2.value)

while True:
    pass                                                   # loop forever
4 Likes