DHT22 temp/rh sensor to OLED screen (New to Arduinos and C++, already got my...)

Hey everyone, just as an initial disclaimer, Im pretty new to Arduinos and C++, have already gotten my feet wet but still dont quite have a proper grasp on all the basics (which i only mention because when i sought advice other places, people were a little short with my level of ignorance).

I started out with (what I consider) to be a fairly simple project, and learned the bulk of what I know just from struggling with this one. Ive been using an UNO, with a DHT22 temperature/humidity sensor and an OLED screen, and have the appropriate libraries installed for both. Ive tested both separately using the respective libraries' example programs, and was hoping to either merge two example programs, or rewrite something entirely (if possible).

At this point, since I initially tried to merge the two programs, I have one (half) working program that successfully compiles/uploads, but only gives the temperature readout, which also was unfortunately written by someone else (from a different forum I posted in), and he didnt want to continue helping me based on my lack of knowledge.

So, for anyone brave enough to help, could anyone either help me finish the incomplete program, or help me write something from the ground up using the two libraries (which i know would be more of an undertaking, but with my understanding of C++ so far, id be willing to give it a novice shot for troubleshooting/help).

Anyway, if anyone wants to see any of the three, or either library, just let me know and Ill post them. Thanks!

Well, you could try googling something like, oh, say..... merge two arduino sketches

But the way it usually works around here is that, first, you make a valiant attempt at doing something, like merging the two sketches. Then, if it doesn't work, you make a stab or two or three or four at figuring out what went wrong. If you still can't get it to dance for you, then you read and follow the instructions prominently posted at the top of each forum group: "How to use this forum - please read" That includes doing the most basic things that a 63 post junior member should know already, such as posting your code, describing what it is supposed to do, what it doesn't do, what you did to try to make it work, etc.

Or, you can go to the "gigs and collaborations" section, and pay someone to do it for you.

Sorry, I didnt mean to come across the wrong way, actually the last thing I want is for someone to do it for me, cuz I want to know what im actually doing, at least as best I can. Its not so much about just the end result so much as it is the gap in my understanding. Dont get me wrong though, I still appreciate what the other guy did and dont blame him not wanting to help me any more, I just didnt go through what (I do know) is the usual posting code, etc, because i wasnt sure if anyone would even be willing to help or not in the first place, didnt wanna waste anyones time if im too green.

Ill also admit, Ive looked up everything i could up until this point, except how to merge two programs, and this is again because I didnt just want to go through the motions doing something and not knowing why, and i wanted to understand the structure of what I was doing and not just either take a stab at random.

I also dont just expect some random person to just wanna hold my hand and walk me through it either, Im just trying to gage my level of inexperience and the headache itd be for other people to help me work through it. If its too much, ill try learning what i need elsewhere instead

People here are usually happy to help, and all the more so if you demonstrate that you've put some effort into self-education, attempting solving the problem, and helping the helpers by doing the things mentioned in post #1.

Alright, well thanks. Just didnt want to throw everything out there and begin by wasting others' time.

All that being said, again since Im so inexperienced Ill have some pretty basic questions. Not that I mind doing the legwork, so long as people have the patience. Thanks. Ill have to post in parts cuz of forum limits.

Heres the two programs Im trying to use, for the screen and humidity sensor respectively:

/*

  HelloWorld.ino

  Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)

  Copyright (c) 2016, olikraus@gmail.com
  All rights reserved.

  Redistribution and use in source and binary forms, with or without modification, 
  are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this list 
    of conditions and the following disclaimer.
    
  * Redistributions in binary form must reproduce the above copyright notice, this 
    list of conditions and the following disclaimer in the documentation and/or other 
    materials provided with the distribution.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  

*/

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

/*
  U8glib Example Overview:
    Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
    Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
    U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
    
*/

// Please UNCOMMENT one of the contructor lines below
// U8g2 Contructor List (Frame Buffer)
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected
U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

// End of constructor list


void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer(); // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!"); // write something to the internal memory
  u8g2.sendBuffer(); // transfer internal memory to the display
  delay(1000);  
}

and

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {
  Serial.begin(9600); 
  // Initialize device.
  dht.begin();
  Serial.println("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.println("Temperature");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" *C");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" *C");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" *C");  
  Serial.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.println("Humidity");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println("%");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println("%");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println("%");  
  Serial.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;
}

void loop() {
  // Delay between measurements.
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println("Error reading temperature!");
  }
  else {
    Serial.print("Temperature: ");
    Serial.print(event.temperature);
    Serial.println(" *C");
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println("Error reading humidity!");
  }
  else {
    Serial.print("Humidity: ");
    Serial.print(event.relative_humidity);
    Serial.println("%");
  }
}

Ive done some additional digging and found the documentation for the u8g2 here: u8g2reference · olikraus/u8g2 Wiki · GitHub

and found the function to for the print command, and set them all to access the screen, rather than the serial window.

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

uint32_t delayMS;

DHT_Unified dht(DHTPIN, DHTTYPE);

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

void setup(void) {
  dht.begin();
  u8g2.begin();
  u8g2.print("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Temperature");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println(" *C");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println(" *C");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println(" *C");  
  u8g2.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Humidity");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println("%");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println("%");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println("%");  
  u8g2.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;

  
void loop(void) {
  // Delay between measurements.
  delay(delayMS);
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display
  // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    u8g2.println("Error reading temperature!");
  }
  else {
    u8g2.print("Temperature: ");
    u8g2.print(event.temperature);
    u8g2.println(" *C");
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    u8g2.println("Error reading humidity!");
  }
  else {
    u8g2.print("Humidity: ");
    u8g2.print(event.relative_humidity);
    u8g2.println("%");
  }
}
  
  u8g2.clearBuffer();          // clear the internal memory
  
  delay(1000);  
}

But I already know its just a mash of nonsense and a shot in the dark, so even just telling me to go read up on something real simple/basic is much appreciated. Thanks!

Sorry, already making dumb mistakes. Just realized I didnt add the u8g2 libraries/headers and a couple others, so just did that.

Sorry, not sure if this is any better or not, tried to fix the braces, too.

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview


#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

DHT_Unified dht(DHTPIN, DHTTYPE);

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);

uint32_t delayMS;

void setup(void) {
  dht.begin();
  u8g2.begin();
  u8g2.print("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Temperature");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println(" *C");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println(" *C");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println(" *C");  
  u8g2.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Humidity");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println("%");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println("%");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println("%");  
  u8g2.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;

  
void loop {
  // Delay between measurements.
  delay(delayMS);
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display}
  // Get temperature event and print its value.
  {sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    u8g2.println("Error reading temperature!");
  }
  else {
    u8g2.print("Temperature: ");
    u8g2.print(event.temperature);
    u8g2.println(" *C");
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    u8g2.println("Error reading humidity!");
  }
  else {
    u8g2.print("Humidity: ");
    u8g2.print(event.relative_humidity);
    u8g2.println("%");}
    
  u8g2.clearBuffer();          // clear the internal memory
  delay(1000);}
}

And I get:

Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Andrew\Documents\Arduino\sketch_jan21a\sketch_jan21a.ino: In function 'void setup()':

sketch_jan21a:72: error: variable or field 'loop' declared void

 void loop {

      ^

sketch_jan21a:74: error: expected '}' before ';' token

   delay(delayMS);

                 ^

exit status 1
variable or field 'loop' declared void

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Sorry, should add Ive been looking up what those two errors mean in the meantime

Sorry, just realized i had a space between loop and (), so that fixed one error.

Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Users\Andyroo\Documents\Arduino\sketch_jan21a\sketch_jan21a.ino: In function 'void setup()':

sketch_jan21a:72: error: a function-definition is not allowed here before '{' token

 void loop(){

            ^

sketch_jan21a:102: error: expected '}' at end of input

 }

 ^

exit status 1
a function-definition is not allowed here before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Sorry for all the spam, but this one at least compiled, only reason it didnt upload was because Ive been having issues with my COM ports, although I know it also wont work, just not sure if it might be closer. Gonna try to fix the usb drivers and hopefully make better progress tomorrow.

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {
  u8g2.begin();
  dht.begin();
  u8g2.println("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Temperature");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println(" *C");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println(" *C");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println(" *C");  
  u8g2.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Humidity");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println("%");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println("%");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println("%");  
  u8g2.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;
}

void loop() {
  {// Delay between measurements.
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    u8g2.println("Error reading temperature!");
  }
  else {
    u8g2.print("Temperature: ");
    u8g2.print(event.temperature);
    u8g2.println(" *C");
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    u8g2.println("Error reading humidity!");
  }
  else {
    u8g2.print("Humidity: ");
    u8g2.print(event.relative_humidity);
    u8g2.println("%");
  }
  u8g2.clearBuffer();          // clear the internal memory
  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.drawStr(0,10,"Hello World!");  // write something to the internal memory
  u8g2.sendBuffer();          // transfer internal memory to the display
  delay(1000);  
  }
}

Alright, so Ive found the appropriate reference information for each library, here:

the screen:

the Adafruit Sensor Library:

and the DHT:

But Im not quite sure how to properly structure everything together, could anyone help by explaining this to me? I know its a pretty vague/loaded question, i just wouldnt even know where to begin (and obviously havent).

Okay, sorry to keep talking to myself, but i at least got this to compile and upload:

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
//#define DHTTYPE           DHT11     // DHT 11 
#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

void setup() {
  u8g2.begin();
  dht.begin();
  u8g2.println("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Temperature");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println(" *C");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println(" *C");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println(" *C");  
  u8g2.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Humidity");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println("%");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println("%");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println("%");  
  u8g2.println("------------------------------------");
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;
}

void loop() {
  {// Delay between measurements.
  delay(delayMS);
  // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    u8g2.println("Error reading temperature!");
  }
  else {
    u8g2.print("Temperature: ");
    u8g2.print(event.temperature);
    u8g2.println(" *C");
  }
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    u8g2.println("Error reading humidity!");
  }
  else {
    u8g2.print("Humidity: ");
    u8g2.print(event.relative_humidity);
    u8g2.println("%");
  }

  u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
  u8g2.sendBuffer();          // transfer internal memory to the display
  delay(1000);  
  u8g2.clearBuffer();          // clear the internal memory
  }
}

But unfortunately it just displayed random pixels.

At this point, I think the issue lies more in the OLED library's functions/objects/parameters, and utilizing the data passed to it, so Im going to move this question to another forum. When (or if) I resolve the issue Ill come back and post the link/working code.

Okay, here is my final code, which i wrote from the ground-up. I had to change the control structure to account for conflicting delays, then just set the rest up using custom functions as outlined in olikraus' wonderful reference manual for the u8g2 library.

// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.

// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library


#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

#define DHTPIN            2         // Pin which is connected to the DHT sensor.

// Uncomment the type of sensor in use:
#define DHTTYPE           DHT11     // DHT 11 
//#define DHTTYPE           DHT22     // DHT 22 (AM2302)
//#define DHTTYPE           DHT21     // DHT 21 (AM2301)

// See guide for details on sensor wiring and usage:
//   https://learn.adafruit.com/dht/overview

U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
DHT_Unified dht(DHTPIN, DHTTYPE);

const long screenInterval = 1000;           // interval at which to buffer (milliseconds)
unsigned long sensorInterval;
unsigned long previousMillis;

void setup() {
  u8g2.begin();
  dht.begin();
  u8g2.enableUTF8Print();
  u8g2.println("DHTxx Unified Sensor Example");
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Temperature");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println(" *C");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println(" *C");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println(" *C");  
  u8g2.println("------------------------------------");
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  u8g2.println("------------------------------------");
  u8g2.println("Humidity");
  u8g2.print  ("Sensor:       "); u8g2.println(sensor.name);
  u8g2.print  ("Driver Ver:   "); u8g2.println(sensor.version);
  u8g2.print  ("Unique ID:    "); u8g2.println(sensor.sensor_id);
  u8g2.print  ("Max Value:    "); u8g2.print(sensor.max_value); u8g2.println("%");
  u8g2.print  ("Min Value:    "); u8g2.print(sensor.min_value); u8g2.println("%");
  u8g2.print  ("Resolution:   "); u8g2.print(sensor.resolution); u8g2.println("%");  
  u8g2.println("------------------------------------");
    // Set delay between sensor readings based on sensor details.
 sensorInterval = sensor.min_delay / 1000;
}

void loop() {
  for(static unsigned long previousMillis=millis();
      millis()-previousMillis>=sensorInterval;
      previousMillis=millis()){
        u8g2.clearBuffer();
        // Get temperature event and print its value.
        sensors_event_t event;  
        dht.temperature().getEvent(&event);
        if(isnan(event.temperature)) {u8g2.setFont(u8g2_font_5x7_tf);
           u8g2.setCursor(0,15);
           u8g2.println("Error reading temperature!");
           }
           else {u8g2.setFont(u8g2_font_5x7_tf);
           u8g2.setCursor(0,15);
           u8g2.print("Temperature: ");
           u8g2.print(event.temperature);
           u8g2.println(" *C");
           }
           // Get humidity event and print its value.
           dht.humidity().getEvent(&event);
           if (isnan(event.relative_humidity)) {u8g2.setFont(u8g2_font_5x7_tf);
           u8g2.setCursor(0,25);
           u8g2.println("Error reading humidity!");
           }
           else {u8g2.setFont(u8g2_font_5x7_tf);
           u8g2.setCursor(0,25);
           u8g2.print("Humidity: ");
           u8g2.print(event.relative_humidity);
           u8g2.println("%");
           }
  }

  for(static unsigned long previousMillis=millis();
      millis()-previousMillis>=screenInterval/4;
      previousMillis=millis()){u8g2.sendBuffer();} 
}