0

I didn't write this code (just made some modifications) but it was using a depreciated library so I'm trying to update to the official circuit python libraries and update everything for python3.

This is for a kiln controller that I've been using successfully for a year. It was using some deprecated libraries however, and recent updates broke things. It seems redundant import both RPi.GPIO and digitalio. Since the max31856 requires digitalio, I thought I'd convert the code to use that instead of RPi.GPIO. However, the code just doesn't seem as elegant. I'm wondering if I'm missing something or if I should just keep using Rpi.GPIO?

The HEAT = (23,24) is the the output pins to trigger the relays for the elements. This should be expandable because some kilns use more than 2 elements.

This is the original code

GPIO.setmode(GPIO.BCM)
HEAT = (23, 24)
for element in HEAT:
    GPIO.setup(element, GPIO.OUT)
    GPIO.output(element, GPIO.LOW)

And to turn the elements on and off

for element in HEAT:
        GPIO.output(element, False)

and

for element in HEAT:
        GPIO.output(element, True)

The code I'm comming up with is something like this

HEAT = (board.D23,board.D24)
for element in HEAT:
        element = digitalio.DigitalInOut(element)
        element.direction = digitalio.Direction.OUTPUT
        element.value = False

I haven't actually tested this to make sure it's triggering both elements but it doesn't generate any errors when I run it.

Is there a better way to do this? I've tried running digitalio.DigitalInOut(element) with various combinations to avoid the board.D23 in the list but circuit python didn't like those.

Here is the entire code base. https://github.com/fayena/PILN

Suggestions?

5
  • RPi.GPIO is better supported and as it's part of RaspiOS should always work on any current or future version of the RPi.
    – Dougie
    Commented Aug 9, 2020 at 21:41
  • So, I would be better off continuing to use the RPi.GPIO interface for the kiln element pins for the sake of future compatibility/more elegant code even though I'm importing two input/output interfaces? Sorry if these are basic questions, I'm self taught and couldn't find these particular questions addressed anywhere in my searches.
    – alforddm
    Commented Aug 9, 2020 at 23:19
  • You would be better supported that way.
    – Dougie
    Commented Aug 9, 2020 at 23:25
  • Thank you, that is exactly what I needed to know.
    – alforddm
    Commented Aug 9, 2020 at 23:33
  • Please create an answer about the solution to your question and accept it after two days with a click on the tick on its left side. There is nothing wrong with self-answering. Only accepting an answer will finish the question and it will not pop up again year for year.
    – Ingo
    Commented Aug 15, 2020 at 9:41

1 Answer 1

1

The OP noted in a comment that she/he would be better supported with this way:

I would be better off continuing to use the RPi.GPIO interface for the kiln element pins for the sake of future compatibility/more elegant code even though I'm importing two input/output interfaces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.