diff --git a/hardware/PiSrf/README.md b/hardware/PiSrf/README.md index d9735f52..46c8c6f8 100644 --- a/hardware/PiSrf/README.md +++ b/hardware/PiSrf/README.md @@ -23,8 +23,10 @@ These can be any spare valid Pi GPIO pins. e.g. 7,11 +You can also set the repeat frequency of measurements - default 0.5 seconds. + Outputs a `msg.payload` with a number representing the range in cm. -Produces one measure every 0.5s - but only if the distance is different from the previous reading. +Produces one measure every 0.5s (by default) - but only if the distance is different from the previous reading. **Note:** we are using the actual physical pin numbers on connector P1 as they are easier to locate. diff --git a/hardware/PiSrf/nrsrf.py b/hardware/PiSrf/nrsrf.py index e226d1df..aafced33 100755 --- a/hardware/PiSrf/nrsrf.py +++ b/hardware/PiSrf/nrsrf.py @@ -15,6 +15,7 @@ GPIO.setwarnings(False) ECHO = 0 TRIGGER = 0 OLD = 0 +SLEEP = 0.5 def Measure(): start = 0 @@ -48,13 +49,14 @@ def Measure(): # Main program loop if len(sys.argv) > 1: pins = sys.argv[1].lower().split(',') - if len(pins) != 2: - print "Bad number of pins supplied" + if len(pins) != 3: + print "Bad parameters supplied" print pins sys.exit(0) TRIGGER = int(pins[0]) ECHO = int(pins[1]) + SLEEP = float(pins[2]) GPIO.setmode(GPIO.BOARD) # Use GPIO BOARD numbers GPIO.setup(TRIGGER, GPIO.OUT) # Trigger @@ -72,7 +74,7 @@ if len(sys.argv) > 1: if distance != OLD: print(distance) OLD = distance - time.sleep(0.5) + time.sleep(SLEEP) except: # try to clean up on exit print("0.0"); GPIO.cleanup(TRIGGER) @@ -81,5 +83,5 @@ if len(sys.argv) > 1: else: print "Bad params" - print " sudo nrsrf.py trigger_pin,echo_pin" + print " sudo nrsrf.py trigger_pin,echo_pin,rate_in_seconds" sys.exit(0) diff --git a/hardware/PiSrf/package.json b/hardware/PiSrf/package.json index 8285c878..0efbd041 100644 --- a/hardware/PiSrf/package.json +++ b/hardware/PiSrf/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-pisrf", - "version" : "0.0.5", + "version" : "0.1.0", "description" : "A Node-RED node for a Raspberry Pi to use a SRF04 or SRF05 range finder", "dependencies" : { }, diff --git a/hardware/PiSrf/pisrf.html b/hardware/PiSrf/pisrf.html index af0b26cd..5dfe2f6b 100644 --- a/hardware/PiSrf/pisrf.html +++ b/hardware/PiSrf/pisrf.html @@ -4,11 +4,14 @@ +