Connecting DHT22 temperature,humidity sensor

I can find no library which works on the Gamebuino META with this sensor

the Arduino Library reports:

E:\Arduino-META\arduino\libraries\DHT\DHT.cpp: In member function ‘boolean DHT::read()’:

E:\Arduino-META\arduino\libraries\DHT\DHT.cpp:110:7: error: ‘cli’ was not declared in this scope

cli();

^

E:\Arduino-META\arduino\libraries\DHT\DHT.cpp:140:7: error: ‘sei’ was not declared in this scope

sei();

^
The Adafruit library reports no error but shows no result

knows somehow a DHT library that works with the META?

regards Rainer

1 Like

Hello Rainer,

I see that you use your Gamebuino to do a lot of things: it makes us very happy.

Can you provide us with the link to this Library ?
It seems to be intended for an ATmega, and not a SAM21.

The Adafruit library should work : adafruit/DHT-sensor-library.

Have you connected the sensor correctly in 3V3 power ?
It will not work in 5V on Gamebuino !
Reminder you should never connect 5V things to the Gameubino META : you risk damaging it

Did you set up the correct pin, as connected to the Gamebuino META ?

#define DHTPIN 2                     // use D2 in this example
#define DHTTYPE DHT22        // use a DHT22 ( not an DHT11 )
DHT dht (DHTPIN, DHTTYPE);  // create the sensor library object

While waiting for your reply,
Jean Marie

Hello, @Rainer (and thanks, @JMP).

However, I’ll clarify things a bit in case you need more direction.

The Adafruit’s DHT sensor library works perfectly (the first one in the list below):

Wiring the temperature sensor is simple:

DHT22 pins Gamebuino pins Wire Color
VCC 3.3V Red
Data 12 White
GND GND Black

I always prefer to connect the data read pin to a pull-up resistor (here I used a 4.7 kΩ resistor, but you can also use a 10 kΩ). This helps stabilize the signal from the sensor.

The pull-up resistor is connected between the readout pin (white wire) and the supply line (red wire):

The connection of the wires on the Backpack is as follows:

I used digital port 12 here, but you can choose the one you want (avoid using ports 0 (RX) and 1 (TX), which are used for UART serial communication with your PC).

Here is a simple demonstration program:

#include <Gamebuino-Meta.h>
#include <DHT.h>

DHT dht(12, DHT22);  // DHT_PIN = 12

void setup() {
    gb.begin();
    dht.begin();
}

void loop() {

    gb.waitForUpdate();
    gb.display.clear();

    gb.display.print(2, 2, F("TEMP:"));
    gb.display.print(26, 2, dht.readTemperature());
    
    gb.display.print(2, 10, F("HUMI:"));
    gb.display.print(26, 10, dht.readHumidity());

    delay(5000);

}

And this is what you get once the code is compiled and uploaded to your Gamebuino:

Hope this helps you :wink:

2 Likes

Waouh :open_mouth: Amazing job ! Thanks for your response.

1 Like

It’s not just an answer, it’s a real little tutorial!
Well done and thank you Steph

1 Like

Hallo Steph, JMP
thank you very much,
with this adafruit DHT-sensor-library it works perfectly (unfortenately the system used the “arduino DHT library” (guess from the arduino forum) or the"DHT-sensor-library-master".
It even works without the resistor (-> simpler wireing without an additional boad)

regards Rainer

2 Likes

Projects sometimes require a little more effort to find the right library, or fix a bug.
It’s also the life of a maker :grinning_face_with_smiling_eyes: