From d3b10d29b031d0fa8d6569f2302da5cd6f11b922 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 20 Aug 2024 22:34:29 -0600 Subject: [PATCH] Add output pin inversion, update docs. --- README.md | 2 ++ config.py | 11 ++++++----- docs/old-to-new.md | 1 + gpioreadall.py | 22 +++++++++++++--------- lib/oven.py | 7 +++++-- test-output.py | 9 ++++++--- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1d2bde0..66d21d9 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,8 @@ My controller plugs into the wall, and the kiln plugs into the controller. **WARNING** This project involves high voltages and high currents. Please make sure that anything you build conforms to local electrical codes and aligns with industry best practices. +**Note:** The GPIO configuration in this schematic does not match the defaults, check [config](https://github.com/jbruce12000/kiln-controller/blob/main/config.py) and make sure the gpio pin configuration aligns with your actual connections. + ![Image](https://github.com/jbruce12000/kiln-controller/blob/main/public/assets/images/schematic.png) *Note: I tried to power my ssr directly using a gpio pin, but it did not work. My ssr required 25ma to switch and rpi's gpio could only provide 16ma. YMMV.* diff --git a/config.py b/config.py index 5e12ec5..c133e9c 100644 --- a/config.py +++ b/config.py @@ -84,11 +84,12 @@ currency_type = "$" # Currency Symbol to show when calculating cost to run j try: import board - spi_sclk = board.D17 #spi clock - spi_miso = board.D27 #spi Microcomputer In Serial Out - spi_cs = board.D22 #spi Chip Select - spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected) - gpio_heat = board.D23 #output that controls relay + spi_sclk = board.D17 #spi clock + spi_miso = board.D27 #spi Microcomputer In Serial Out + spi_cs = board.D22 #spi Chip Select + spi_mosi = board.D10 #spi Microcomputer Out Serial In (not connected) + gpio_heat = board.D23 #output that controls relay + gpio_heat_invert = False #invert the output state except (NotImplementedError,AttributeError): print("not running on blinka recognized board, probably a simulation") diff --git a/docs/old-to-new.md b/docs/old-to-new.md index 9a7d343..dba6332 100644 --- a/docs/old-to-new.md +++ b/docs/old-to-new.md @@ -55,6 +55,7 @@ pip install -r ./requirements.txt spi_miso = board.D17 spi_mosi = board.D10 #this one is not actually used, so set it or not gpio_heat = board.D23 + gpio_heat_invert = False ``` 5. test the thermocouple board and thermocouple diff --git a/gpioreadall.py b/gpioreadall.py index 2816b45..d935da7 100755 --- a/gpioreadall.py +++ b/gpioreadall.py @@ -67,17 +67,21 @@ def pin_state(g): else: D[p] = v - if(D['fsel'] < 2): # i.e. IN or OUT - name = 'GPIO{}'.format(g) + if('fsel' in D): + if(D['fsel'] < 2): # i.e. IN or OUT + name = 'GPIO{}'.format(g) + else: + name = D['func'] + + mode = MODES[D['fsel']] + if(D['fsel'] == 0 and 'pull' in D): + if(D['pull'] == 'UP'): + mode = 'IN ^' + if(D['pull'] == 'DOWN'): + mode = 'IN v' else: name = D['func'] - - mode = MODES[D['fsel']] - if(D['fsel'] == 0 and 'pull' in D): - if(D['pull'] == 'UP'): - mode = 'IN ^' - if(D['pull'] == 'DOWN'): - mode = 'IN v' + mode = '' return name, mode, D['level'] diff --git a/lib/oven.py b/lib/oven.py index fcb6197..9eed518 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -36,19 +36,22 @@ class Output(object): state relay to turn the kiln elements on and off. inputs config.gpio_heat + config.gpio_heat_invert ''' def __init__(self): self.active = False self.heater = digitalio.DigitalInOut(config.gpio_heat) self.heater.direction = digitalio.Direction.OUTPUT + self.off = config.gpio_heat_invert + self.on = not self.off def heat(self,sleepfor): - self.heater.value = True + self.heater.value = self.on time.sleep(sleepfor) def cool(self,sleepfor): '''no active cooling, so sleep''' - self.heater.value = False + self.heater.value = self.off time.sleep(sleepfor) # wrapper for blinka board diff --git a/test-output.py b/test-output.py index 3c9ea1a..37fc2cd 100755 --- a/test-output.py +++ b/test-output.py @@ -17,7 +17,7 @@ except NotImplementedError: # To test your gpio output to control a relay... # # Edit config.py and set the following in that file to match your -# hardware setup: GPIO_HEAT +# hardware setup: gpio_heat, gpio_heat_invert # # then run this script... # @@ -31,14 +31,17 @@ except NotImplementedError: heater = digitalio.DigitalInOut(config.gpio_heat) heater.direction = digitalio.Direction.OUTPUT +off = config.gpio_heat_invert +on = not off print("\nboard: %s" % (board.board_id)) print("heater configured as config.gpio_heat = %s BCM pin\n" % (config.gpio_heat)) +print("heater output pin configured as invert = %r\n" % (config.gpio_heat_invert)) while True: - heater.value = True + heater.value = on print("%s heater on" % datetime.datetime.now()) time.sleep(5) - heater.value = False + heater.value = off print("%s heater off" % datetime.datetime.now()) time.sleep(5)