Xbee3 MicroPython and TE HTU21D Humidity Sensor


This details an example of interfacing TE Connectivity’s HTU21D relative humidity / temperature sensor to Digi International’s XBee3 intelligent wireless module (programmed with 802.15.4 protocol firmware). The project uses the HTU21D sensor included on TE’s weather shield connected over I2C to Digi International’s Grove development board with an Xbee 3 wireless module plugged in. A Micropython script running on the Xbee3 communicates with the HTU21D sensor to read the I2C address and trigger/measure relative humidity and temperature.

Hardware Requirements

Supplier Documentation

Hardware Setup

TE Weather Shield

TE Connectivity’s Weather Shield is an Arduino form factor sensor evaluation board with five TE environmental sensors mounted. The five sensors are the HTU21D Humidity/Temperature Sensor, MS5637 Pressure Sensor, MS8607 Pressure Sensor, TSYS01 Temperature Sensor, and TSD305-1C55 Contactless Temperature Sensor. All five sensors communicate on the I2C bus which is routed through mux/demux to allow switching of the I2C bus to the various sensors. For selection of the HTU21D and MS5637 sensors the inputs CA, CB and EN are set “low”.

Xbee SMT Grove Board

Digi International’s Xbee SMT Grove board is a development platform allowing use of multiple SMT form factor Xbee wireless modules. Various Xbee signals, including I2C, are routed to eight grove connectors on the board to allow easy interface to external devices.

Example Code


MicroPython code that runs on a Xbee 3 wireless module connected to an HTU21D humidity/temperature sensor over I2C. The example code scans the I2C bus and prints active addresses, reads/prints the user register, and reads/prints relative humidity and temperature in a continuous loop.

TE Connectivity HTU21D Humidity and Temperature Calculation Background

Configuration settings and calculations used are based on edition 8 of the HTU21D datasheet per below: