node_hcsr04 icon indicating copy to clipboard operation
node_hcsr04 copied to clipboard

not working -1 returned on all measurements

Open asmeureanu opened this issue 9 years ago • 5 comments

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.

asmeureanu avatar Oct 11 '16 18:10 asmeureanu

http://www.esp8266.com/viewtopic.php?f=23&t=9341

This class will not work on 1.5.1 onward

asmeureanu avatar Oct 12 '16 15:10 asmeureanu

have you found a solution to this problem?

pdesterlich avatar Apr 28 '17 13:04 pdesterlich

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.

asmeureanu avatar Apr 28 '17 14:04 asmeureanu

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

pdesterlich avatar Apr 28 '17 14:04 pdesterlich

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

andreas83 avatar Feb 09 '19 23:02 andreas83