// SGP30 Air Quality Sensor demo // Initalises connection, retrieves unique chip ID, starts measurement. // Call returns immediately so that air quality can be measured every second. // After 30 seconds, resets the chip, and restarts measurement, // but that call waits up to 20 seconds for the readings to start being useful. // Reports status and results to Serial connection on GPIO 0 and 1. #include #include #include "pico/stdlib.h" #include "breakout_sgp30.hpp" using namespace pimoroni; BreakoutSGP30 sgp30; int main() { uint8_t prd; uint16_t eCO2, TVOC; uint16_t raweCO2, rawTVOC; uint16_t baseCO2, baseTVOC; gpio_init(PICO_DEFAULT_LED_PIN); gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); stdio_init_all(); bool init_ok = sgp30.init(); if(init_ok) { printf("SGP30 initialised - about to start measuring without waiting\n"); sgp30.start_measurement(false); printf("Started measuring for id %012llx\n", sgp30.get_unique_id()); if(sgp30.get_air_quality(&eCO2, &TVOC)) { prd = 1; } else { printf("SGP30 not found when reading air quality\n"); prd = 2; } } else { printf("SGP30 not found when initialising\n"); prd = 3; } uint16_t j = 0; while(true) { j++; for(uint8_t i=0; i