radwimps
Posts: 4
Joined: Sun Jun 23, 2019 6:37 pm

GPIO pins are not turning on in while loop

Sun Jun 23, 2019 6:41 pm

Hello. I'm trying to write a temperature maintaining script using a thermocouple and some peltier modules. When I run my while loop, the prints in the defined functions print accordingly but the pins do not seem to be supplying voltage. Any help would be appreciated.

Code: Select all

import RPi.GPIO as GPIO
import time
import board
import busio
import digitalio
import adafruit_max31855

GPIO.setmode(GPIO.BCM)
GPIO.setup(0, GPIO.OUT)
GPIO.setup(2, GPIO.OUT)
GPIO.setup(3, GPIO.OUT)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)

def heating():
    GPIO.output(0, False)
    GPIO.output(2, True)
    GPIO.output(3, False)
    GPIO.output(4, True)
    GPIO.output(22, False)
    GPIO.output(23, True)
    GPIO.output(24, False)
    GPIO.output(25, True)
    GPIO.output(27, True)
    print("Now Heating...")

def cooling():
    GPIO.output(0, True)
    GPIO.output(2, False)
    GPIO.output(3, True)
    GPIO.output(4, False)
    GPIO.output(22, True)
    GPIO.output(23, False)
    GPIO.output(24, True)
    GPIO.output(25, False)
    GPIO.output(27, False)
    print("Now Cooling...")

# User Input
desired_temp = int(input("Enter your desired temperature: "))

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = digitalio.DigitalInOut(board.D5)

max31855=adafruit_max31855.MAX31855(spi, cs)

try:
    while True:
        tempC = max31855.temperature
        tempF = tempC * 9 / 5 + 32
        print('Temperature: {} C {} F '.format(tempC, tempF))
        time.sleep(0.05)
        if tempF <= desired_temp:
            heating()
        else:
            cooling()
finally:
    GPIO.cleanup()

User avatar
B.Goode
Posts: 7868
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 8:08 pm

Welcome to the Raspberry Pi forums.

. When I run my while loop, the prints in the defined functions print accordingly but the pins do not seem to be supplying voltage. Any help would be appreciated.

Some indication, preferably a clearly focussed image, of how your project has the external components wired to your RPi would be of value.

How/where are you measuring for the change of voltage you hope to detect?

ghp
Posts: 1352
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 8:21 pm

Do you get the printout : "Now Heating..." or "Now Cooling..." ?
What is the reason for these many GPIO to control the peltier ?

pcmanbob
Posts: 6236
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 9:09 pm

Hi.

How are you driving the peltire moduals , as trying to drive them directly from the gpio pins won't work as the gpio pins can only supply or sink 16mA per pin max.

May be you should give us more detail about the hardware setup of your project.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

radwimps
Posts: 4
Joined: Sun Jun 23, 2019 6:37 pm

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 10:49 pm

B.Goode wrote:
Sun Jun 23, 2019 8:08 pm
Welcome to the Raspberry Pi forums.

Thanks for the welcome and the reply! Please let me know if you need more information.
. When I run my while loop, the prints in the defined functions print accordingly but the pins do not seem to be supplying voltage. Any help would be appreciated.

Some indication, preferably a clearly focussed image, of how your project has the external components wired to your RPi would be of value.

Sure. https://www.youtube.com/watch?v=eUMi2y7 ... e=youtu.be and https://www.youtube.com/watch?v=269cMOJ ... e=youtu.be
The script I had posted earlier was intended to combine the python script for the thermocouple and the script for the h-bridge, fans, peltier modules, and relay. One note was that at the time of recording the video, pin numbering was done via BOARD whereas the script I posted is in BCM. GPIO (BCM) 0, 2, 3, 4, 22, 23, 24, and 25 were used in conjunction with an h-bridge and an external power supply to change the heating with the cooling side of the peltier modules. This was done so that we could use the same peltier chips for heating and cooling. GPIO 27 was used to control the 12V relay. When the relay is turned on, 12V fans will power on. That was intended to cool the hot side of the peltier modules to increase cooling efficiency. The thermocouple is a k-type, glass braid off adafruit and the amplifier is the MAX31855 and it is connected via SCLK, MISO, and GPIO 21.

How/where are you measuring for the change of voltage you hope to detect?
To measure the change in voltage, we used a multimeter and measured to see if we were receiving any voltage at all at where the peltier modules would connect on the h-bridge (OUT1, OUT2/OUT3, OUT4). From what we've measured so far, voltage has been zero with the script running.

radwimps
Posts: 4
Joined: Sun Jun 23, 2019 6:37 pm

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 10:56 pm

pcmanbob wrote:
Sun Jun 23, 2019 9:09 pm
Hi.

How are you driving the peltire moduals , as trying to drive them directly from the gpio pins won't work as the gpio pins can only supply or sink 16mA per pin max.

May be you should give us more detail about the hardware setup of your project.
Apologies for the vagueness. The connection order goes RPi > h-bridge > peltier module. I have an external power supply that is supplying 6V at 5A for the cooling/heating. I also have RPi > 5V relay > 12V fans in order to cool the hot side of the peltier modules when cooling. Here's a video of the components of what I have so far:
https://www.youtube.com/watch?v=eUMi2y7 ... e=youtu.be This script controls the h-bridges, peltier modules, fans, and relay.
https://www.youtube.com/watch?v=269cMOJ ... e=youtu.be This script is used in conjunction with a thermocouple and an amplifier.

Essentially, what I want is to combine the two scripts to make a script that asks for a user input then heats and cools with respect to whether or not the temperature readout of the thermocouple is above or below the user input.

Please let me know if you would need more info. Thanks for your reply!

radwimps
Posts: 4
Joined: Sun Jun 23, 2019 6:37 pm

Re: GPIO pins are not turning on in while loop

Sun Jun 23, 2019 10:58 pm

ghp wrote:
Sun Jun 23, 2019 8:21 pm
Do you get the printout : "Now Heating..." or "Now Cooling..." ?
What is the reason for these many GPIO to control the peltier ?
Hello, thanks for your reply!

I do get the printout. They work perfectly. I'm just not getting the GPIO pins to function.

As for why i'm using that many GPIO pins, I'm using 8 peltier modules. It's a bit overkill but we thought it'd be cool...

ghp
Posts: 1352
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: GPIO pins are not turning on in while loop

Mon Jun 24, 2019 4:30 am

Nice video, but not giving all the details needed.
Going step by step: the peltier are driven by GPIO --> H-Bridge --> Peltier.
(1) Disconnect H-bridge, at least one. Check GPIO which have been used for the bridge. Write a small python script which just toggles these pins in a loop: low-wait3sec-high-wait3sec. These should show voltages close to GND or close to 3.3V.

(2) H-Bridge next. Which chip is used, think there have been breakouts visible in the video. Where can datasheet be found for chip and breakout ?
And how is h-bridge connected to GPIO, Ground, Power, Peltier. Is there an enable input ? Provide a sketch on a sheet of paper.

pcmanbob
Posts: 6236
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: GPIO pins are not turning on in while loop

Mon Jun 24, 2019 10:25 am

I am confused your videos clearly shows that the gpio outputs are working as you demonstrate that the voltage on the H-bridge changes and that you get a cooling affect on the Peltier..

Unless of course this is not your set-up but one you found on youtube that you are trying to copy.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Python”