From de3816f9172796722fb1b28dd14e2dcf61fbe8de Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Mon, 27 Jul 2020 10:46:10 +0100 Subject: [PATCH] Work around BCM8 edge detect/SPI issue for #1 --- install.sh | 0 library/grow/moisture.py | 14 +++++++++++++- library/setup.cfg | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) mode change 100644 => 100755 install.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 diff --git a/library/grow/moisture.py b/library/grow/moisture.py index 46db64e..b96e948 100644 --- a/library/grow/moisture.py +++ b/library/grow/moisture.py @@ -34,7 +34,19 @@ class Moisture(object): self._wet_point = wet_point if wet_point is not None else 0.7 self._dry_point = dry_point if dry_point is not None else 27.6 self._time_last_reading = time.time() - GPIO.add_event_detect(self._gpio_pin, GPIO.RISING, callback=self._event_handler, bouncetime=1) + try: + GPIO.add_event_detect(self._gpio_pin, GPIO.RISING, callback=self._event_handler, bouncetime=1) + except RuntimeError as e: + if self._gpio_pin == 8: + raise RuntimeError("""Unable to set up edge detection on BCM8. + +Please ensure you add the following to /boot/config.txt and reboot: + +dtoverlay=spi0-cs,cs0_pin=14 # Re-assign CS0 from BCM 8 so that Grow can use it + +""") + else: + raise e self._time_start = time.time() self._total_count = 0 diff --git a/library/setup.cfg b/library/setup.cfg index 79cc617..0b5f28b 100644 --- a/library/setup.cfg +++ b/library/setup.cfg @@ -64,4 +64,7 @@ commands = printf "Setting up i2c and SPI..\n" raspi-config nonint do_spi 0 raspi-config nonint do_i2c 0 +configtxt = + dtoverlay=spi0-cs,cs0_pin=14 # Re-assign CS0 from BCM 8 so that Grow can use it +