AHT21 & ENS160 Temperature, humidity and air quality

Post and discuss new components that you have created.
Post Reply
mnfisher
Valued Contributor
Posts: 1509
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 723 times

AHT21 & ENS160 Temperature, humidity and air quality

Post by mnfisher »

Someone asked about this addon board a while ago.

I got one of them - and thought to make a component. To start (and not a component yet) - the AHT21.

This could use the AHT10 component - and I went it alone for a few reasons.. Mostly I like to understand the device by some low level work (but that's probably just me).

There are also a couple of issues with the AHT10 component - it uses floating point. Here we have the choice (and not using fp saves about 1k on an Arduino)
The component can (theoretically) lock up in a couple of places - it's unlikely, but you wouldn't want your car to fail because it can't read the outside temperature.
It doesn't allow for the CRC check - nor do most of the libraries out there - but in the sake of completeness :-)

So - stage 1) Can read temp and humidity!

Martin
Attachments
aht21ens160.fcfx
(41.49 KiB) Downloaded 35 times

mnfisher
Valued Contributor
Posts: 1509
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 723 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by mnfisher »

I managed to get the ENS160 working too.

Still not a component - any suggestions as to better naming conventions?

This reads the temp / humidity and sets the compensation for the ens160. It then enters a loop displaying AQI (Air Quality), TVOC (Volatile organic particles), CO2, Temp and humidity - using the ens160's data ready interrupt (this generates samples every 1s)

I'd wired the board over the interrupt pins on my Arduino - so I just busy wait on a pin (in properties - I used pin 12) going to 0 - which isn't ideal but works as a test. Figures look sensible :-)

It is also possible to test the integrity of the ENS160 data (using a CRC) - but I haven't looked into this yet.

The board I have is https://www.amazon.co.uk/dp/B0DLVDTY9D

Martin
Attachments
aht21ens160.fcfx
(60.29 KiB) Downloaded 34 times

Viktor74
Posts: 29
Joined: Sun Sep 22, 2024 9:13 pm
Has thanked: 5 times
Been thanked: 4 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by Viktor74 »

Hi Martin. I asked earlier about this ENS160 sensor that measures air quality. I have a module with BME280 and ENS160 together on one board. It is a bit difficult for me to understand the code you wrote. Maybe there will be a macro for BME280 and ENS160, it would be better for me. OK thanks for your work, it will be interesting to understand your code for ENS160.

mnfisher
Valued Contributor
Posts: 1509
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 723 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by mnfisher »

There is a component for the BME280.

It would be possible to create 'combined' code (as here) or (probably better) to have a separate bme and ens160 component.

What board are you using (do you have a link?)

Martin

Viktor74
Posts: 29
Joined: Sun Sep 22, 2024 9:13 pm
Has thanked: 5 times
Been thanked: 4 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by Viktor74 »

Hi Martin! I use a board like this. But in my opinion, it is better to make a macro separately for the ENS160 as these sensors can be used separately from each other. And the measurement intervals of their values may not always be the same, because temperature or humidity can be measured more often than air purity, and in other cases it may be the other way round.
Attachments
BME280_ENS160_r.png
BME280_ENS160_r.png (671.41 KiB) Viewed 245 times
BME280_ENS160.png
BME280_ENS160.png (529.1 KiB) Viewed 245 times

mnfisher
Valued Contributor
Posts: 1509
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 723 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by mnfisher »

Stripped the aht21 out - and made into a (very basic) component. There is no simulation / image / etc but runs okay on hardware....

To test - put the component into a directory pointed to by build->customise->locations->search for components in.

There is a very simple test program that display AQI, TVOC and EC02.

Guilty confession time -> testing I couldn't get i2c to read correctly.... I'd actually connected a gyroscope board instead of the ens160 board. Such little writing :-(

Martin
Attachments
ENS160.fcpx
(4.14 KiB) Downloaded 15 times
ens160fcfx.fcfx
(34.55 KiB) Downloaded 14 times
ens160_test.fcfx
(15.33 KiB) Downloaded 14 times

Viktor74
Posts: 29
Joined: Sun Sep 22, 2024 9:13 pm
Has thanked: 5 times
Been thanked: 4 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by Viktor74 »

Unfortunately, I can't use this component in the free version. ;)

mnfisher
Valued Contributor
Posts: 1509
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 723 times

Re: AHT21 & ENS160 Temperature, humidity and air quality

Post by mnfisher »

You could use the source - add code to main (and more macros) to suit...

Martin

Post Reply