Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Can I use a GY-21 temperature/humidity sensor with the Pro2?
#1

Hi,

As mentioned elsewhere on the forum, I've acquired various WeatherDuino boards and sensors from my former PhD supervisor after his untimely death. I'm trying to make sense of the stuff I have.

I have a Pro2 TX and a Pro2 Compact RX board. In the pile of things I got from him was a GY-21 temperature and humidity sensor. It has a four-wire connector on it, which fits on the I2C or SHT2X connectors on the TX board.

The GY-21 sensor board also lists HTU21 and SHT21 on the board - a good picture of it can be found at https://github.com/JonasGMorsch/GY-21

Is this supported by the WeatherDuino Pro2? I was hoping that it would "just work" as it seems to use the same HTU21 and SHT21 sensors that are mentioned in the config file, but regardless what I choose in the config file I either get values of zero for temperature and humidity, or a value of -312 for temperature and zero for humidity.

If this is supported, what should I set the values in the config file to? And which socket should I plug it into?

Best regards,

Robin
Reply
#2

Hi Robin,

Usually those GY-21 modules are fitted with HTU21 sensors, and they should work on the WeatherDuino TX boards.

You should connect it to connector market as I2C (second one starting from left).

Do you have any picture of the connections?
Your config_options.h file may help too.

Rgs.
Werk_AG

Reply
#3

Hi,

I couldn't manage to get it working with the HTU21 configuration option, so I investigated a bit more myself and came across an Arduino library for reading from the GY-21 sensors - available at https://github.com/JonasGMorsch/GY-21

I then modified the WeatherDuino code to read from this sensor, and it all works well. Thank you for writing code that is very clear and easy to modify.

In case anyone else wants to modify their code similarly (or in case you want to include this in the main WeatherDuino code release), the modifications I did are below:

1. Add the following to Routines.ino:
 
Code:
​​​​​​​#if (TH_SENSOR0 == 3)
// ----- Read temperature from GY21 ---------
void read_GY21()
{
GY21 sensor;
T_ExtS0 = sensor.GY21_Temperature() * 100.0;
H_ExtS0 = sensor.GY21_Humidity() * 100.0;
}
#endif

2. Add the following at line 19 in Process_IDx.ino:
 
Code:
#if (TH_SENSOR0 == 3)
    read_GY21();
  #endif

3. Add the following in the include list at the top of the main file:
Code:
#include <GY21.h>

4. Update the Config file to set the TH_SENSOR0 variable to the new value of 3 for the GY-21 sensor
 
Code:
#define TH_SENSOR0  3

5. Include the GY21.h file from the Github repo above to the Arduino libraries folder.

And then it should all work!
​​​​​​​
Best regards,

Robin
Reply
#4

(16-01-2024, 13:50)robintw Wrote:  Hi,

I couldn't manage to get it working with the HTU21 configuration option, so I investigated a bit more myself and came across an Arduino library for reading from the GY-21 sensors - available at https://github.com/JonasGMorsch/GY-21

I then modified the WeatherDuino code to read from this sensor, and it all works well. Thank you for writing code that is very clear and easy to modify.

In case anyone else wants to modify their code similarly (or in case you want to include this in the main WeatherDuino code release), the modifications I did are below:

1. Add the following to Routines.ino:
 
...

Hi Robin,

Thank your for the detailed info.
As the GY-21 sensor module seems to be quite popular nowadays, it makes sense to add your changes on next software release.
I will try do add them to Pro2 and 4Pro TX software.

Rgs.
Werk_AG

Reply
#5

I've just run into some problems with the GY-21 sensor - so beware of taking the code I gave above and using it elsewhere.

I haven't had chance to debug it yet, but the humidity sensor seems to be giving intermittent values, and the temperature sensor was fine until it suddenly started registering -126 degrees (that sounds like an overflow error, but I haven't had chance to investigate yet). Of course these could be partially broken electronics (I have no idea whether something I got from my former PhD supervisor might have been in his 'pile of broken things'), but I suspect I've screwed up the code somehow.

I'll get back to you once I've managed to have a proper look,

Robin
Reply
#6

Hi Robin,

The code you posted for adding support for the GY-21 sensor, for me seems fine and placed on the correct places, however I haven't tested it yet because I don't have any GY-21 module like yours. I have some GY-21 modules but they are fitted with the HTU21, and they work with the existing code.

Seems those modules can be fitted with three types of sensors.
Could you please tell me what reference is writen on the sensor chip of your module?

Just for curiosity could you post the info you get after compiling the software?
Something like this:

Quote:Sketch uses 12004 bytes (39%) of program storage space. Maximum is 30720 bytes.
Global variables use 1241 bytes (60%) of dynamic memory, leaving 807 bytes for local variables. Maximum is 2048 bytes.



Rgs,
Werk_AG

Reply




Users browsing this thread: 1 Guest(s)