i2c pyb or machine for sgp30 adafruit sensor?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
boadeletrius
Posts: 4
Joined: Fri Jun 18, 2021 2:03 am

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by boadeletrius » Sun Jun 20, 2021 7:42 am

In case anyone else wants to use this sensor. This post was very useful for getting the SGP30 working with the current Micropython version on an esp8266. A quick summary:

Use the driver from here: https://github.com/alexmrqt/micropython-sgp30
modify line 54 from

Code: Select all

_SGP30_FEATURESET        = const(0x0020)
to this:

Code: Select all

_SGP30_FEATURESET        = const(0x0022)

Code: Select all

import machine
import adafruit_sgp30
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4), freq=100000)
i2c.init(scl=machine.Pin(5), sda=machine.Pin(4))
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
co2eq, tvoc = sgp30.iaq_measure()
print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))

ChrisPook
Posts: 1
Joined: Fri Oct 22, 2021 6:13 am

Re: i2c pyb or machine for sgp30 adafruit sensor?

Post by ChrisPook » Fri Oct 22, 2021 6:19 am

Thanks a lot, @IHOXOHI. Your contribution helped me get the SGP30 shield working on a LOLIN Mini D1.
I started with this library: https://github.com/alexmrqt/micropython-sgp30

I made the change you suggested:
"_SGP30_FEATURESET = const(0x0020)" by "_SGP30_FEATURESET = const(0x0022)"
Then I used some trial-and-error to work out the following code:

Code: Select all

import adafruit_sgp30
from machine import I2C, Pin

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
sgp = adafruit_sgp30.Adafruit_SGP30(i2c)
co2eq, tvoc = sgp.iaq_measure()
print("CO2eq = %d ppm \t TVOC = %d ppb" % (co2eq, tvoc))

Post Reply