2016-12-02 29 views
0

我正在使用类似于霍尔效应传感器的传感器来计数中断次数。经过一段随机时间后,通常在开启1-2小时后,它会重置并随后随机重置随机间隔。是什么导致我的Nodemcu/ESP 8266重置?

counter = 0; 
sampletime = 0; 
lastrisetime = tmr.now() 
pin = 2 

do 
    gpio.mode(pin, gpio.INT) 

    local function rising(level) 
    -- to eliminate multiple counts during a short period (.5 second) difference is taken 
     if ((tmr.now() - lastrisetime) > 500000) then 
     lastrisetime = tmr.now(); 
    end 
    -- when tmr.now() resets to zero this takes into account that particular count 
    if ((tmr.now() - lastrisetime) < 0) then 
     lastrisetime = tmr.now(); 
    end 
    end 

    local function falling(level) 
    if ((tmr.now() - lastrisetime) > 500000) then 
     -- Only counted when the pin is on falling 
     -- It is like a sine curve so either the peak or trough is counted 
      counter = counter + 1; 
     print(counter) 
     lastrisetime = tmr.now(); 
     sampletime = lastrisetime; 
    end 
    -- when tmr.now() resets to zero this takes into account that particular count 
    if ((tmr.now() - lastrisetime) < 0) then 
     lastrisetime = tmr.now(); 
      counter = counter + 1; 
     print(counter) 
    end 
    end 

    gpio.trig(pin, "up", rising) 
    gpio.trig(pin, "down", falling) 
end 

这是我得到CoolTerm错误,我也检查了内存每隔几个小时,你可以在那里看到的结果。

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
22920 
> print(node.heap()) 
22904 
> print(node.heap()) 
22944 
> print(node.heap()) 
22944 
> 2. .print(node.heap()) 
22944 
> print(node.heap()) 
22944 
> ∆.)ç˛.䂸 ã ¸@H7.àåË‘ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
21216 
> F.)ç˛.¶Ùå¶[email protected]  .ÊÍ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
H!໩.ä‚D.ã ¸å¶H.åb‘ 

NodeMCU 0.9.6 build 20150704 powered by Lua 5.1.4 
> Connecting... 
connected 
print(node.heap()) 
22904 
> print(node.heap()) 
21216 
> 

感谢您花时间阅读本文。感谢您的意见。

+0

问题解决了吗?如果是这样,请考虑[upvoting/accepting](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)答案。 –

回答

0

可能的看门狗定时器问题。

在你的中断服务程序看起来像你等待太多。

更好地从那里删除定时操作,只需设置一个标志,并在另一个循环中,检查标志状态并完成您的定时操作。

0

NodeMCU 0.9.6构建20150704搭载的Lua 5.1.4

的第一件事情真的是用最近的NodeMCU固件版本。 0.9.x是古老的,包含大量的错误,不再支持。看到这里https://github.com/nodemcu/nodemcu-firmware/#releases

lastrisetime = tmr.now()

真正的问题是,tmr.now()轧在2147秒我相信。 I learned about this当我在proper debounce function工作。

-- inspired by https://github.com/hackhitchin/esp8266-co-uk/blob/master/tutorials/introduction-to-gpio-api.md 
-- and http://www.esp8266.com/viewtopic.php?f=24&t=4833&start=5#p29127 
local pin = 4 --> GPIO2 

function debounce (func) 
    local last = 0 
    local delay = 50000 -- 50ms * 1000 as tmr.now() has μs resolution 

    return function (...) 
     local now = tmr.now() 
     local delta = now - last 
     if delta < 0 then delta = delta + 2147483647 end; -- proposed because of delta rolling over, https://github.com/hackhitchin/esp8266-co-uk/issues/2 
     if delta < delay then return end; 

     last = now 
     return func(...) 
    end 
end 

function onChange() 
    print('The pin value has changed to '..gpio.read(pin)) 
end 

gpio.mode(pin, gpio.INT, gpio.PULLUP) -- see https://github.com/hackhitchin/esp8266-co-uk/pull/1 
gpio.trig(pin, 'both', debounce(onChange)) 
+0

感谢您的回复。是否有销售最新NodeMCU固件的可靠来源?我试图闪光它,但它没有工作,我发现只卖老洛林版 –

+0

“我试图闪光但它不起作用” - 那么你需要(学习如何)来解决这个问题。无论何时您需要更新的固件,订购新开发套件都是不可持续的:http://nodemcu.readthedocs.io/en/latest/en/flash/ –

相关问题