2024年2月27日发(作者:穰夜天)
Adafruit SGP30 TVOC/eCO2 Gas SensorCreated by lady ada
/adafruit-sgp30-gas-tvoc-eco2-mox-sensorLast updated on 2022-12-01 03:09:00 PM EST©Adafruit IndustriesPage 1 of 22
Table of ContentsOverviewPinouts• Data Pins• Power Pins:36Arduino Test• Wiring• Install Adafruit_SGP30 library• Load Demo• Baseline Set & Get7Arduino Library DocsPython & CircuitPython Test• CircuitPython MicroController Wiring• Python Computer Wiring• CircuitPython Installation of SGP30 Library• Python Installation of SGP30 Library• CircuitPython & Python Usage• Baseline Set & Get1313Python Library DocsDownload• Files:• Schematic STEMMA QT Version• Fabrication Print STEMMA QT Version• Schematic & Fabrication Print Original Version2020©Adafruit IndustriesPage 2 of 22
Overview
Breathe easy with the SGP30 Multi-Pixel Gas Sensor, a fully integrated MOX gassensor. This is a very fine air quality sensor from the sensor experts at Sensirion, withI2C interfacing and fully calibrated output signals with a typical accuracy of 15% withinmeasured values. The SGP combines multiple metal-oxide sensing elements on onechip to provide more detailed air quality is a gas sensor that can detect a wide range of Volatile Organic Compounds(VOCs) and H2 and is intended for indoor air quality monitoring. When connected toyour microcontroller (running our library code) it will return a Total Volatile OrganicCompound (TVOC) reading and an equivalent carbon dioxide reading (eCO2) overI2C.©Adafruit IndustriesPage 3 of 22
The SGP30 has a 'standard' hot-plate MOX sensor, as well as a small microcontrollerthat controls power to the plate, reads the analog voltage, tracks the baselinecalibration, calcluates TVOC and eCO2 values, and provides an I2C interface to readfrom. Unlike the CCS811, this sensor does not require I2C clock stretching.
This part will measure eCO2 (equivalent calculated carbon-dioxide) concentrationwithin a range of 400 to 60,000 parts per million (ppm), and TVOC (Total VolatileOrganic Compound) concentration within a range of 0 to 60,000 parts perbillion (ppb).©Adafruit IndustriesPage 4 of 22
Please note, this sensor, like all VOC/gas sensors, has variability and to get precisemeasurements you will want to calibrate it against known sources! That said, forgeneral environmental sensors, it will give you a good idea of trends and SGP30 does have built in calibration capabilities, note that eCO2 is calculatedbased on H2 concentration, it is not a 'true' CO2 sensor for laboratory r nice element to this sensor is the ability to set humidity compensation forbetter accuracy. An external humidity sensor is required and then the RH% is writtenover I2C to the sensor, so it can better calculate the TVOC/eCO2 values.
Nice sensor right? So we made it easy for you to get right into your next project. Thesurface-mount sensor is soldered onto a custom made PCB in the STEMMA QT formfactor (), making them easy to interface with. The STEMMA QT connectors () on eitherside are compatible with the SparkFun Qwiic () I2C connectors. This allows you tomake solderless connections between your development board and the SGP30 or tochain it with a wide range of other sensors and accessories using a compatible cable ().We’ve of course broken out all the pins to standard headers and added a 1.8V voltageregulator and level shifting so allow you to use it with either 3.3V or 5V systems suchas the Raspberry Pi, or Metro M4 or Arduino Uno.©Adafruit IndustriesPage 5 of 22
Pinouts
©Adafruit IndustriesPage 6 of 22
Power Pins:• Vin - this is the power pin. Since the sensor chip uses 3 VDC for logic, we haveincluded a voltage regulator on board that will take 3-5VDC and safely convert itdown. To power the board, give it the same power as the logic level of yourmicrocontroller - e.g. for a 5V micro like Arduino, use 5V• 1V8 - this is the 1.8V output from the voltage regulator, you can grab up to 50mAfrom this if you like• GND - common ground for power and logicData Pins• SCL - I2C clock pin, connect to your microcontrollers I2C clock line. Can use 3Vor 5V logic, and has a 10K pullup to Vin
• SDA - I2C data pin, connect to your microcontrollers I2C data line. Can use 3V or5V logic, and has a 10K pullup to Vin• STEMMA QT () - These connectors allow you to connectors to dev boards with STEMMA QT connectors or to other things with various associated accessories ()
Arduino Test
You can easily wire this breakout to any microcontroller; we'll be using an Arduino.©Adafruit IndustriesPage 7 of 22
Start by soldering the headers to the SGP30 breakout board. Check out the Adafruitguide to excellent soldering () if you're new to soldering. Then continue on below tolearn how to wire it to a sensor uses I2C address 0x58 and cannot be Connect the SGP30 breakout to your board using an I2C connection. Here's anexample with an Arduino-compatible Metro:©Adafruit IndustriesPage 8 of 22
Board 5V to Sensor Vin (red wire onSTEMMA QT version). (Metro is a 5V logicchip)Board ground / GND to sensor ground /GND (black wire on STEMMA QT version).Board SCL to sensor SCL (yellow wire onSTEMMA QT version).Board SDA to sensor SDA (blue wire onSTEMMA QT version).
Metro Original Fritzing FileInstall Adafruit_SGP30 libraryTo begin reading sensor data, you will need to install the Adafruit_SGP30 library(code on our github repository) (). It is available from the Arduino library manager sowe recommend using that.©Adafruit IndustriesPage 9 of 22
From the IDE open up the
And type in adafruit sgp30 to locate the library. Click Install
Load DemoOpen up File->Examples->Adafruit_SGP30->sgp30test and upload to yourmicrocontroller wired up to the sensor
Then open up the serial console at 115200 baud, you'll see the serial number printedout - this is a unique 48-bit number burned into each chip. Since you may want to doper-chip calibration, this can help keep your calibration detail separate©Adafruit IndustriesPage 10 of 22
The first 10-20 readings will always be
TVOC 0 ppb eCO2 400 ppm. That's becausethe sensor is warming up, so it will have 'null' a few seconds, you will see the TVOC and eCO2 readings fluctuate:
Every minute or so you'll also get a Baseline value printed out. More about that later!You can take a bit of alcohol on a swap and swipe it nearby to get the readings tospike©Adafruit IndustriesPage 11 of 22
That's it! The sensor pretty much only does that - all the calculations for the TVOC andeCO2 are done within the sensor itself, no other data is exposed beyond the'baseline' valuesBaseline Set & GetAll VOC/gas sensors use the same underlying technology: a tin oxide element that,when exposed to organic compounds, changes resistance. The 'problem' with thesesensors is that the baseline changes, often with humidity, temperature, and other non-gas-related-events. To keep the values coming out reasonable, you'll need tocalibrate the no stored baseline is available after initializing the baseline algorithm,the sensor has to run for 12 hours until the baseline can be stored. This willensure an optimal behavior for the next time it starts up. Reading out thebaseline prior should be avoided unless a valid baseline is restored the baseline is properly initialized or restored, the current baselinevalue should be stored approximately once per hour. While the sensor isoff, baseline values are valid for a maximum of seven ting the sensor without reading back a previously stored baselinewill result in the sensor trying to determine a new baseline. Theadjustement algorithm will be accelerated for 12hrs which is the Maximumtime required to find a new sensor adjusts to the best value it has been exposed to. So keeping itindoors the sensor thinks this is the best value and sets it to ~0ppb tVOCand 400ppm CO2eq. As soon as you expose the sensor to outside air itcan adjust to the global H2 Background Signal. For normal Operationexposing the sensor to outside air for 10min cumulative time should besufficient.©Adafruit IndustriesPage 12 of 22
If you're experienced with sensors that don't have a baseline, you eitherwon't be able to measure absolute values or you'll have to implement yourown baseline sensor to sensor variation of SGP30 in terms of sensitivity is very goodas each of them is calibrated. But the baseline has to be determined foreach sensor individually during the first make that easy, SGP lets you query the 'baseline calibration readings' from thesensor with code like this:uint16_t TVOC_base, eCO2_base;Baseline(&eCO2_base, &TVOC_base);This will grab the two 16-bit sensor calibration words and place them in the should store these in EEPROM, FLASH or hard-coded. Then, next time you startup the sensor, you can pre-fill the calibration words with
Baseline(eCO2_baseline, TVOC_baseline);Arduino Library Docs
Arduino Library Docs ()
Python & CircuitPython Test
It's easy to use the SGP30 sensor with Python or CircuitPython and the AdafruitCircuitPython SGP30 () module. This module allows you to easily write Python codethat reads the TVOC, eCO2, and more from the can use this sensor with any CircuitPython microcontroller board or with acomputer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library ().CircuitPython MicroController WiringConnect the SGP30 breakout to your board using an I2C connection, exactly asshown on the previous page for Arduino. Here's an example with a Feather M0:©Adafruit IndustriesPage 13 of 22
Board 3.3V to sensor Vin (red wire onSTEMMA QT version) (Feather is 3.3Vlogic)Board ground / GND to sensor ground /GND (black wire on STEMMA QT version).Board SCL to sensor SCL (yellow wire onSTEMMA QT version).Board SDA to sensor SDA (blue wire onSTEMMA QT version).
Feather Original Fritzing filePython Computer WiringSince there's dozens of Linux computers/boards you can use we will show wiring forRaspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux tosee whether your platform is supported (). ©Adafruit IndustriesPage 14 of 22
Here's the Raspberry Pi wired with I2C:
Pi 3V3 to sensor VIN (red wire on STEMMAQT version)Pi GND to sensor GND (black wire onSTEMMA QT version)Pi SCL to sensor SCL (yellow wire onSTEMMA QT version)Pi SDA to sensor SDA (blue wire onSTEMMA QT version)
CircuitPython Installation of SGP30 LibraryTo use the SGP30 you'll need to install the Adafruit CircuitPython SGP30 () library onyour CircuitPython board.©Adafruit IndustriesPage 15 of 22
First make sure you are running the latest version of Adafruit CircuitPython () for you'll need to install the necessary libraries to use the hardware--carefully followthe steps to find and install these libraries from Adafruit's CircuitPython library bundle (). Our introduction guide has a great page on how to install the library bundle () forboth express and non-express er for non-express boards like the, you'll need to manually install thenecessary libraries from the bundle:• adafruit_• adafruit_bus_deviceYou can also download the adafruit_ from its releases page on Github ().Before continuing make sure your board's lib folder or root filesystem has the adafruit_, and adafruit_bus_device files and folders copied connect to the board's serial REPL ()so you are at the CircuitPython >>> Installation of SGP30 LibraryYou'll need to install the Adafruit_Blinka library that provides the CircuitPythonsupport in Python. This may also require enabling I2C on your platform and verifyingyou are running Python 3. Since each platform is a little different, and Linux changesoften, please visit the CircuitPython on Linux guide to get your computer ready ()!Once that's done, from your command line run the following command:•
sudo pip3 install adafruit-circuitpython-sgp30If your default Python is version 3 you may need to run 'pip' instead. Just make sureyou aren't trying to use CircuitPython on Python 2.x, it isn't supported!©Adafruit IndustriesPage 16 of 22
CircuitPython & Python UsageTo demonstrate the usage of the sensor we'll initialize it and read the eCO2 andTVOC data and print it to the REPLSave this example sketch as on your CircuitPython board:# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries# SPDX-License-Identifier: MIT""" Example for using the SGP30 with CircuitPython and the Adafruit library"""import timeimport boardimport busioimport adafruit_sgp30i2c = busio.I2C(, , frequency=100000)# Create library object on our I2C portsgp30 = adafruit_it_SGP30(i2c)print("SGP30 serial #", [hex(i) for i in ])_iaq_baseline(0x8973, 0x8AAE)_iaq_relative_humidity(celsius=22.1, relative_humidity=44)elapsed_sec = 0while True: print("eCO2 = %d ppm t TVOC = %d ppb" % (2, )) (1) elapsed_sec += 1 if elapsed_sec > 10: elapsed_sec = 0 print( "**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x" % (ne_eCO2, ne_TVOC) )In the REPL you'll see the serial number printed out:
[0x0, 0x64, 0xb878] in thiscase. This is a unique 48-bit number burned into each chip. Since you may want to doper-chip calibration, this can help keep your calibration detail separate©Adafruit IndustriesPage 17 of 22
The first 10-20 readings will always be
eCO2 400 ppm
TVOC 0 ppb
. That'sbecause the sensor is warming up, so it will have 'null' a few seconds, you will see the TVOC and eCO2 readings fluctuateEvery minute or so you'll also get a Baseline value printed out. More about that later!You can take a bit of alcohol on a swap and swipe it nearby to get the readings tospike
That's it! The sensor pretty much only does that - all the calculations for the TVOC andeCO2 are done within the sensor itself, no other data is exposed beyond the'baseline' valuesBaseline Set & GetAll VOC/gas sensors use the same underlying technology: a tin oxide element that,when exposed to organic compounds, changes resistance. The 'problem' with thesesensors is that the baseline changes, often with humidity, temperature, and other non-©Adafruit IndustriesPage 18 of 22
gas-related-events. To keep the values coming out reasonable, you'll need tocalibrate the no stored baseline is available after initializing the baseline algorithm,the sensor has to run for 12 hours until the baseline can be stored. This willensure an optimal behavior for preceding startups. Reading out thebaseline prior should be avoided unless a valid baseline is restored the baseline is properly initialized or restored, the current baselinevalue should be stored approximately once per hour. While the sensor isoff, baseline values are valid for a maximum of seven ting the sensor without reading back a previously stored baselinewill result in the sensor trying to determine a new baseline. Theadjustement algorithm will be accelerated for 12hrs which is the Maximumtime required to find a new sensor adjusts to the best value it has been exposed to. So keeping itindoors the sensor thinks this is the best value and sets it to ~0ppb tVOCand 400ppm CO2eq. As soon as you expose the sensor to outside air itcan adjust to the global H2 Background Signal. For normal Operationexposing the sensor to outside air for 10min cumulative time should you're experienced with sensors that don't have a baseline, you eitherwon't be able to measure absolute values or you'll have to implement yourown baseline sensor to sensor variation of SGP30 in terms of sensitivity is very goodas each of them is calibrated. But the baseline has to be determined foreach sensor individually during the first make that easy, SGP lets you query the 'baseline calibration readings' from thesensor with code like this:co2eq_base, tvoc_base = ne_co2eq, ne_tvocThis will grab the two 16-bit sensor calibration words and place them in the should store these in EEPROM, FLASH or hard-coded. Then, next time you startup the sensor, you can pre-fill the calibration wordswith _iaq_baseline(co2eq_base, tvoc_base)©Adafruit IndustriesPage 19 of 22
Python Library Docs
Python Library Docs ()
Download
Files:• SGP30 Datasheet ()
• Fritzing object in Adafruit Fritzing library ()
• EagleCAD files on GitHub ()
Schematic STEMMA QT Version
Page 20 of 22©Adafruit Industries
Fabrication Print STEMMA QT Version
Schematic & Fabrication Print OriginalVersion
Page 21 of 22©Adafruit Industries
Page 22 of 22©Adafruit Industries
2024年2月27日发(作者:穰夜天)
Adafruit SGP30 TVOC/eCO2 Gas SensorCreated by lady ada
/adafruit-sgp30-gas-tvoc-eco2-mox-sensorLast updated on 2022-12-01 03:09:00 PM EST©Adafruit IndustriesPage 1 of 22
Table of ContentsOverviewPinouts• Data Pins• Power Pins:36Arduino Test• Wiring• Install Adafruit_SGP30 library• Load Demo• Baseline Set & Get7Arduino Library DocsPython & CircuitPython Test• CircuitPython MicroController Wiring• Python Computer Wiring• CircuitPython Installation of SGP30 Library• Python Installation of SGP30 Library• CircuitPython & Python Usage• Baseline Set & Get1313Python Library DocsDownload• Files:• Schematic STEMMA QT Version• Fabrication Print STEMMA QT Version• Schematic & Fabrication Print Original Version2020©Adafruit IndustriesPage 2 of 22
Overview
Breathe easy with the SGP30 Multi-Pixel Gas Sensor, a fully integrated MOX gassensor. This is a very fine air quality sensor from the sensor experts at Sensirion, withI2C interfacing and fully calibrated output signals with a typical accuracy of 15% withinmeasured values. The SGP combines multiple metal-oxide sensing elements on onechip to provide more detailed air quality is a gas sensor that can detect a wide range of Volatile Organic Compounds(VOCs) and H2 and is intended for indoor air quality monitoring. When connected toyour microcontroller (running our library code) it will return a Total Volatile OrganicCompound (TVOC) reading and an equivalent carbon dioxide reading (eCO2) overI2C.©Adafruit IndustriesPage 3 of 22
The SGP30 has a 'standard' hot-plate MOX sensor, as well as a small microcontrollerthat controls power to the plate, reads the analog voltage, tracks the baselinecalibration, calcluates TVOC and eCO2 values, and provides an I2C interface to readfrom. Unlike the CCS811, this sensor does not require I2C clock stretching.
This part will measure eCO2 (equivalent calculated carbon-dioxide) concentrationwithin a range of 400 to 60,000 parts per million (ppm), and TVOC (Total VolatileOrganic Compound) concentration within a range of 0 to 60,000 parts perbillion (ppb).©Adafruit IndustriesPage 4 of 22
Please note, this sensor, like all VOC/gas sensors, has variability and to get precisemeasurements you will want to calibrate it against known sources! That said, forgeneral environmental sensors, it will give you a good idea of trends and SGP30 does have built in calibration capabilities, note that eCO2 is calculatedbased on H2 concentration, it is not a 'true' CO2 sensor for laboratory r nice element to this sensor is the ability to set humidity compensation forbetter accuracy. An external humidity sensor is required and then the RH% is writtenover I2C to the sensor, so it can better calculate the TVOC/eCO2 values.
Nice sensor right? So we made it easy for you to get right into your next project. Thesurface-mount sensor is soldered onto a custom made PCB in the STEMMA QT formfactor (), making them easy to interface with. The STEMMA QT connectors () on eitherside are compatible with the SparkFun Qwiic () I2C connectors. This allows you tomake solderless connections between your development board and the SGP30 or tochain it with a wide range of other sensors and accessories using a compatible cable ().We’ve of course broken out all the pins to standard headers and added a 1.8V voltageregulator and level shifting so allow you to use it with either 3.3V or 5V systems suchas the Raspberry Pi, or Metro M4 or Arduino Uno.©Adafruit IndustriesPage 5 of 22
Pinouts
©Adafruit IndustriesPage 6 of 22
Power Pins:• Vin - this is the power pin. Since the sensor chip uses 3 VDC for logic, we haveincluded a voltage regulator on board that will take 3-5VDC and safely convert itdown. To power the board, give it the same power as the logic level of yourmicrocontroller - e.g. for a 5V micro like Arduino, use 5V• 1V8 - this is the 1.8V output from the voltage regulator, you can grab up to 50mAfrom this if you like• GND - common ground for power and logicData Pins• SCL - I2C clock pin, connect to your microcontrollers I2C clock line. Can use 3Vor 5V logic, and has a 10K pullup to Vin
• SDA - I2C data pin, connect to your microcontrollers I2C data line. Can use 3V or5V logic, and has a 10K pullup to Vin• STEMMA QT () - These connectors allow you to connectors to dev boards with STEMMA QT connectors or to other things with various associated accessories ()
Arduino Test
You can easily wire this breakout to any microcontroller; we'll be using an Arduino.©Adafruit IndustriesPage 7 of 22
Start by soldering the headers to the SGP30 breakout board. Check out the Adafruitguide to excellent soldering () if you're new to soldering. Then continue on below tolearn how to wire it to a sensor uses I2C address 0x58 and cannot be Connect the SGP30 breakout to your board using an I2C connection. Here's anexample with an Arduino-compatible Metro:©Adafruit IndustriesPage 8 of 22
Board 5V to Sensor Vin (red wire onSTEMMA QT version). (Metro is a 5V logicchip)Board ground / GND to sensor ground /GND (black wire on STEMMA QT version).Board SCL to sensor SCL (yellow wire onSTEMMA QT version).Board SDA to sensor SDA (blue wire onSTEMMA QT version).
Metro Original Fritzing FileInstall Adafruit_SGP30 libraryTo begin reading sensor data, you will need to install the Adafruit_SGP30 library(code on our github repository) (). It is available from the Arduino library manager sowe recommend using that.©Adafruit IndustriesPage 9 of 22
From the IDE open up the
And type in adafruit sgp30 to locate the library. Click Install
Load DemoOpen up File->Examples->Adafruit_SGP30->sgp30test and upload to yourmicrocontroller wired up to the sensor
Then open up the serial console at 115200 baud, you'll see the serial number printedout - this is a unique 48-bit number burned into each chip. Since you may want to doper-chip calibration, this can help keep your calibration detail separate©Adafruit IndustriesPage 10 of 22
The first 10-20 readings will always be
TVOC 0 ppb eCO2 400 ppm. That's becausethe sensor is warming up, so it will have 'null' a few seconds, you will see the TVOC and eCO2 readings fluctuate:
Every minute or so you'll also get a Baseline value printed out. More about that later!You can take a bit of alcohol on a swap and swipe it nearby to get the readings tospike©Adafruit IndustriesPage 11 of 22
That's it! The sensor pretty much only does that - all the calculations for the TVOC andeCO2 are done within the sensor itself, no other data is exposed beyond the'baseline' valuesBaseline Set & GetAll VOC/gas sensors use the same underlying technology: a tin oxide element that,when exposed to organic compounds, changes resistance. The 'problem' with thesesensors is that the baseline changes, often with humidity, temperature, and other non-gas-related-events. To keep the values coming out reasonable, you'll need tocalibrate the no stored baseline is available after initializing the baseline algorithm,the sensor has to run for 12 hours until the baseline can be stored. This willensure an optimal behavior for the next time it starts up. Reading out thebaseline prior should be avoided unless a valid baseline is restored the baseline is properly initialized or restored, the current baselinevalue should be stored approximately once per hour. While the sensor isoff, baseline values are valid for a maximum of seven ting the sensor without reading back a previously stored baselinewill result in the sensor trying to determine a new baseline. Theadjustement algorithm will be accelerated for 12hrs which is the Maximumtime required to find a new sensor adjusts to the best value it has been exposed to. So keeping itindoors the sensor thinks this is the best value and sets it to ~0ppb tVOCand 400ppm CO2eq. As soon as you expose the sensor to outside air itcan adjust to the global H2 Background Signal. For normal Operationexposing the sensor to outside air for 10min cumulative time should besufficient.©Adafruit IndustriesPage 12 of 22
If you're experienced with sensors that don't have a baseline, you eitherwon't be able to measure absolute values or you'll have to implement yourown baseline sensor to sensor variation of SGP30 in terms of sensitivity is very goodas each of them is calibrated. But the baseline has to be determined foreach sensor individually during the first make that easy, SGP lets you query the 'baseline calibration readings' from thesensor with code like this:uint16_t TVOC_base, eCO2_base;Baseline(&eCO2_base, &TVOC_base);This will grab the two 16-bit sensor calibration words and place them in the should store these in EEPROM, FLASH or hard-coded. Then, next time you startup the sensor, you can pre-fill the calibration words with
Baseline(eCO2_baseline, TVOC_baseline);Arduino Library Docs
Arduino Library Docs ()
Python & CircuitPython Test
It's easy to use the SGP30 sensor with Python or CircuitPython and the AdafruitCircuitPython SGP30 () module. This module allows you to easily write Python codethat reads the TVOC, eCO2, and more from the can use this sensor with any CircuitPython microcontroller board or with acomputer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library ().CircuitPython MicroController WiringConnect the SGP30 breakout to your board using an I2C connection, exactly asshown on the previous page for Arduino. Here's an example with a Feather M0:©Adafruit IndustriesPage 13 of 22
Board 3.3V to sensor Vin (red wire onSTEMMA QT version) (Feather is 3.3Vlogic)Board ground / GND to sensor ground /GND (black wire on STEMMA QT version).Board SCL to sensor SCL (yellow wire onSTEMMA QT version).Board SDA to sensor SDA (blue wire onSTEMMA QT version).
Feather Original Fritzing filePython Computer WiringSince there's dozens of Linux computers/boards you can use we will show wiring forRaspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux tosee whether your platform is supported (). ©Adafruit IndustriesPage 14 of 22
Here's the Raspberry Pi wired with I2C:
Pi 3V3 to sensor VIN (red wire on STEMMAQT version)Pi GND to sensor GND (black wire onSTEMMA QT version)Pi SCL to sensor SCL (yellow wire onSTEMMA QT version)Pi SDA to sensor SDA (blue wire onSTEMMA QT version)
CircuitPython Installation of SGP30 LibraryTo use the SGP30 you'll need to install the Adafruit CircuitPython SGP30 () library onyour CircuitPython board.©Adafruit IndustriesPage 15 of 22
First make sure you are running the latest version of Adafruit CircuitPython () for you'll need to install the necessary libraries to use the hardware--carefully followthe steps to find and install these libraries from Adafruit's CircuitPython library bundle (). Our introduction guide has a great page on how to install the library bundle () forboth express and non-express er for non-express boards like the, you'll need to manually install thenecessary libraries from the bundle:• adafruit_• adafruit_bus_deviceYou can also download the adafruit_ from its releases page on Github ().Before continuing make sure your board's lib folder or root filesystem has the adafruit_, and adafruit_bus_device files and folders copied connect to the board's serial REPL ()so you are at the CircuitPython >>> Installation of SGP30 LibraryYou'll need to install the Adafruit_Blinka library that provides the CircuitPythonsupport in Python. This may also require enabling I2C on your platform and verifyingyou are running Python 3. Since each platform is a little different, and Linux changesoften, please visit the CircuitPython on Linux guide to get your computer ready ()!Once that's done, from your command line run the following command:•
sudo pip3 install adafruit-circuitpython-sgp30If your default Python is version 3 you may need to run 'pip' instead. Just make sureyou aren't trying to use CircuitPython on Python 2.x, it isn't supported!©Adafruit IndustriesPage 16 of 22
CircuitPython & Python UsageTo demonstrate the usage of the sensor we'll initialize it and read the eCO2 andTVOC data and print it to the REPLSave this example sketch as on your CircuitPython board:# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries# SPDX-License-Identifier: MIT""" Example for using the SGP30 with CircuitPython and the Adafruit library"""import timeimport boardimport busioimport adafruit_sgp30i2c = busio.I2C(, , frequency=100000)# Create library object on our I2C portsgp30 = adafruit_it_SGP30(i2c)print("SGP30 serial #", [hex(i) for i in ])_iaq_baseline(0x8973, 0x8AAE)_iaq_relative_humidity(celsius=22.1, relative_humidity=44)elapsed_sec = 0while True: print("eCO2 = %d ppm t TVOC = %d ppb" % (2, )) (1) elapsed_sec += 1 if elapsed_sec > 10: elapsed_sec = 0 print( "**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x" % (ne_eCO2, ne_TVOC) )In the REPL you'll see the serial number printed out:
[0x0, 0x64, 0xb878] in thiscase. This is a unique 48-bit number burned into each chip. Since you may want to doper-chip calibration, this can help keep your calibration detail separate©Adafruit IndustriesPage 17 of 22
The first 10-20 readings will always be
eCO2 400 ppm
TVOC 0 ppb
. That'sbecause the sensor is warming up, so it will have 'null' a few seconds, you will see the TVOC and eCO2 readings fluctuateEvery minute or so you'll also get a Baseline value printed out. More about that later!You can take a bit of alcohol on a swap and swipe it nearby to get the readings tospike
That's it! The sensor pretty much only does that - all the calculations for the TVOC andeCO2 are done within the sensor itself, no other data is exposed beyond the'baseline' valuesBaseline Set & GetAll VOC/gas sensors use the same underlying technology: a tin oxide element that,when exposed to organic compounds, changes resistance. The 'problem' with thesesensors is that the baseline changes, often with humidity, temperature, and other non-©Adafruit IndustriesPage 18 of 22
gas-related-events. To keep the values coming out reasonable, you'll need tocalibrate the no stored baseline is available after initializing the baseline algorithm,the sensor has to run for 12 hours until the baseline can be stored. This willensure an optimal behavior for preceding startups. Reading out thebaseline prior should be avoided unless a valid baseline is restored the baseline is properly initialized or restored, the current baselinevalue should be stored approximately once per hour. While the sensor isoff, baseline values are valid for a maximum of seven ting the sensor without reading back a previously stored baselinewill result in the sensor trying to determine a new baseline. Theadjustement algorithm will be accelerated for 12hrs which is the Maximumtime required to find a new sensor adjusts to the best value it has been exposed to. So keeping itindoors the sensor thinks this is the best value and sets it to ~0ppb tVOCand 400ppm CO2eq. As soon as you expose the sensor to outside air itcan adjust to the global H2 Background Signal. For normal Operationexposing the sensor to outside air for 10min cumulative time should you're experienced with sensors that don't have a baseline, you eitherwon't be able to measure absolute values or you'll have to implement yourown baseline sensor to sensor variation of SGP30 in terms of sensitivity is very goodas each of them is calibrated. But the baseline has to be determined foreach sensor individually during the first make that easy, SGP lets you query the 'baseline calibration readings' from thesensor with code like this:co2eq_base, tvoc_base = ne_co2eq, ne_tvocThis will grab the two 16-bit sensor calibration words and place them in the should store these in EEPROM, FLASH or hard-coded. Then, next time you startup the sensor, you can pre-fill the calibration wordswith _iaq_baseline(co2eq_base, tvoc_base)©Adafruit IndustriesPage 19 of 22
Python Library Docs
Python Library Docs ()
Download
Files:• SGP30 Datasheet ()
• Fritzing object in Adafruit Fritzing library ()
• EagleCAD files on GitHub ()
Schematic STEMMA QT Version
Page 20 of 22©Adafruit Industries
Fabrication Print STEMMA QT Version
Schematic & Fabrication Print OriginalVersion
Page 21 of 22©Adafruit Industries
Page 22 of 22©Adafruit Industries