Current Lua downloadable firmware will be posted here

User avatar
By pyr0ball
#82673 I'm running around an ESP32 that I'm trying to integrate with a few modules. 99% of the code examples I'm finding are originally for the ESP8266, and have some depreciated stuff like gpio.mode instead of gpio.config, but I've been able to address that for the most part.

The one thing that's really holding me up right now is that I can't seem to find any equivalent to tmr.delay() with the new timer module in the esp32-dev branch. The documentation is pretty sparse on this particular topic, and for someone who's not super familiar with how to use timers already, it's become a bit of a roadblock.

I already nearly bricked my ESP32 by getting the thing into an infinite bootloop that I nearly couldn't get it out of (bootloader mode wasn't working even pulling GPIO0 low on boot). Anyhoo, if someone could point me toward a more verbose explanation of the tmr module, or at least tell me how to set a fixed delay time, I'd be incredibly grateful!

Thanks in advance!
User avatar
By pyr0ball
#82684 So while I was waiting for mod approval on the post, I did more research.

I realize that the builting dht library actually does work, I just wanted to use a separate functions file as I've been using for all of the other modules (ws2812 / ssd1306 / wifi / ect) which all seem to work the way I expect. I tried writing my own but I'm definitely getting my syntax wrong somehere because it's returning a bunch of nil call field exceptions:

Code: Select alllua: init.lua:25: attempt to call field 'getTemp' (a nil value)


Here's the lua file I wrote for reference, and my init:

Code: Select all-- dht_sensor.lua
-- DHT Sensor
dhtpin = 4

local Dt = {}

local humi
local temp
local temp_dec
local humi_dec

function Dt.read(dhtpin)
    status, temp, humi, temp_dec, humi_dec = dht.read2x(dhtpin)
    if status == dht.OK then
        print( "DHT Sensor reading good.")
        -- Integer firmware using this example
        --print(string.format("DHT Temperature:%d.%03d;Humidity:%d.%03d\r\n",
        --      math.floor(temp),
        --      temp_dec,
        --      math.floor(humi),
        --      humi_dec
        --))
   
        -- Float firmware using this example
        -- print("DHT Temperature:"..temp..";".."Humidity:"..humi)
   
    elseif status == dht.ERROR_CHECKSUM then
        print( "DHT Checksum error." )
    elseif status == dht.ERROR_TIMEOUT then
        print( "DHT timed out." )
    end
end

Dt.read = read

function Dt.getHumi()
    Dt.read(dhtpin)
    return humi
end
Dt.getHumi = getHumi

function Dt.getTemp()
    Dt.read(dhtpin)
    return temp
end
Dt.getTemp = getTemp

function Dt.getHumi_dec()
    Dt.read(dhtpin)
    return humi_dec
end
Dt.getHumi_dec = getHumi_dec

function Dt.getTemp_dec()
    Dt.read(dhtpin)
    return humi_dec
end
Dt.getTemp_dec = getTemp_dec

return Dt


Code: Select all-- Init.lua
print("Initializing...")

-- WS2812 Control
ws2812 = require("ws281x_leds")
--ws2812.chase(255, 0, 0)

-- Wifi init
wf = require("esp32_wifi")
wf.init()
wf.on("connection", function(info)
  print("Got wifi. IP:", info.ip, "Netmask:", info.netmask, "GW:", info.gw)
end)

-- I2C SSD1306
zd = require('zipwhip_oled')
zd.setupDisplay()
zd.showText("Hey there ", "check", "it out?")

-- DHT Sensor
print("Checking sensor")
dhts = require('dht_sensor')
dhtpin=4

dhts.getTemp()
dhts.getHumi()
print("DHT Temperature:"..temp..";".."Humidity:"..humi)
User avatar
By marcelstoer
#82696 The NodeMCU for ESP8266 documentation warn against using delay() at https://nodemcu.readthedocs.io/en/lates ... /#tmrdelay and https://nodemcu.readthedocs.io/en/lates ... g-tmrdelay. I guess this was the reason it wasn't ported to the ESP32 version.
User avatar
By pyr0ball
#82698 Yep, I noticed that while searching. mods hadn't approved my previous reply since this post, so we'll see what happens.

Update from the previous one to this, I managed to get a lot of the code I'm struggling with to work by including it as functions in the main init.lua instead of as separate files. I'm assuming my syntax for calling those functions is just wrong somehow.

I started a github repo for it. more than likely I'll find and fix more stuff as I go: https://github.com/pyr0ball/mini-greenhouser_ESP32-8266