Hello I have been sitting here for many hours trying to find the problems with this sketch and my libraries and was hoping someone here can help
I have the DHT22 sensor working fine and printing to serial monitor but I would like to display it on an OLED
the sketch I settled on could not find the library but I beileive I have resolved that, I do not think thislibrary was intended for this sketch, that said I cannot find any alternatives, renaming it seemed to do the trick though
changed #include <dht.h> to #include <DHT.h>
full code is here
/******************************************************************************
OLED DHT22 Humidity/Temperature Display using U8GLIB Library
visit https://code.google.com/p/u8glib/ for full details of the U8GLIB library and
full instructions for use.
by Chris Rouse Oct 2015
DHT22 portions Credit Rob Tillaart
https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib
Using a IIC 128x64 OLED with DHT22
DHT22
Humidity/Temperature Sensor
Wire OLED:
VCC +5v
GND GND
SDA Analog pin 4
SCL Analog pin 5
Wire DHT22
Vcc to Arduino 5 volts
Gnd to Arduino Gnd
Data to Arduino pin 2
******************************************************************************/
// Add libraries
#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include <DHT.h>
// setup u8g object
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C
//
dht DHT;
#define DHT22_PIN 2
struct
{
uint32_t total;
uint32_t ok;
uint32_t crc_error;
uint32_t time_out;
uint32_t connect;
uint32_t ack_l;
uint32_t ack_h;
uint32_t unknown;
} stat = { 0,0,0,0,0,0,0,0};
//
int humidity;
double temperature;
double temperatureF;
int dewPoint1;
String thisTemp = "";
String thisHumidity = "";
String thisDewPoint = "";
//
void draw(void) {
u8g.setFont(u8g_font_profont12);
u8g.drawStr(29,10, "DHT22 Sensor");
u8g.setFont(u8g_font_profont12);
// display Centigrade
thisTemp = String(temperature) + "\260C";
const char* newTempC = (const char*) thisTemp.c_str();
u8g.drawStr(70,25, newTempC);
// display Fahrenheit
temperatureF = 1.8 * temperature + 32;
thisTemp = String(temperatureF) + "\260F";
const char* newTempF = (const char*) thisTemp.c_str();
u8g.drawStr(15,25, newTempF);
// now display Humidity
u8g.setFont(u8g_font_profont29);
thisHumidity = String(humidity) + "%";
const char* newHumidity = (const char*) thisHumidity.c_str();
u8g.drawStr(15,50, newHumidity);
u8g.setFont(u8g_font_profont12);
u8g.drawStr(65,38, "humidity");
// now display the dew point
thisDewPoint = String(dewPoint1) + "\260C";
const char* newDewPoint = (const char*) thisDewPoint.c_str();
u8g.drawStr(85,50, newDewPoint);
u8g.setFont(u8g_font_profont12);
u8g.drawStr(65,50, "DP=");
}
void setup(void) {
Serial.begin(9600);
Wire.begin();
Serial.println("DHT22");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
}
void loop(void) {
uint32_t start = micros();
int chk = DHT.read22(DHT22_PIN);
uint32_t stop = micros();
stat.total++;
switch (chk)
{
case DHTLIB_OK:
stat.ok++;
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
stat.crc_error++;
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
stat.time_out++;
Serial.print("Time out error,\t");
break;
case DHTLIB_ERROR_CONNECT:
stat.connect++;
Serial.print("Connect error,\t");
break;
case DHTLIB_ERROR_ACK_L:
stat.ack_l++;
Serial.print("Ack Low error,\t");
break;
case DHTLIB_ERROR_ACK_H:
stat.ack_h++;
Serial.print("Ack High error,\t");
break;
default:
stat.unknown++;
Serial.print("Unknown error,\t");
break;
}
temperature = DHT.temperature;
humidity = DHT.humidity;
dewPoint(temperature,humidity);
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// delay needed between sensor reads
delay(2000);
}
double dewPoint(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
dewPoint1 = (b * temp) / (a - temp);
}
there is a problem here dht DHT; but I do not understand what the issue is, I presume this is what is creating all the othere errors
I also seem to have picked up multiple dht.h libraries, how can I consolidate these?
here are the multiple errors I am getting
DHT22HumiditySensorwithOLEDDisplay:38: error: 'dht' does not name a type
dht DHT;
^
C:\Users\danbl\Documents\Arduino\DHT22HumiditySensorwithOLEDDisplay\DHT22HumiditySensorwithOLEDDisplay.ino: In function 'void setup()':
DHT22HumiditySensorwithOLEDDisplay:97: error: 'DHT_LIB_VERSION' was not declared in this scope
Serial.println(DHT_LIB_VERSION);
^
C:\Users\danbl\Documents\Arduino\DHT22HumiditySensorwithOLEDDisplay\DHT22HumiditySensorwithOLEDDisplay.ino: In function 'void loop()':
DHT22HumiditySensorwithOLEDDisplay:103: error: expected primary-expression before '.' token
int chk = DHT.read22(DHT22_PIN);
^
DHT22HumiditySensorwithOLEDDisplay:108: error: 'DHTLIB_OK' was not declared in this scope
case DHTLIB_OK:
^
DHT22HumiditySensorwithOLEDDisplay:112: error: 'DHTLIB_ERROR_CHECKSUM' was not declared in this scope
case DHTLIB_ERROR_CHECKSUM:
^
DHT22HumiditySensorwithOLEDDisplay:116: error: 'DHTLIB_ERROR_TIMEOUT' was not declared in this scope
case DHTLIB_ERROR_TIMEOUT:
^
DHT22HumiditySensorwithOLEDDisplay:120: error: 'DHTLIB_ERROR_CONNECT' was not declared in this scope
case DHTLIB_ERROR_CONNECT:
^
DHT22HumiditySensorwithOLEDDisplay:124: error: 'DHTLIB_ERROR_ACK_L' was not declared in this scope
case DHTLIB_ERROR_ACK_L:
^
DHT22HumiditySensorwithOLEDDisplay:128: error: 'DHTLIB_ERROR_ACK_H' was not declared in this scope
case DHTLIB_ERROR_ACK_H:
^
DHT22HumiditySensorwithOLEDDisplay:137: error: expected primary-expression before '.' token
temperature = DHT.temperature;
^
DHT22HumiditySensorwithOLEDDisplay:138: error: expected primary-expression before '.' token
humidity = DHT.humidity;
^
Multiple libraries were found for "DHT.h"
Used: C:\Users\danbl\Documents\Arduino\libraries\DHT_sensor_library
Not used: C:\Users\danbl\Documents\Arduino\libraries\DHT-sensor-library-master
Using library U8glib at version 1.19.1 in folder: C:\Users\danbl\Documents\Arduino\libraries\U8glib
Using library SPI at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI
Using library Wire at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.10.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire
Using library DHT_sensor_library at version 1.3.0 in folder: C:\Users\danbl\Documents\Arduino\libraries\DHT_sensor_library
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Users\danbl\Documents\Arduino\libraries\Adafruit_Unified_Sensor
exit status 1
'dht' does not name a type
amny thanks for any assistance you can offer
Dan