not working -1 returned on all measurements
I am able to make the module/setup work perfectly with the Arduino code and can confirm hardware is in proper order.
With this library unfortunately i get only -1 as a reading and sometimes 15 sporadically not sure what is the cause.
http://www.esp8266.com/viewtopic.php?f=23&t=9341
This class will not work on 1.5.1 onward
have you found a solution to this problem?
I dropped node and flashed arduino ... this ultrasonic sensor is a very basic thing ... and there is zero support ... the newer fw was breaking this lib.
Alexandru
On 28 Apr 2017, at 16:45, Phelipe de Sterlich [email protected] wrote:
have you found a solution to this problem?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
just in case you (or anyone else) are still remotely interested in using sr04 with lua, i've found (and slightly edited myself) some working code
function sr04read(pin_trig, pin_echo)
time_start = 0
time_end = 0
gpio.mode(pin_trig, gpio.OUTPUT)
gpio.mode(pin_echo, gpio.INPUT)
gpio.write(pin_trig, gpio.LOW)
tmr.delay(100000)
gpio.write(pin_trig, gpio.HIGH)
tmr.delay(10)
gpio.write(pin_trig, gpio.LOW)
while gpio.read(pin_echo) == 0 do
-- DoNothing(TM)
end
time_start = tmr.now()
while gpio.read(pin_echo) == 1 do
-- DoNothing(TM)
end
time_end = tmr.now()
time_duration = time_end - time_start
return time_duration / 58
end
it's not extremely accurate, but it's accurate enough for my use case
oh dear, next time i will have a look at the issue tracker first. took me hours to figure out that this is not my cricut, level shifter or sensor fault... i use the code from @vsserafim and it works brilliant: https://github.com/vsserafim/hcsr04-nodemcu