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.
And here is a picture of the actual thing, working with a CR2032 Coin Cell:
The Libraries I am using are:
- OLED Libraries for ATTiny85 - Source: http://www.14core.com/wiring-digispark-attiny85-with-096-oled-screen-display/
- Rob Tillaart DHT Library - Source: https://github.com/RobTillaart/Arduino/tree/master/libraries
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("[email protected]");
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.
DHT.read11(DHT11_PIN);
commented? You have to perform a read before accessing the variables...