Skip to content

Commit 5b56802

Browse files
committed
Support DHT20 on GIGA R1
1 parent 3548014 commit 5b56802

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

examples/Combined_Demo/Combined_Demo.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#include "Arduino_SensorKit.h"
77

8+
// Uncomment line below if your SensorKit is the variant with the DHT20 sensor
9+
// (It's marked IIC on the PCB and has a black cover, while the DHT11 sensor
10+
// has a blue cover.)
11+
//#define Environment Environment_I2C
12+
813
#define BUZZER 5
914
#define BUTTON 4
1015
#define LED 6

examples/Temp_and_Humidity/Temp_and_Humidity.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include "Arduino_SensorKit.h"
22

3-
//uncomment line below if using DHT20
3+
// Uncomment line below if your SensorKit is the variant with the DHT20 sensor
4+
// (It's marked IIC on the PCB and has a black cover, while the DHT11 sensor
5+
// has a blue cover.)
46
//#define Environment Environment_I2C
57

68
void setup() {
7-
//uncomment line below if using DHT20
8-
//Wire.begin();
9-
10-
//uncomment line below if you're connecting your DHT20 to pin a different than 3
9+
// Uncomment line below if your kit has a DHT11 and you're connecting it to
10+
// a pin different than 3
1111
//Environment.setPin(4);
1212

1313
Serial.begin(9600);

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Sensors
88
url=https://sensorkit.arduino.cc/
99
architectures=avr,mbed_giga
1010
precompiled=false
11-
depends=Grove-3-Axis-Digital-Accelerometer-2g-to-16g-LIS3DHTR
11+
depends=Grove-3-Axis-Digital-Accelerometer-2g-to-16g-LIS3DHTR,DHT20

src/Arduino_SensorKit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//Declare component's classes
44
SensorKit_Oled Oled;
5-
SensorKit_DHT Environment(3,DHT11);
6-
DHT Environment_I2C(DHT20);
5+
SensorKit_DHT11 Environment(3,DHT11);
6+
SensorKit_DHT20 Environment_I2C;
77
SensorKit_LIS3DHTR Accelerometer(_WIRE);
88
SensorKit_BMP280 Pressure(_WIRE);

src/Arduino_SensorKit.h

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "Arduino_SensorKit_BMP280.h" // Pressure
1515
#include "Arduino_SensorKit_LIS3DHTR.h" // Accel
1616
#include "Grove_Temperature_And_Humidity_Sensor/DHT.h" // Temp & Humidity
17+
#undef DHT20
18+
#include <DHT20.h> // Temp & Humidity
1719
#include "U8g2/src/U8x8lib.h" // OLED Display
1820

1921
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_UNOR4_MINIMA) || defined(ARDUINO_UNOR4_WIFI)
@@ -28,8 +30,6 @@
2830
#error "This board is not supported by Arduino_SensorKit"
2931
#endif
3032

31-
class SensorKit_DHT;
32-
3333
// The upstream U8X8 library provides two variants, one for hardware I2C (using
3434
// the Wire object provided by Arduino) and one for software I2C. The latter
3535
// doesn't seem to work. However it seems that when breaking the sensors from
@@ -54,18 +54,31 @@ class SensorKit_Oled : public _Oled_class {
5454
};
5555
extern SensorKit_Oled Oled;
5656

57+
class SensorKit_DHT11;
58+
class SensorKit_DHT20;
5759
extern SensorKit_LIS3DHTR Accelerometer;
5860
extern SensorKit_BMP280 Pressure;
59-
extern SensorKit_DHT Environment;
60-
extern DHT Environment_I2C;
61+
extern SensorKit_DHT11 Environment;
62+
extern SensorKit_DHT20 Environment_I2C;
6163

62-
//Subclass DHT
63-
class SensorKit_DHT : public DHT {
64+
// Subclass DHT
65+
class SensorKit_DHT11 : public DHT {
6466
public:
65-
SensorKit_DHT(uint8_t pin, uint8_t type) : DHT(pin, type) {};
67+
SensorKit_DHT11(uint8_t pin, uint8_t type) : DHT(pin, type) {};
6668
void setPin(uint8_t pin) {
67-
Environment = SensorKit_DHT(pin, DHT11);
69+
Environment = SensorKit_DHT11(pin, DHT11);
70+
};
71+
};
72+
73+
class SensorKit_DHT20 : public DHT20 {
74+
public:
75+
SensorKit_DHT20() : DHT20(&_WIRE) {};
76+
bool begin(void) {
77+
_WIRE.begin();
78+
return DHT20::begin();
6879
};
80+
float readHumidity() { read(); return getHumidity(); };
81+
float readTemperature() { read(); return getTemperature(); };
6982
};
7083

7184
#endif

0 commit comments

Comments
 (0)