Read data from HTS221 on Arduino_nano-33-ble + RIOT

Hello:) I am trying to read temperature and humidity data from HTS221, which is located on arduino nano ble sense. But In the first step to initialize the sensor and set the parameters, I have a problem. Could you please some one help me how can I initialize my sensor (HTS221) in RIOT?

Thanks in advance

Hi,

Have you looked at the HTS221 sample test application code: https://github.com/RIOT-OS/RIOT/tree/master/tests/driver_hts221 ?

1 Like

When sensors are connected to boards on which they are not on by default, the steps are:

  • Add USEMODULE += hts221 to your project’s Makefile
  • If the device is not attatched to its default location (see drivers/hts221/include/hts221_params.h: HTS221_PARAM_I2C defaults to I2C_DEV(0), you’ll need to define that separately, eg. by setting CFLAGS += "-DHTS221_PARAM_I2C=I2C_DEV(1)" (but probably the zeroth is good anyway)

You can also make these changes to the SAUL example, and then use the sensor through the SAUL abstraction.

Thanks a lot for the reply. my problem here is that temperature and humidity sensors are located on board (integrated with arduino-nano-33-ble sense). Therefore I try to use the default parameters, determined in hts221_params.h but still I can not initialize the sensor. I attached my setup as well.

Thanks a lot in advance

Ah, I’ve looked at the relevant data sheet now:

The sensor is connected to what the data sheet calls SCL1/SDA1 (that would be reasonably called I2C_DEV(1) in RIOT). However, the board file for arduino-nano-33-ble does not set up that I2C.

I’m not familiar with that particular board, but it appears that what should happen here is that the second I2C bus should be initialized too. You can do that yourself by adding a second i2c_config entry in boards/arduino-nano-33-ble/include/periph_conf.h (presumably with NRF_TWIM1; it would be good to verify with the data sheet that the pins of the HTS221 can actually be assigned to that device, but it would be weird if not). Note that in the same place you can then also #define HTS221_PARAM_I2C (I2C_DEV(1)) to make the HTS driver actually use it.

If that works (actually, even if not), you can file a pull request with that change to make the board better. (When there is a sensor on a board, it should really work out-of-the-box; unfortunately, not all boards that have not-yet-supported components document that).

By the way, when that works, you can also enable the APDS-9960, which should then also show up in SAUL.

1 Like