Hardware Needed
Gather the following components before you wire anything up:- ANX dev module
- 10 kΩ potentiometer (for the ADC channel)
- SHT31 temperature and humidity sensor breakout board (for I2C)
- Jumper wires and a breadboard
Wiring
Connect your components to the ANX dev module as described below. Double-check the connections before powering on — reversing VCC and GND on the SHT31 breakout can damage the sensor.- Potentiometer (ADC)
- SHT31 (I2C)
Rotating the potentiometer knob varies the voltage on the wiper between 0 V and 3.3 V, which the ADC converts to a 12-bit value between 0 and 4095.
Application Code
The example is split into two helper functions —read_adc() and read_sht31() — each responsible for a single sensor. The app_main() function calls both in a loop with a two-second delay between readings.
sensor_data.c
Run and Monitor
Flash the example to your connected module and open the serial monitor with the following two commands:Raw and Voltage values update in real time. Move the SHT31 near a warm surface or breathe gently on it to see temperature and humidity respond.
The default I2C address for the SHT31 is 0x44, which is what
SHT31_ADDR is set to in the example. Some breakout boards pull the ADDR pin high, changing the address to 0x45. If your readings never appear or you see I2C timeout errors in the monitor, change the define to 0x45 and re-flash.How the SHT31 Conversion Works
The SHT31 returns raw 16-bit values for temperature and humidity that you convert to physical units using the formulas from the datasheet. The example applies both conversions inline:Temperature conversion formula
Temperature conversion formula
0 maps to −45 °C and a raw value of 65535 maps to +130 °C, giving a full-scale range of 175 °C across 16 bits.Humidity conversion formula
Humidity conversion formula
0 maps to 0 % RH and 65535 maps to 100 % RH. The sensor’s specified accuracy is ±2 % RH between 20 % and 80 % RH.