Hello,
The code is working. When AHT10 is reachable there is no problem. But if it is not attached I get the WDT error.
Heres the entire code:
Code: Select all
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_AHTX0.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_AHTX0 aht;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
delay (4000);
Wire.begin (2,0);
while (!Serial) {
; // wait for serial port to connect
}
Serial.println("ESP01-t/h-V1.00i");
if (!aht.begin()) {
Serial.println("Could not find AHT10 sensor!");
while (1);{
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("X AHT10");
}
}
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.setBrightness(128);
display.clearDisplay();
display.display();
}
void loop() {
sensors_event_t humidity, temp;
int tempi, rheli;
aht.getEvent(&humidity, &temp);
// Print to serial port
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.print(" ");
Serial.print(char(247));
Serial.print("C | Humidity: ");
Serial.print(humidity.relative_humidity);
Serial.println(" %");
// Display on OLED
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
tempi = round(temp.temperature*10);
display.print("Tm:" + String(tempi/10)+"."+String(tempi%10)+" "+char(247)+"C");
display.setCursor(0,18);
rheli = round(humidity.relative_humidity);
display.print("rH:");
display.print(rheli,1);
display.print(" %");
display.display();
delay(2000); // wait a few seconds between readings
}
Here is the code snippet where the code crashes. It should keep blinking the LED if AHT10 is not accessible.
Code: Select all
if (!aht.begin()) {
Serial.println("Could not find AHT10 sensor!");
while (1);{
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("X AHT10");
}
}
But I only get the output of the first line. Then WDT kicks in and all I get is WDT crashes and starts to send crashdump:
Code: Select all
Could not find AHT10 sensor!
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90: 3fffdad0 3ffee5b8 3ffee6f4 40201091
3fffffa0: feefeffe 00000000 3ffee748 40203af4
<<<stack<<<
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v000460d0
~ld