2

Good day.

I am making a small weather station using ATTiny85, DHT11, and an OLED display.

There are many, many tutorials that explain how this works, and various libraries that show you how to get the DHT11 to work with the ATTiny85 and others that are dedicated to the SSD1306 Oled displays, some even show you how to combine them together. Well, for the better part of 2 days nothing worked for me.

My schematics is as follows: enter image description here

And here is a picture of the actual thing, working with a CR2032 Coin Cell:

enter image description here

The Libraries I am using are:

My Code is as follows:

    //OLED Libraries for ATTiny85 - Source: http://www.14core.com/wiring-digispark-attiny85-with-096-oled-screen-display/

#include <font6x8.h>
#include <font8x16.h>
#include <num2str.h>
#include <ssd1306xled.h>
#include <ssd1306xled8x16.h>
#include <SSD1306_minimal.h>
#include <TinyWireM.h>
#include <USI_TWI_Master.h>

#define DEG "\xa7" "C"

SSD1306_Mini oled;

char strHum[4];
char strTemp[4]; 

#include <dht.h>
dht DHT;
#define DHT11_PIN 1


void setup()
{


  TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos
  oled.init(0x3c);
  oled.clear();



}


void loop()
{

  //            DHT Code goes here                              //

  DHT.read11(DHT11_PIN); //Calling the read function

  float hu  = (DHT.humidity, 1);
  float te  = (DHT.temperature, 1);



  //            OLED Start -- DO NOT CHANGE ANYTHING            //

  //oled.clear();

  oled.startScreen();
  oled.cursorTo(10, 0);
  oled.printString("ATTiny85 & DHT11");

  oled.startScreen();
  oled.cursorTo(12, 9);
  oled.printString("Temp & Humidity");

  oled.startScreen();
  oled.cursorTo(10, 18);
  oled.printString("www.MDChaara.com");

  oled.startScreen();
  oled.cursorTo(0, 27);
  oled.printString("mdchaara@gmail.com");


  oled.startScreen();
  oled.cursorTo(0, 45);
  oled.printString("Humidity(%): ");

  oled.startScreen();
  oled.cursorTo(110, 45);
  oled.printString( itoa(int(hu), strHum, 10));


  oled.startScreen();
  oled.cursorTo(0, 55);
  oled.printString("Temperature(c): ");


  oled.startScreen();
  oled.cursorTo(110, 55);
  oled.printString( itoa(int(te), strTemp, 10));


  //            OLED End          //


  delay(5000);
}

Now I know that the OLED code works, and it was a very interesting round or research to get it to work. The DHT code is another story. I have tried 6 different libraries and none of them worked. They all either return 0, 1, or blank readings on the screen.

I have checked if the sensor is working with an Uno and a Nano, works well! I checked the connections, and the soldered parts and did continuity tests, but the issue still remains.

I am asking because I am hoping a fresh set of eyes can pin-point the issue that I am facing. Any help will be highly appreciated.

  • Arduino IDE: 1.8.2
  • OS: Windows 7 64 bits
  • Micro controller: ATTiny85-20PU

Sketch is uploaded to the micro controller using Arduino Uno as a programmer. Sketch is uploaded at Internal 8MHz clock setting.

Thank You.

  • 1
    Is that second pin of the DHT, the one that goes to the ATTiny pin, supposed to also be connected to +3V like that? Pretty sure there was supposed to be a resistor there. You should probably also include some decoupling caps on the power lines. 0.1uF as close as you can get to the power pins of the ATTiny. – Delta_G Jun 7 '17 at 2:05
  • 1
    Why is the line DHT.read11(DHT11_PIN); commented? You have to perform a read before accessing the variables... – frarugi87 Jun 7 '17 at 12:08
  • 1
    itoa() is for converting an integer to ascii, but you are giving it a float. It works on a PC (Visual Studio), but you might want to check it works under GCC. Also what happens if itoa returns more than 4 characters? You might want to consider putting the strings in flash? I think you prefix them with T?? (Please someone help!!) – Code Gorilla Jun 7 '17 at 12:15
  • 1
    @CodeGorilla - You are right, but changing the type does not help. I did try to read it from DHT as an int (didn't work), pass it to itoa() as an int (didn't work), and as a float (also didn't work). itoa() would never pass more than 4 characters, but I have non the less changed a few things in the code. Please have a look and check if you can spot something. Thank you for the comment, and the call for help. – MDChaara Jun 7 '17 at 12:43
  • 2
    @MDChaara you said that you are using Rob Tillaart's library. This library (actually there are two, but they work the same) REQUIRES you to call the read function before getting the results from the object. See this example – frarugi87 Jun 7 '17 at 13:17
1

my tryout build, the uno you see is just the "programmer" script runs on the Attiny85

Ok i tried something like that for myself and thanks to this and ..many other posts and forums/videos i could make myself something that works but with a little other setting like in the start post (other libs ect)

in my case the main reason for the "1" output on the oled was this:

  float hu  = (DHT.humidity, 1);    //original

  hu  = (DHT.humidity);       //what worked for me 

Maybe you can figure out more Problems, my code is shure not perfekt! But maybe it helps someone for a vew steps

#include <dht.h>
#include <U8x8lib.h>
#define DHT11_PIN 1
dht DHT;
int temp = 0;
int humi = 0;
char strTemp[4]; 
char strHumi[4];

U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 2, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE);         // Digispark ATTiny85 Pin 0 Data, Pin 2 clock



void setup(void)
{

  u8x8.begin();
  u8x8.setPowerSave(0); //enegergiesparen 0 aus

}

void loop(void)
{

  int chk = DHT.read11(DHT11_PIN);

  temp = (DHT.temperature);
  humi = (DHT.humidity);



  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(0,0,"~~~~~~~~~~~~~~~~");
  u8x8.drawString(0,1,"Temperatur");
  u8x8.drawString(1,2,( itoa(int(temp), strTemp, 10)));
  u8x8.drawString(4,2,"Grad Celsius");
  u8x8.drawString(1,3,"--------------");
  u8x8.drawString(0,4,"Luftfeuchtigkeit");
  u8x8.drawString(1,5,( itoa(int(humi), strHumi, 10)));
  u8x8.drawString(4,5,"Prozent");
  u8x8.drawString(0,6,"~~~~~~~~~~~~~~~~");
  delay(200);
}
0

The DHT11 is notoriously slow to respond and often returns null for readings sporadically. I notice in your second circuit you have resistors by the sensor but I cant see what pins they are connected to. You will need pullup for the sensor data line 4K7 usually does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.