Minimal Pi Pico 2 Humidity Sensor Design
Waiting for input
0x70Table
| Function | Pico 2 Pin | Net | Connected To | Notes |
|---|---|---|---|---|
| I2C0 SDA | GPIO4 | I2C0_SDA | U2:SDA, R1 10kΩ pull-up | Arduino Wire SDA |
| I2C0 SCL | GPIO5 | I2C0_SCL | U2:SCL, R2 10kΩ pull-up | Arduino Wire SCL |
| 3.3 V | 3V3 | 3V3 | U2:VDD, C1, pull-ups | Sensor power |
| Ground | GND/AGND | GND | U2:VSS, U2:EPAD, C1 | Common return |
platformio.ini:Ini
[env:pico2] platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = rpipico2 framework = arduino board_build.core = earlephilhower monitor_speed = 115200 lib_deps = sensirion/Sensirion I2C SHTC3@^1.0.0
raspberrypi platform instead of the Git URL above.src/main.cpp:Cpp
#include <Arduino.h> #include <Wire.h> #include <SensirionI2CShtc3.h> // Schematic pin mapping static constexpr uint8_t PIN_I2C0_SDA = 4; // U1 GPIO4 -> U2 SDA static constexpr uint8_t PIN_I2C0_SCL = 5; // U1 GPIO5 -> U2 SCL static constexpr uint32_t I2C_CLOCK_HZ = 400000; // SHTC3 supports up to 1 MHz static constexpr uint32_t SAMPLE_INTERVAL_MS = 2000; // Humidity response is not instantaneous SensirionI2CShtc3 shtc3; unsigned long lastSampleMs = 0; static void printShtc3Error(uint16_t error) { if (error == 0) { return; } Serial.print("SHTC3 error: 0x"); Serial.println(error, HEX); } static bool initShtc3() { Wire.setSDA(PIN_I2C0_SDA); Wire.setSCL(PIN_I2C0_SCL); Wire.begin(); Wire.setClock(I2C_CLOCK_HZ); shtc3.begin(Wire); uint32_t serialNumber = 0; uint16_t error = shtc3.wakeUp(); if (error) { printShtc3Error(error); return false; } error = shtc3.serialNumber(serialNumber); if (error) { printShtc3Error(error); return false; } Serial.print("SHTC3 serial: "); Serial.println(serialNumber); // Sleep between measurements for low power and datasheet-recommended operation. error = shtc3.sleep(); if (error) { printShtc3Error(error); return false; } return true; } static bool readShtc3(float& temperatureC, float& relativeHumidity) { uint16_t error = shtc3.wakeUp(); if (error) { printShtc3Error(error); return false; } // Normal precision, clock stretching disabled for broad controller compatibility. error = shtc3.measurePowerMode(SHTC3_CMD_CSE_RHF_NPM, temperatureC, relativeHumidity); if (error) { printShtc3Error(error); (void)shtc3.sleep(); return false; } error = shtc3.sleep(); if (error) { printShtc3Error(error); return false; } return true; } void setup() { Serial.begin(115200); delay(2000); Serial.println("Pico 2 SHTC3 humidity shield starting..."); if (!initShtc3()) { Serial.println("SHTC3 init failed. Check 3V3, GND, SDA=GPIO4, SCL=GPIO5, and pull-ups."); } else { Serial.println("SHTC3 init OK."); } } void loop() { const unsigned long now = millis(); if (now - lastSampleMs < SAMPLE_INTERVAL_MS) { return; } lastSampleMs = now; float temperatureC = NAN; float relativeHumidity = NAN; if (readShtc3(temperatureC, relativeHumidity)) { Serial.print("Temperature: "); Serial.print(temperatureC, 2); Serial.print(" C, Humidity: "); Serial.print(relativeHumidity, 2); Serial.println(" %RH"); } else { Serial.println("SHTC3 read failed; retrying on next interval."); } }
Bash
pio run pio run -t upload pio device monitor -b 115200
3V3, GND, GPIO4/SDA, GPIO5/SCL, R1/R2 10kΩ pull-ups, and C1 100nF decoupling.Platform & Toolchain
Pin Mapping
PlatformIO Setup
Complete Firmware Source
Build & Flash
Bring-Up Checklist