ESP32 and DHT22 abort() crashes

Posted on
  • Hey guys,

    thank you for this great project! Currentyl I'm just playing around with some sensors with my ESP32. I'm pretty new to microcontrollers.

    I just got a SSD1306 working with espruino on my ESP32, it works flawless. Yesterday I had to connect a DHT22 and my ESP32 keeps crashing after a few measurements of the temp. This code isn't that spectacular, but I really don't know why its crashing. I always get that message:

    WARNING: jshI2CSetup: driver installed, sda: 21 sdl: 22 freq: 50000,
    =undefined
    Booting up...
    Temp: 22.1°C | RH: 40%
    Temp: 22.1°C | RH: 39.7%
    abort() was called at PC 0x4008280b on core 0
    Backtrace: 0x40087818:0x3ffb04a0 0x40087917:0x3ffb04c0 0x4008280b:0x3ffb04e0 0x400828f9:0x3ffb0510 0x400d3256:0x3ffb0530 0x400829d4:0x3ffb0550 0x40116595:0x3ffb0570 0x40082c9e:0x3ffb0590 0x40082b78:0x3ffb05c0 0x40082c73:0x3ffb05e0 0x40081711:0x3ffb0600
    ================= CORE DUMP START =================

    After the core dump I see:

    E (29281) esp_core_dump: Skipped 1 tasks with bad TCB!
    E (29326) esp_core_dump: Crashed task has been skipped!
    Rebooting...
    ets Jun 8 2016 00:22:57
    rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0x00
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_d­rv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0008,len:8
    load:0x3fff0010,len:1932
    ho 0 tail 12 room 4
    load:0x40078000,len:10012
    load:0x40080000,len:252
    entry 0x40080034

    It doesn't matter how often I read the DHT. It crashes after two measurements and after none.
    The DHT is connected to GPIO15 with a pullup resistor (10k). It keeps crashing even without WiFi and a webserver. You can see my wiring (without the oled) attached.

    My code:

    I2C1.setup({scl:D22,sda:D21});
    var g = require("SSD1306").connect(I2C1, start,{
      contrast: 255 
    });
    
    require("FontDennis8").add(Graphics);
    g.setFontDennis8();
    
    function start(){
      log("Booting up...");
      var ssid = "SSID";
      var pw = "PW";
      
      readTemp(D15);
      
      if(connectWifi(ssid, pw)){
       if(startWebserver(8080)){
          log("Let's get started!"); 
       }  
      }
    }
    
    function connectWifi(ssid, password){
      var wifi = require('Wifi');
      //wifi.setHostname("Disane_ESP32");
      var ip = wifi.getIP().ip;
      if(ip != "0.0.0.0" && ip){
        log("IP: "+ip);
        return true;
      }else{
        wifi.connect(ssid, {password: password}, function(err) {
          if (err) {
            log("Connection error: "+err);
            return false;
          }
          log('Connected to Wifi: '+ ip);
          //wifi.save(); // Next reboot will auto-connect
          return true;
        });
      }
    }
    
    function startWebserver(port){
      log("Starting Webserver...");
      var http = require("http");
      http.createServer(function (req, res) {
        res.writeHead(200);
        res.end("Hello World");
      }).listen(port);
      return true;
    }
    
    
    function readTemp(pin){
      
      //log("Reading temp and RH");
      //pinMode(D15, input_pullup);
      var dht = require("DHT22").connect(pin);
      setInterval(function(){
        dht.read(function (a) {
          if(a.err){
            log("Error | checksumError: "+a.checksumError);
          }else{
            log("Temp: "+a.temp.toFixed(2).toString()+"°C | RH: "+a.rh.toFixed(2).toString()+"%", 8);
          }
        });
      },5*1000);
    }
    
    
    
    function log(text, fs = 5){
      g.clear();
      console.log("["+Date.now() +"]: " +text);
      //g.setFontVector(fs);
      g.drawString(text,2,2);
      // write to the screen
      g.flip();
    }
    

    Does anybody of you have a clue?


    1 Attachment

    • ESP32_DHT22.png
  • Sorry, there is an issue with setwatch and that is probably what the DHT module is using.

    It has been raised on GitHub, however no one has sorted it out.

  • ^^ this - DHT11 and DHT22 definitely use setWatch (and also clearWatch)

  • You mean this issue on github? https://github.com/espruino/Espruino/iss­ues/643

    Is there any ETA to fix this?

  • It's this one: https://github.com/espruino/Espruino/iss­ues/1176

    setWatch works fine on ESP8266.

    I'm afraid there's no ETA. Nobody makes anything off the ESP8266 or ESP32 ports, so it's very much a free-time project by members of the Espruino community like @Wilberforce. It'll get fixed when they feel like it or have a need for it in one of their own projects :)

    If you need something where someone takes an active role in fixing issues then get an official Espruino board - they're a little more expensive, but that directly pays my salary so I can work full-time to make sure things get fixed in a timely manner :)

  • Ah okay :) Sorry! I guess I have to switch to another solution in the meanwhile. But that projects is very promising!

  • The setwatch issue has been fixed.

    It will be in version 1v95, so for now a latest travis build will work:
    http://www.espruino.com/binaries/travis/­master/

  • wow, thank you! :)

  • I have nearly the exace same problem.
    I have baught and received one of those cheap TTGO ESP32 with OLED and batterypack two days ago.
    I have downloaded 1v95, setup my folders/project and previously with the ESP8622 i had used thingssdk as a toolchain so i could stay in my editor, but that didn't work anymore with the ESP32. So i changed to the IDE, which is ... well it is something, but i prefer sublime and a console. And it seems slower than before. But i can live with that.

    So far the OLED runs without any change to my old code, great! But the DHT22 makes me sad.
    My code is basically that from the OP, i have connected the D-pin from the DHT with D15 on my board, i even threw in a 10kRes.
    but all i get is a checksumError:

    #3987[r1,l1] Object {
      #4008[r1,l2] Name String [1 blocks] "err"    #4007[r1,l1] Bool true
      #4009[r1,l2] Name String [2 blocks] "checksumError"    #3994[r1,l1] Bool false
      #3986[r1,l2] Name String [1 blocks] "raw"    #4005[r2,l1] String [1 blocks] ""
      #4010[r1,l2] Name String [1 blocks] "temp"= int -1
      #4018[r1,l2] Name String [1 blocks] "rh"= int -1
    }
    

    so i guess i managed to damage my DHT or am i missing sth?

    mycode:

    let pin_DHT22 = D15; // D-out DHT22
    const DHT = require('DHT22').connect(pin_DHT22);
    // 
    const intval_temp_measure = 10 * 1000; // every n second
    let intval_temp_measure_id = null;
    //
    const measureInterval = function() {
        DHT.read(function (a) {
          if(a.err) {
             trace(a); 
          }
            let temp = a.temp.toString();
            let rh = a.rh.toString();
            //if(a.raw.length > 3)
              drawMeasurement(temp, rh);
        });
    };
    // 
    let temps = []; // store temperature data for some time
    // 
    let sig = false; 
    const drawMeasurement = function(temp, rh){
        // wipe clean
        OLED.clear();
        
        if(temp === undefined) {
            OLED.setFontBitmap();
            OLED.setFont8x12();
            OLED.drawString('Warte auf Daten ...', 1, 1);
        } else {
            if(temps.length >= 124) { // we can only draw so much on the x-axis
                temps.shift(); // remove first entry
            }
            temps.push(temp);
    
            //  draw chart:
            //  we have: x => 2 -> 126 and y => 22 -> 62
            for(var t = 0; t < temps.length; t++) {
                var y = temps[t] + 22 ;
                var x = t + 2;
            }
    
            // OLED.setFontBitmap();
            // OLED.setFont8x12();
            // OLED.drawString('Aktuelle Temperatur:', 0, 0);
            // 
            OLED.setFontVector(15);
            OLED.drawString(temp + ' C', 1, 1);
            //
            // OLED.setFontBitmap();
            // OLED.setFont8x12();
            // OLED.drawString('Luftfeuchtigkeit:', 0, 15);
            // 
            OLED.setFontVector(12);
            OLED.drawString(rh + ' %', 74, 2);
        }
        // draw some borders
        /*
        ________|________
        |                |
        |                |
        |________________|
        */
        //            x1  y1  x2  y2
        OLED.drawLine(64, 0, 64, 21);
        OLED.drawLine(0, 21, 127, 21);
    
        OLED.drawLine(0, 21, 0, 64);
        OLED.drawLine(127, 21, 127, 64);
        
        OLED.drawLine(0, 63, 127, 63);
    
        // refresh
        OLED.flip();
        return 'temp.: ' + temp + ' C, hum.: ' + rh + ' %';
    };
    //  ----------------------------------------­--------
    let pin_OLED_SCL = D4; // onboard
    let pin_OLED_SDA = D5; // onboard
    // PRECONF
    I2C1.setup({
        scl: pin_OLED_SCL,
        sda: pin_OLED_SDA
    });
    require('Font8x12').add(Graphics);
    let OLED = null;
    // 
    function testOLED(){
        log('writing on OLED');
        OLED.clear();
        //OLED.setFontBitmap();
        OLED.setFont8x12();
        // write some text
        OLED.drawString("loading ...", 2, 2);
        // write to the screen
        OLED.flip();
    }
    
    function main () {
        log('main started');
        let OLED_options = {
            address: 0x3C
        };
        OLED = require("SSD1306").connect(I2C1, testOLED, OLED_options);
        //OLED.off();
        intval_temp_measure_id = setInterval(measureInterval, intval_temp_measure);
        measureInterval();
    }
    
    function init() {
        //OLED.on();
        log('program start ...');
        main();
    }
    setTimeout(init, 1500);
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ESP32 and DHT22 abort() crashes

Posted by Avatar for Disane87 @Disane87

Actions