It may be small, but this OLED is cute and useful and that little DHT11 really knows when something is hot or not

WP_20140302_013As I stated in a previous post, I have a fetish for displays. Any display. Again, while searching eBay for some parts for my Half-Byte Console project, I found a small, .96 inch OLED display. This little gem uses either SPI, Serial or I2C to interface with your device.  I ordered one and received it a few days ago. As is with most of these cheap parts from China, there was little in the way of documentation or code.  Fortunately, more than one vendor sold them and I found some code, which was good since none of the code I found on the net seemed to work.

This little display is advertised as monochrome, but it really is a two color display.  The top two lines have a yellow background OR yellow foreground and the rest of the screen is blue on black or black on blue.  It was likely out of an old cell phone. To be honest, I’ve not done much research on the history of the screen itself.

Since there are a number of ways to connect the display, which uses the SSD1306, I chose the method in the code that I found:

  1. SCL –>9
  2. SCA –>8

Of course, VCC goes to either 3.3v or 5v and GND to ground.  Once the hardware was connected, I uploaded the code I found. 

The code, found here (but, download it from here, instead), was a simple demonstration and did not come with a very versatile library. Though, it does appear to use the Adafruit GFX library.

Although too small for most of my uses, I wanted to see if it may fit a project I have in mind further down the road. Turns out, it will. So, I then attempted to bang together WP_20140302_016part of that idea using a DHT11 temperature sensor. This sensor also gives the relative humidity. So, I connect the OLED and the DHT11 sensor to an Arduino Mini Pro. The DHT11’s data pin goes to Pin 2 (TX) on the Arduino, and pin 1 goes to 5v and the third pin to GND. I incorporated the DHT code into my OLED demo and then … problems.  Turns out, the OLED library has no built in method to output numerical data.  Remembering my Tiny Basic code, I stole some code from it to output numerical data and…viola! Works like a charm (see photo above.)

At six dollars, the screen isn’t really worth it, as there are better screens out there for the same or even less.  However, if you can these cheaper, they will make great little status displays or even part of a smartwatch or other wearable device.

To use my sample code below, you will need the following libraries installed:

  • SoftwareSerial (should be part of your Arduino installation)
  • IIC_without_ACK.h (use the link above)
  • TinyDHT (download here)
  • avr/power.h (part of your install)

A note about the AdaFruit libraries: While provided free of charge, developing these is not always an easy task (though, it might for Lady Ada) and, as such, you should patronize them whenever you can. They have a great selection and good pricing. I buy quite a bit from them.

The display is also capable of graphical display, but I’ve not yet bothered to try and put an image on the screen. There is a bitmap function in the limited library, but you must convert your image to a C array first.  Take a look at the header file for the OLED font.

have fun!

Sample Code:

#include <SoftwareSerial.h>
#include <IIC_without_ACK.h>
#include “oledfont.c”  

#define OLED_SDA 8
#define OLED_SCL 9

IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl

/*
* DHT Temperature Sensor
// Connect DHT pin 1 (on the left) of the sensor to +5V
// Connect DHT pin 2 of the sensor to whatever your DHTPIN is
// Connect DHT pin 3 (on the right) of the sensor to GROUND
*/
 
// include the library code

#include <TinyDHT.h>        // lightweight DHT sensor library
#include <avr/power.h>      // needed to up clock to 16 MHz on 5v Trinket
 
// Uncomment whatever type sensor you are using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)
#define TEMPTYPE 1        // Use Fahrenheit (0 for celsius)
#define DHTPIN 1          DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor
static unsigned char *spt;
/***************************************************************************/
static void pushb(const char b)
{
    spt–;
    *spt = b;
}

/***************************************************************************/
static unsigned char popb()
{
    unsigned char b;
    b = *spt;
    spt++;
    return b;
}

/***************************************************************************/
void printnum(unsigned char x, unsigned char y, int num)
{
        char st[]=”   “;
    int digits=0;
        int pos=0;
       
    if(num < 0)
    {
        num = -num;
        oled.Char_F6x8(x,y,”-“);
    }

    do {
        pushb(num%10+’0′);
        num = num/10;
        digits++;
    }
    while (num > 0);
        while(digits > 0)
          {
                  st[pos]=popb();
                  x++;
            digits–;
                  pos++;
          }
         oled.Char_F6x8(x,y, st);
}
 
void setup() { 
  dht.begin();  // Initialize DHT Teperature Sensor
  oled.Initial();
}
 
void loop() {
  int8_t h = dht.readHumidity();               // Read humidity
  int16_t t = dht.readTemperature(TEMPTYPE);   // read temperature
 
  delay(2000);
  oled.Fill_Screen(0x00);
 
  if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions (see TinyDHT.h)
    oled.Char_F6x8(0,0,”Bad Read on DHT”); //   print error message
  } else {
    oled.Char_F6x8(0,2,”Humidity:”);
    printnum(60,2,h);
    oled.Char_F6x8(78,2,”%”);
    oled.Char_F6x8(0,4,”Temp: “);
    printnum(36,4,t);
    oled.Char_F6x8(50,8,”F”);    
  }
  delay(2000);  // Read temp every second (2000 ms) (DHT sensor max rate)
}

33 thoughts on “It may be small, but this OLED is cute and useful and that little DHT11 really knows when something is hot or not

  1. Thanks for the link to the IIC_without_ACK files.
    It’s not using the Adafruit GFX library at all, there are only the functions IIC_SetPos, Fill_Screen, Char_F6x8 and Draw_BMP available.
    The data for the BMP is in file oledfont.c but I haven’t figured out what format it has to have.

  2. Hi please can you help me,i cant get the sample code to work,there loads of errors,ime copy and past it all,ive installed the librarys too,have you just joted the code roughly?

  3. HI Duncan, sorry for the delay in responding.
    The code I posted worked for me. If you could let us know what errors you get and the code you are using, we would be happy to help.

  4. This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.
    Arduino: 1.0.6 (Windows XP), Board: “Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328”
    sketch_jan30a.ino:3:10: error: #include expects “FILENAME” or
    sketch_jan30a:32: error: stray ‘\’ in program
    sketch_jan30a:48: error: stray ‘\’ in program
    sketch_jan30a:48: error: stray ‘\’ in program
    sketch_jan30a:55: error: stray ‘\’ in program
    sketch_jan30a:55: error: stray ‘\’ in program
    sketch_jan30a:59: error: stray ‘\’ in program
    sketch_jan30a:59: error: stray ‘\’ in program
    sketch_jan30a:68: error: stray ‘\’ in program
    sketch_jan30a:87: error: stray ‘\’ in program
    sketch_jan30a:87: error: stray ‘\’ in program
    sketch_jan30a:89: error: stray ‘\’ in program
    sketch_jan30a:89: error: stray ‘\’ in program
    sketch_jan30a:91: error: stray ‘\’ in program
    sketch_jan30a:91: error: stray ‘\’ in program
    sketch_jan30a:92: error: stray ‘\’ in program
    sketch_jan30a:92: error: stray ‘\’ in program
    sketch_jan30a:94: error: stray ‘\’ in program
    sketch_jan30a:94: error: stray ‘\’ in program
    sketch_jan30a.ino: In function ‘void pushb(char)’:
    sketch_jan30a:32: error: expected `;’ before ‘u2013’
    sketch_jan30a.ino: In function ‘void printnum(unsigned char, unsigned char, int)’:
    sketch_jan30a:48: error: ‘u201d’ was not declared in this scope
    sketch_jan30a:48: error: expected ‘,’ or ‘;’ before ‘u201c’
    sketch_jan30a:55: error: ‘u201c’ was not declared in this scope
    sketch_jan30a:59: error: ‘u20190′ was not declared in this scope
    sketch_jan30a:68: error: expected `;’ before ‘u2013’
    sketch_jan30a.ino: In function ‘void setup()’:
    sketch_jan30a:75: error: ‘dht’ was not declared in this scope
    sketch_jan30a.ino: In function ‘void loop()’:
    sketch_jan30a:80: error: ‘dht’ was not declared in this scope
    sketch_jan30a:87: error: ‘u201dBad’ was not declared in this scope
    sketch_jan30a:89: error: ‘u201dHumidity’ was not declared in this scope
    sketch_jan30a:91: error: ‘u201d’ was not declared in this scope
    sketch_jan30a:92: error: ‘u201dTemp’ was not declared in this scope
    sketch_jan30a:94: error: ‘u201dF’ was not declared in this scope

  5. ITS SOMTHING TO DO WITH THIS PART= static void pushb(const char b)
    {
    spt–;
    *spt = b;
    }

    spt-; (is highlighted)

  6. In the code I posted, I noticed this:
    #define DHTPIN 1 DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor
    separate the #define DHTPIN 1 from the rest. Should be:
    #define DHTPIN 1
    DHT dht(DHTPIN, DHTTYPE); // Define Temp Sensor

  7. Correct that line above and it should compile. I am running most of the code in another project and ran it here without problem. I suspect the formatting got hosed when I posted it.

  8. This report would have more information with
    “Show verbose output during compilation”
    enabled in File > Preferences.
    Arduino: 1.0.6 (Windows 7), Board: “Arduino Nano w/ ATmega328”
    sketch_feb14a.ino:5:10: error: #include expects “FILENAME” or
    sketch_feb14a:36: error: stray ‘\’ in program
    sketch_feb14a:52: error: stray ‘\’ in program
    sketch_feb14a:52: error: stray ‘\’ in program
    sketch_feb14a:59: error: stray ‘\’ in program
    sketch_feb14a:59: error: stray ‘\’ in program
    sketch_feb14a:63: error: stray ‘\’ in program
    sketch_feb14a:63: error: missing terminating ‘ character
    sketch_feb14a:72: error: stray ‘\’ in program
    sketch_feb14a:91: error: stray ‘\’ in program
    sketch_feb14a:91: error: stray ‘\’ in program
    sketch_feb14a:93: error: stray ‘\’ in program
    sketch_feb14a:93: error: stray ‘\’ in program
    sketch_feb14a:95: error: stray ‘\’ in program
    sketch_feb14a:95: error: stray ‘\’ in program
    sketch_feb14a:96: error: stray ‘\’ in program
    sketch_feb14a:96: error: stray ‘\’ in program
    sketch_feb14a:98: error: stray ‘\’ in program
    sketch_feb14a:98: error: stray ‘\’ in program
    sketch_feb14a.ino: In function ‘void pushb(char)’:
    sketch_feb14a:36: error: expected `;’ before ‘u2013’
    sketch_feb14a.ino: In function ‘void printnum(unsigned char, unsigned char, int)’:
    sketch_feb14a:52: error: ‘u201d’ was not declared in this scope
    sketch_feb14a:52: error: expected ‘,’ or ‘;’ before ‘u201c’
    sketch_feb14a:59: error: ‘u201c’ was not declared in this scope
    sketch_feb14a:63: error: ‘u20190′ was not declared in this scope
    sketch_feb14a:72: error: expected `;’ before ‘u2013’
    sketch_feb14a.ino: In function ‘void loop()’:
    sketch_feb14a:91: error: ‘u201dBad’ was not declared in this scope
    sketch_feb14a:93: error: ‘u201dHumidity’ was not declared in this scope
    sketch_feb14a:95: error: ‘u201d’ was not declared in this scope
    sketch_feb14a:96: error: ‘u201dTemp’ was not declared in this scope
    sketch_feb14a:98: error: ‘u201dF’ was not declared in this scope

    1. Hi Duncan,
      I don’t normally do this, but…will in this case. Send me your sketch. It looks like, judging from this report, that an INCLUDE is not complete and that there are some typos. If you send me your sketch, I’d be happy to help you get it working.

  9. I’m having exactly the same problem as Duncan, have followed your help but not having any joy. Sketch is:

    #include
    #include
    #include “oledfont.c”

    #define OLED_SDA 8
    #define OLED_SCL 9

    IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl

    /*
    * DHT Temperature Sensor
    // Connect DHT pin 1 (on the left) of the sensor to +5V
    // Connect DHT pin 2 of the sensor to whatever your DHTPIN is
    // Connect DHT pin 3 (on the right) of the sensor to GROUND
    */

    // include the library code

    #include // lightweight DHT sensor library
    #include // needed to up clock to 16 MHz on 5v Trinket

    // Uncomment whatever type sensor you are using!
    #define DHTTYPE DHT11 // DHT 11
    //#define DHTTYPE DHT22 // DHT 22 (AM2302)
    //#define DHTTYPE DHT21 // DHT 21 (AM2301)
    #define TEMPTYPE 1 // Use Fahrenheit (0 for celsius)
    #define DHTPIN 2 //define DHT pin
    DHT dht (DHTPIN, DHTTYPE); // Define Temp Sensor
    static unsigned char *spt;
    /***************************************************************************/
    static void pushb(const char b)
    {
    spt–;
    *spt = b;
    }

    /***************************************************************************/
    static unsigned char popb()
    {
    unsigned char b;
    b = *spt;
    spt++;
    return b;
    }

    /***************************************************************************/
    void printnum(unsigned char x, unsigned char y, int num)
    {
    char st[]=” “;
    int digits=0;
    int pos=0;

    if(num 0);
    while(digits > 0)
    {
    st[pos]=popb();
    x++;
    digits–;
    pos++;
    }
    oled.Char_F6x8(x,y, st);
    }

    void setup() {
    DHT.begin(); // Initialize DHT Teperature Sensor
    oled.Initial();
    }

    void loop() {
    int8_t h = DHT.readHumidity(); // Read humidity
    int16_t t = DHT.readTemperature(TEMPTYPE); // read temperature

    delay(2000);
    oled.Fill_Screen(0x00);

    if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions (see TinyDHT.h)
    oled.Char_F6x8(0,0,”Bad Read on DHT”); // print error message
    } else {
    oled.Char_F6x8(0,2,”Humidity:”);
    printnum(60,2,h);
    oled.Char_F6x8(78,2,”%”);
    oled.Char_F6x8(0,4,”Temp: “);
    printnum(36,4,t);
    oled.Char_F6x8(50,8,”F”);
    }
    delay(800); // Read temp every second (2000 ms) (DHT sensor max rate)
    }

    And the error I’m seeing shows:

    testnewdhtanddisplay:33: error: stray ‘\’ in program
    testnewdhtanddisplay:49: error: stray ‘\’ in program
    testnewdhtanddisplay:49: error: stray ‘\’ in program
    testnewdhtanddisplay:56: error: stray ‘\’ in program
    testnewdhtanddisplay:56: error: stray ‘\’ in program
    testnewdhtanddisplay:60: error: stray ‘\’ in program
    testnewdhtanddisplay:60: error: stray ‘\’ in program
    testnewdhtanddisplay:69: error: stray ‘\’ in program
    testnewdhtanddisplay:88: error: stray ‘\’ in program
    testnewdhtanddisplay:88: error: stray ‘\’ in program
    testnewdhtanddisplay:90: error: stray ‘\’ in program
    testnewdhtanddisplay:90: error: stray ‘\’ in program
    testnewdhtanddisplay:92: error: stray ‘\’ in program
    testnewdhtanddisplay:92: error: stray ‘\’ in program
    testnewdhtanddisplay:93: error: stray ‘\’ in program
    testnewdhtanddisplay:93: error: stray ‘\’ in program
    testnewdhtanddisplay:95: error: stray ‘\’ in program
    testnewdhtanddisplay:95: error: stray ‘\’ in program
    testnewdhtanddisplay.ino: In function ‘void pushb(char)’:
    testnewdhtanddisplay:33: error: expected ‘;’ before ‘u2013’
    testnewdhtanddisplay.ino: In function ‘void printnum(unsigned char, unsigned char, int)’:
    testnewdhtanddisplay:49: error: ‘u201d’ was not declared in this scope
    testnewdhtanddisplay:56: error: ‘u201c’ was not declared in this scope
    testnewdhtanddisplay:60: error: ‘u20190’ was not declared in this scope
    testnewdhtanddisplay:69: error: expected ‘;’ before ‘u2013’
    testnewdhtanddisplay.ino: In function ‘void setup()’:
    testnewdhtanddisplay:76: error: expected unqualified-id before ‘.’ token
    testnewdhtanddisplay.ino: In function ‘void loop()’:
    testnewdhtanddisplay:81: error: expected primary-expression before ‘.’ token
    testnewdhtanddisplay:82: error: expected primary-expression before ‘.’ token
    testnewdhtanddisplay:88: error: ‘u201dBad’ was not declared in this scope
    testnewdhtanddisplay:90: error: found ‘:’ in nested-name-specifier, expected ‘::’
    testnewdhtanddisplay:90: error: ‘u201dHumidity’ has not been declared
    testnewdhtanddisplay:92: error: ‘u201d’ was not declared in this scope
    testnewdhtanddisplay:93: error: found ‘:’ in nested-name-specifier, expected ‘::’
    testnewdhtanddisplay:93: error: ‘u201dTemp’ has not been declared
    testnewdhtanddisplay:95: error: ‘u201dF’ was not declared in this scope
    stray ‘\’ in program

    What I’ve done to fix it is change the DHTPin line to separate into 2 lines and replaced all instances of dht with DHT which removed some errors but beyond that I’m stumped, are you able to help?

  10. Part of the problem is that, at least what you posted, is missing several INCLUDE statements, the quotes are wrong (” instead of “, did you use Word?) and there are non-ASCII characters in the source. If you copied from this web page, you need to paste in NOTEPAD then save that. Pasting into anything else that does not strip non-Ascii characters will result in awful things. So…fix the INCLUDES and that should correct the ‘was not declared in this scope’ errors. Fix the quotes everywhere. The thing that stumps me are the lines about the backslash. Have not figured that out yet. I suspect it has something to do with copying from the browser and pasting into Word or the IDE.

    1. yeah, the includes have been taken out by the web page, presuming because of the format and being outside of

       

      has probably snaffled them up, they are there in the IDE though, which is where I directly pasted.

      Have just tried again, using notepad as a go between and I’m still having the same problem compiling which is odd. I made all the changes you suggested as well, here’s the code I’m using, hoping that the formatting doesn’t get grabbed:

      #include <SoftwareSerial.h>
      #include <IIC_without_ACK.h>
      #include "oledfont.c"
      
      #define OLED_SDA 8
       #define OLED_SCL 9
      
      IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl
      
      /*
       * DHT Temperature Sensor
       // Connect DHT pin 1 (on the left) of the sensor to +5V
       // Connect DHT pin 2 of the sensor to whatever your DHTPIN is
       // Connect DHT pin 3 (on the right) of the sensor to GROUND
       */
      
      // include the library code
      
      #include <TinyDHT.h>        // lightweight DHT sensor library
      #include <avr/power.h>      // needed to up clock to 16 MHz on 5v Trinket
      
      // Uncomment whatever type sensor you are using!
       #define DHTTYPE DHT11 // DHT 11
       //#define DHTTYPE DHT22 // DHT 22 (AM2302)
       //#define DHTTYPE DHT21 // DHT 21 (AM2301)
       #define TEMPTYPE 1 // Use Fahrenheit (0 for celsius)
       #define DHTPIN 2 //define DHT pin
       DHT dht (DHTPIN, DHTTYPE); // Define Temp Sensor
       static unsigned char *spt;
       /***************************************************************************/
       static void pushb(const char b)
       {
       spt–-;
       *spt = b;
       }
      
      /***************************************************************************/
       static unsigned char popb()
       {
       unsigned char b;
       b = *spt;
       spt++;
       return b;
       }
      
      /***************************************************************************/
       void printnum(unsigned char x, unsigned char y, int num)
       {
       char st[]=” “;
      int digits=0;
       int pos=0;
      
      if(num 0);
       while(digits > 0)
       {
       st[pos]=popb();
       x++;
       digits–-;
      pos++;
       }
       oled.Char_F6x8(x,y, st);
       }
      
      void setup() {
       dht.begin(); // Initialize DHT Teperature Sensor
       oled.Initial();
       }
      
      void loop() {
       int8_t h = dht.readHumidity(); // Read humidity
       int16_t t = dht.readTemperature(TEMPTYPE); // read temperature
      
      delay(2000);
       oled.Fill_Screen(0x00);
      
      if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions (see TinyDHT.h)
       oled.Char_F6x8(0,0,”Bad Read on DHT”); // print error message
       } else {
       oled.Char_F6x8(0,2,”Humidity:”);
      printnum(60,2,h);
       oled.Char_F6x8(78,2,”%”);
      oled.Char_F6x8(0,4,”Temp: “);
      printnum(36,4,t);
       oled.Char_F6x8(50,8,”F”);
       }
      delay(800); // Read temp every second (2000 ms) (DHT sensor max rate)
       }
      

      I’m hoping that the formatting gets saved by the code tags, maybe …

      I am wondering if the problem is actually in the libraries rather than the code itself though as the “/” error repeating doesn’t seem very relevant to what’s on the screen. I’m still very new to all this though so probably very wrong :p

      Thanks for coming back to me so quickly 🙂

  11. OK, I think much of the problem stemmed from copying the source from this page. I tried it and got many of the same errors. Looks like WordPress may have changed the quotes, and nothing you did caused that. Also, the less-than character was lost, that caused problems and the double minus on the SPT- and DIGITS- was replaced.
    #include

    #include
    #include
    #include “oledfont.c”

    #define OLED_SDA 8
    #define OLED_SCL 9

    IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl

    /*
    * DHT Temperature Sensor
    // Connect DHT pin 1 (on the left) of the sensor to +5V
    // Connect DHT pin 2 of the sensor to whatever your DHTPIN is
    // Connect DHT pin 3 (on the right) of the sensor to GROUND
    */

    // include the library code

    #include // lightweight DHT sensor library
    #include // needed to up clock to 16 MHz on 5v Trinket

    // Uncomment whatever type sensor you are using!
    #define DHTTYPE DHT11 // DHT 11
    //#define DHTTYPE DHT22 // DHT 22 (AM2302)
    //#define DHTTYPE DHT21 // DHT 21 (AM2301)
    #define TEMPTYPE 1 // Use Fahrenheit (0 for celsius)
    #define DHTPIN 2 //define DHT pin
    DHT dht (DHTPIN, DHTTYPE); // Define Temp Sensor
    static unsigned char *spt;
    /***************************************************************************/
    static void pushb(const char b)
    {
    spt–;
    *spt = b;
    }

    /***************************************************************************/
    static unsigned char popb()
    {
    unsigned char b;
    b = *spt;
    spt++;
    return b;
    }

    /***************************************************************************/
    void printnum(unsigned char x, unsigned char y, int num)
    {
    char st[]=” “;
    int digits=0;
    int pos=0;

    if(num 0);
    while(digits > 0)
    {
    st[pos]=popb();
    x++;
    digits–;
    pos++;
    }
    oled.Char_F6x8(x,y, st);
    }

    void setup() {
    dht.begin(); // Initialize DHT Teperature Sensor
    oled.Initial();
    }

    void loop() {
    int8_t h = dht.readHumidity(); // Read humidity
    int16_t t = dht.readTemperature(TEMPTYPE); // read temperature

    delay(2000);
    oled.Fill_Screen(0x00);

    if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions (see TinyDHT.h)
    oled.Char_F6x8(0,0,”Bad Read on DHT”); // print error message
    } else {
    oled.Char_F6x8(0,2,”Humidity:”);
    printnum(60,2,h);
    oled.Char_F6x8(78,2,”%”);
    oled.Char_F6x8(0,4,”Temp: “);
    printnum(36,4,t);
    oled.Char_F6x8(50,8,”F”);
    }
    delay(800); // Read temp every second (2000 ms) (DHT sensor max rate)
    }
    Try this code and let us know if it works for you. It compiled for me, but I don’t have the actual circuit setup at the moment.

    Thanks for stopping by and apologies for the headache.

  12. Damn, Yeah, the site hosed the code. Any line that contains the ‘\’, retype it, manually. Also, make sure the double quotes are actually double quotes and not the open/close double quotes. I need to use the code tag from now on, I see that. My mistake. Also, the libraries are, likely, fine. It is the crappy formatting from my page that is your problem. When I get time, over the next couple of days, I’m going to repost the code, using the right format. I assure you, this code does work.
    Again, apologies for the problems.

  13. hah, compiled!!!

    #include <SoftwareSerial.h>
    #include <IIC_without_ACK.h>
    #include "oledfont.c"
    
    #define OLED_SDA 8
     #define OLED_SCL 9
    
    IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl
    
    /*
     * DHT Temperature Sensor
     // Connect DHT pin 1 (on the left) of the sensor to +5V
     // Connect DHT pin 2 of the sensor to whatever your DHTPIN is
     // Connect DHT pin 3 (on the right) of the sensor to GROUND
     */
    
    // include the library code
    
    #include <TinyDHT.h>        // lightweight DHT sensor library
    #include <avr/power.h>      // needed to up clock to 16 MHz on 5v Trinket
    
    // Uncomment whatever type sensor you are using!
     #define DHTTYPE DHT11 // DHT 11
     //#define DHTTYPE DHT22 // DHT 22 (AM2302)
     //#define DHTTYPE DHT21 // DHT 21 (AM2301)
     #define TEMPTYPE 1 // Use Fahrenheit (0 for celsius)
     #define DHTPIN 2 //define DHT pin
     DHT dht (DHTPIN, DHTTYPE); // Define Temp Sensor
     static unsigned char *spt;
     /***************************************************************************/
     static void pushb(const char b)
     {
     spt--;
     *spt = b;
     }
    
    /***************************************************************************/
     static unsigned char popb()
     {
     unsigned char b;
     b = *spt;
     spt++;
     return b;
     }
    
    /***************************************************************************/
     void printnum(unsigned char x, unsigned char y, int num)
     {
    char st[]=" ";
    int digits=0;
     int pos=0;
    
    if(num=0){
     while(digits > 0)
     {
     st[pos]=popb();
     x++;
     digits--;
    pos++;
     }
     oled.Char_F6x8(x,y, st);
     }
     }
    void setup()
    {
    dht.begin();
    oled.Initial();
     }
    
    void loop()
    {
     int8_t h = dht.readHumidity(); // Read humidity
     int16_t t = dht.readTemperature(TEMPTYPE); // read temperature
    
    delay(800);
     oled.Fill_Screen(0x00);
    
    if ( t == BAD_TEMP || h == BAD_HUM ) { // if error conditions (see TinyDHT.h)
    oled.Char_F6x8(0,0,"Bad Read on DHT"); //Print Error Message
     } else {
    oled.Char_F6x8(0,2,"Humiduty: ");
    printnum(60,2,h);
    oled.Char_F6x8(78,2,"%");
    oled.Char_F6x8(0,4,"temp: ");
    printnum(36,4,t);
    oled.Char_F6x8(50,8,"C");
     }
    delay(800); // Read temp every second (2000 ms) (DHT sensor max rate)
    }
    

    Thanks for your help there, if you hadn’t have pointed out the formatting problems I wouldn’t have got that one working 🙂 Now to see how it works with my screen 🙂

      1. gah, I take it back!! The code I put up wasn’t displaying the values for t or h, just the text. I had a look and have missed out part of one of the functions somehow, have fixed that and also make the DHT echo to serial monitor as well to test if it was the sensor at fault or the code. moved the fillscreen into setup as well to stop the blinking 🙂

        #include <SoftwareSerial.h>
        #include <IIC_without_ACK.h>
        #include "oledfont.c"
        
        #define OLED_SDA 8
        #define OLED_SCL 9
        
        IIC_without_ACK oled(OLED_SDA, OLED_SCL);//9 — sda,10 — scl
        
        /*
         * DHT Temperature Sensor
         // Connect DHT pin 1 (on the left) of the sensor to +5V
         // Connect DHT pin 2 of the sensor to whatever your DHTPIN is
         // Connect DHT pin 3 (on the right) of the sensor to GROUND
         */
        
        // include the library code
        
        #include <TinyDHT.h>        // DHT sensor library
        #include <avr/power.h>      // needed to up clock to 16 MHz on 5v Trinket
        
        // Uncomment whatever type sensor you are using!
        #define DHTTYPE DHT11 // DHT 11
        //#define DHTTYPE DHT22 // DHT 22 (AM2302)
        //#define DHTTYPE DHT21 // DHT 21 (AM2301)
        #define TEMPTYPE 1 // Use Fahrenheit (0 for celsius)
        #define DHTPIN 2 //define DHT pin
        DHT dht (DHTPIN, DHTTYPE); // Define Temp Sensor
        static unsigned char *spt;
        /***************************************************************************/
        static void pushb(const char b)
        {
          spt--;
          *spt = b;
        }
        
        /***************************************************************************/
        static unsigned char popb()
        {
          unsigned char b;
          b = *spt;
          spt++;
          return b;
        }
        
        /***************************************************************************/
        void printnum(unsigned char x, unsigned char y, int num)
        {
          char st[] = " ";
          int digits = 0;
          int pos = 0;
        
          if (num < 0)
          {
            num = -num;
            oled.Char_F6x8(x, y, st);
          }
        
          do {
            pushb(num % 10 + '0');
            num = num / 10;
            digits++;
          }
          while (num > 0);
          while (digits > 0)
          {
            st[pos] = popb();
            x++;
            digits--;
            pos++;
          }
          oled.Char_F6x8(x, y, st);
        }
        void setup() {
          Serial.begin(9600);
          Serial.println("DHT11 test!");
        oled.Fill_Screen(0x00);
          dht.begin();
        }
        
        void loop()
        {
          float h = dht.readHumidity();
          float t = dht.readTemperature();
        
          if (isnan(h) || isnan(t)) {
            oled.Fill_Screen(0x00);
            Serial.println("Failed to read from DHT sensor!");
            oled.Char_F6x8(0, 2, "Sensor Failed");
            oled.Fill_Screen(0x00);
            return;
          }
          oled.Char_F6x8(10, 2, "Bedroom Sensor");
          oled.Char_F6x8(0, 4, "Humidity: ");
          printnum(75, 4, h);
          oled.Char_F6x8(90, 4, "%");
          oled.Char_F6x8(0, 6, "Temperature: ");
          printnum(75, 6, t);
          oled.Char_F6x8(90, 10, "C");
        
          Serial.print("Humidity: ");
          Serial.print(h);
          Serial.print(" %\t");
          Serial.print("Temperature: ");
          Serial.print(t);
          Serial.println(" *C ");
          delay(800); // Read temp every second (2000 ms) (DHT sensor max rate)
        }
        

        My next job is to wire that all through a CC3000 wifi module and print off a nice box for it all to live in 😀

      2. Very nice, let us know when you finish it. If you like, you can write up a short ditty on what you did and how did it, a photo or two and I’ll put it up on the blog. I would be interested in seeing your 3d printed enclosure, that’s one of the next things I want to get into, 3d printing.

  14. The enclosure is one I made myself with some plywood, nothing too special really. The printer itself is a Prusa i3, which is brilliant. The one bit of advice I’d give you though, is to not buy cheap kit for the printer. I did that and then spent a LOT of extra money, time and frustration getting it working. I really wish I’d spent the extre money for a pre-fab one and got it working out of the box instead of spending the first month of owning it on tinkering around to make it run. I’ll flick you some picks of the enclosure when I’m at home thoguh, it’s a fun project in itself if you want to make it cool 🙂

    1. No, I won’t buy a kit, it will be assembled. There are a few in the two to four hundred range. Small, but functional. Prices should come down even more…I hope.

      1. yeah, once you’ve got them they’re actually very cheap to operate so spending the money up front is definitely the best way to go. The main consideration should be build area size, even as 200x200x180 I often find myself wanting more room and having to think of ways to join pieces together

Leave a comment