Did you ever figure this out?
I can get the SGP30 to work with n Arduino Sketch but not in ESPHome on an M5 Core 2.
Here is the sketch
#include <M5Core2.h>
//SGP30 needs 15 seconds to initialize calibration after power on.
//The screen will display TVOC and CO2
#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;
int i = 15;
long last_millis = 0;
void header(const char *string, uint16_t color)
{
M5.Lcd.fillScreen(color);
M5.Lcd.setTextSize(1);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLACK);
M5.Lcd.setTextDatum(TC_DATUM);
M5.Lcd.drawString(string, 160, 3, 4);
}
void setup() {
M5.begin(true, false, true, true);
header("SGP30 TEST",TFT_BLACK);
Serial.println("SGP30 test");
if (! sgp.begin()){
Serial.println("Sensor not found :(");
while (1);
}
M5.Lcd.drawString("TVOC:", 50, 40, 4);
M5.Lcd.drawString("eCO2:", 50, 80, 4);
Serial.print("Found SGP30 serial #");
Serial.print(sgp.serialnumber[0], HEX);
Serial.print(sgp.serialnumber[1], HEX);
Serial.println(sgp.serialnumber[2], HEX);
M5.Lcd.drawString("Initialization...", 140, 120, 4);
}
void loop() {
while(i > 0) {
if(millis()- last_millis > 1000) {
last_millis = millis();
i--;
M5.Lcd.fillRect(198, 120, 40, 20, TFT_BLACK);
M5.Lcd.drawNumber(i, 20, 120, 4);
}
}
M5.Lcd.fillRect(0, 120, 300, 30, TFT_BLACK);
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
M5.Lcd.fillRect(100, 40, 220, 90, TFT_BLACK);
M5.Lcd.drawNumber(sgp.TVOC, 120, 40 , 4);
M5.Lcd.drawString("ppb", 200, 40, 4);
M5.Lcd.drawNumber(sgp.eCO2, 120, 80, 4);
M5.Lcd.drawString("ppm", 200, 80, 4);
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
delay(1000);
}
In ESPHome I get this
[11:10:34][C][i2c.arduino:052]: I2C Bus:
[11:10:34][C][i2c.arduino:053]: SDA Pin: GPIO21
[11:10:34][C][i2c.arduino:054]: SCL Pin: GPIO22
[11:10:34][C][i2c.arduino:055]: Frequency: 400000 Hz
[11:10:34][C][i2c.arduino:058]: Recovery: bus successfully recovered
[11:10:34][I][i2c.arduino:068]: Results from i2c bus scan:
[11:10:34][I][i2c.arduino:074]: Found i2c device at address 0x34
[11:10:34][I][i2c.arduino:074]: Found i2c device at address 0x51
[11:10:34][I][i2c.arduino:074]: Found i2c device at address 0x68
[11:10:34][C][sgp30:220]: SGP30:
[11:10:34][C][sgp30:221]: Address: 0x58
[11:10:34][W][sgp30:237]: Unknown setup error!
[11:10:34][C][sgp30:251]: Update Interval: 3.0s
[11:10:34][C][sgp30:252]: eCO2 sensor 'eCO2'
[11:10:34][C][sgp30:252]: Device Class: 'carbon_dioxide'
[11:10:34][C][sgp30:252]: State Class: 'measurement'
[11:10:34][C][sgp30:252]: Unit of Measurement: 'ppm'
[11:10:34][C][sgp30:252]: Accuracy Decimals: 1
[11:10:34][C][sgp30:252]: Icon: 'mdi:molecule-co2'
[11:10:34][C][sgp30:253]: TVOC sensor 'TVOC'
[11:10:34][C][sgp30:253]: Device Class: 'volatile_organic_compounds'
[11:10:34][C][sgp30:253]: State Class: 'measurement'
[11:10:34][C][sgp30:253]: Unit of Measurement: 'ppb'
[11:10:34][C][sgp30:253]: Accuracy Decimals: 1
[11:10:34][C][sgp30:253]: Icon: 'mdi:radiator'
Here is my yaml
esphome:
name: "esphome-m5stack-core-1"
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
spi:
clk_pin: 18
mosi_pin: 23
miso_pin: 38
i2c:
- id: bus_a
sda: 21
scl: 22
scan: true
frequency: 400 kHz
sensor:
- platform: sgp30
i2c_id: bus_a
eco2:
name: "eCO2"
accuracy_decimals: 1
id: eco2
tvoc:
name: "TVOC"
accuracy_decimals: 1
id: tvoc
update_interval: 3s
baseline:
eco2_baseline: 0x92B7
tvoc_baseline: 0x935A