Waveshare Pico Environment Sensor Sample
THP: BME280, I2C temperature, humidity and air pressure sensor
VOC: SGP40, I2C digital multipixel gas sensor
DOF: ICM-20948 (MPU-9250), I2C accelerometer, gyroscope and magnetometer
Description
This sample application periodically measures the ambient temperature, humidity and air pressure from the THP device, a raw gas sensor value from the VOC device and the chip temperature, acceleration, angular velocity and the terrestrial magnetism in all XYZ spatial coordinates from the DOF device. The result is written to the console along with the time since startup.
You can choose to use the on-chip T/RH compensation of the SGP40 by feeding the
values measured by the BME280 into it. This is enabled in the Application by
default, you can turn it off by setting APP_USE_COMPENSATION=n
.
References
Wiring
This sample uses all sensors controlled by using the I2C interface.
connect supply: VDD, GND
and interface: SDA, SCL.
The supply voltage can be in the 1.7V to 3.6V range. Depending on the baseboard used, the SDA and SCL lines require Pull-Up resistors.
Building and Running
This project outputs sensor data to the console. It requires a BME280, a SGP40 and a ICM-20948 (MPU-9250) sensor. It should work with any platform featuring a I2C peripheral interface. This example is usable with the Devicetree overlay that comes with the Waveshare Pico Environment Sensor shield for the Raspberry Pi Pico board.
west build -b rpi_pico -p -S usb-console --shield waveshare_pico_environment_sensor -d build/waveshare_pico_environment_sensor bridle/samples/waveshare_pico_environment_sensor
west flash -r uf2 -d build/waveshare_pico_environment_sensor
Sample Output
[00:00:00.001,000] <dbg> BME280: bme280_chip_init: ID OK [00:00:00.010,000] <dbg> BME280: bme280_chip_init: "bme280@76" OK [00:00:00.260,000] <dbg> SGP40: sgp40_init: Selftest succeeded! [00:00:00.325,000] <dbg> MPU9250: ak8963_fetch_adj: Adjustment values 1774 1774 1709 ***** delaying boot 4000ms (per build configuration) ***** [00:00:00.627,000] <wrn> udc_rpi: BUS RESET [00:00:00.707,000] <wrn> udc_rpi: BUS RESET *** Booting Zephyr OS build v4.0.99… (delayed boot 4000ms) *** [00:00:04.337,000] <inf> wspes_sample: ICM20948: Found device "mpu9250@68", getting sensor data [00:00:04.337,000] <inf> wspes_sample: BME280: Found device "bme280@76", getting sensor data [00:00:04.337,000] <inf> wspes_sample: SGP40: Found device "sgp40@59", getting sensor data [00:00:06.339,000] <dbg> MPU9250: mpu9250_sample_fetch: magn_st2: 16 [00:00:06.372,000] <inf> wspes_sample: DOF: 0.287304 0.171783 -9.950303 XYZ-Accel. [m/s/s] [00:00:06.372,000] <inf> wspes_sample: DOF: 0.018785 -0.001732 0.007993 XYZ-Gyro. [rad/s] [00:00:06.373,000] <inf> wspes_sample: DOF: 0.051446 0.952638 -0.941659 XYZ-Magn. [uG] [00:00:06.373,000] <inf> wspes_sample: DOF: 29.30 Temp. [C] [00:00:06.373,000] <inf> wspes_sample: THP: 101.31 AirPr. [hPa] [00:00:06.373,000] <inf> wspes_sample: THP: 26.50 Temp. [C] [00:00:06.373,000] <inf> wspes_sample: THP: 51.318 RH [%] [00:00:06.373,000] <inf> wspes_sample: VOC: 20 Gas [a.u.] [00:00:08.375,000] <dbg> MPU9250: mpu9250_sample_fetch: magn_st2: 16 [00:00:08.407,000] <inf> wspes_sample: DOF: 0.303465 0.171185 -9.943719 XYZ-Accel. [m/s/s] [00:00:08.408,000] <inf> wspes_sample: DOF: 0.018519 -0.000666 0.007460 XYZ-Gyro. [rad/s] [00:00:08.408,000] <inf> wspes_sample: DOF: 0.053220 0.954412 -0.936532 XYZ-Magn. [uG] [00:00:08.408,000] <inf> wspes_sample: DOF: 29.41 Temp. [C] [00:00:08.408,000] <inf> wspes_sample: THP: 101.31 AirPr. [hPa] [00:00:08.408,000] <inf> wspes_sample: THP: 26.53 Temp. [C] [00:00:08.408,000] <inf> wspes_sample: THP: 51.238 RH [%] [00:00:08.408,000] <inf> wspes_sample: VOC: 28285 Gas [a.u.] [00:00:10.410,000] <dbg> MPU9250: mpu9250_sample_fetch: magn_st2: 16 [00:00:10.483,000] <inf> wspes_sample: DOF: 0.286705 0.164002 -9.949105 XYZ-Accel. [m/s/s] [00:00:10.483,000] <inf> wspes_sample: DOF: 0.019584 -0.000932 0.008393 XYZ-Gyro. [rad/s] [00:00:10.483,000] <inf> wspes_sample: DOF: 0.047898 0.956186 -0.938241 XYZ-Magn. [uG] [00:00:10.483,000] <inf> wspes_sample: DOF: 29.49 Temp. [C] [00:00:10.483,000] <inf> wspes_sample: THP: 101.31 AirPr. [hPa] [00:00:10.483,000] <inf> wspes_sample: THP: 26.60 Temp. [C] [00:00:10.484,000] <inf> wspes_sample: THP: 51.062 RH [%] [00:00:10.484,000] <inf> wspes_sample: VOC: 28789 Gas [a.u.]
The SGP40 Datasheet states that the raw sensor signal for the SGP40 is proportional to the logarithm of the sensors resistance, hence the VOC Gas value is labeled as [a.u.] (arbitrary units) in the example.