From 58d27a79d5a649f1f195dac3365b8d37e0514ca6 Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Sun, 3 May 2020 13:08:13 +0100 Subject: [PATCH 1/4] Update to the correct distance call It looks like the `distance property replaces the `dist_cm()` function. Also gave a hint here that the board pin objects are needed, and not just integers. --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 56d0263..9e3f952 100644 --- a/README.rst +++ b/README.rst @@ -99,7 +99,7 @@ Without a Context Manager ------------------------- In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then -de-initialize the device. +de-initialize the device. Note trig and echo should come from the `board` module - they aren't just integers. :: @@ -107,7 +107,7 @@ de-initialize the device. sonar = HCSR04(trig, echo) try: while True: - print(sonar.dist_cm()) + print(sonar.distance) sleep(2) except KeyboardInterrupt: pass @@ -127,7 +127,7 @@ us. with HCSR04(trig, echo) as sonar: try: while True: - print(sonar.dist_cm()) + print(sonar.distance) sleep(2) except KeyboardInterrupt: pass From 8f69e91ca19a84e221cc620758e481a6b95e6344 Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Sun, 21 Jun 2020 12:20:52 +0100 Subject: [PATCH 2/4] Swap the note for example from example code Updating based on PR comments --- README.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 9e3f952..7a9fa93 100644 --- a/README.rst +++ b/README.rst @@ -99,12 +99,12 @@ Without a Context Manager ------------------------- In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then -de-initialize the device. Note trig and echo should come from the `board` module - they aren't just integers. +de-initialize the device. :: - + import board from adafruit_hcsr04 import HCSR04 - sonar = HCSR04(trig, echo) + sonar = HCSR04(trigger_pin=board.D5, echo_pin=board.D6) try: while True: print(sonar.distance) @@ -122,9 +122,9 @@ instance, again get the distance every 2 seconds, but then the context manager h us. :: - + import board from adafruit_hcsr04 import HCSR04 - with HCSR04(trig, echo) as sonar: + with HCSR04(trigger_pin=board.D5, echo_pin=board.D6) as sonar: try: while True: print(sonar.distance) From 88f34e75829819490b64d8fd4140965855720b84 Mon Sep 17 00:00:00 2001 From: FoamyGuy Date: Sun, 21 Jun 2020 08:26:06 -0500 Subject: [PATCH 3/4] fix docs building --- README.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 7a9fa93..6fb1074 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ See Also: `_ (the guide linked was written for the pyboard, but it still works), then input the following: - :: + .. code-block:: python import board dir(board) @@ -101,7 +101,8 @@ Without a Context Manager In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then de-initialize the device. -:: +.. code-block:: python + import board from adafruit_hcsr04 import HCSR04 sonar = HCSR04(trigger_pin=board.D5, echo_pin=board.D6) @@ -121,7 +122,8 @@ In the example below, we use a context manager (the `with Date: Wed, 19 Aug 2020 23:08:43 -0500 Subject: [PATCH 4/4] make readme example match simpletest --- README.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 6fb1074..974de9d 100644 --- a/README.rst +++ b/README.rst @@ -98,21 +98,22 @@ See Also: Without a Context Manager ------------------------- -In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then -de-initialize the device. +In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds. .. code-block:: python + import time import board - from adafruit_hcsr04 import HCSR04 - sonar = HCSR04(trigger_pin=board.D5, echo_pin=board.D6) - try: - while True: - print(sonar.distance) - sleep(2) - except KeyboardInterrupt: - pass - sonar.deinit() + import adafruit_hcsr04 + + sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6) + + while True: + try: + print((sonar.distance,)) + except RuntimeError: + print("Retrying!") + time.sleep(2) With a Context Manager