Since the argument to the sleep function is in seconds instead of milliseconds, you will want to update this line (and others with units in seconds): sleep(1) #Wait 1 mS to allow logic controler time to respond to sleep(0.001) #Wait 1 mS to allow logic controller time to respond [image] Rich… Answer from onePythonUser on discuss.python.org
🌐
SourceForge
sourceforge.net › home › browse › raspberry-gpio-python › wiki
raspberry-gpio-python / Wiki / Outputs
chan_list = (11,12) GPIO.output(chan_list, GPIO.LOW) # all LOW GPIO.output(chan_list, (GPIO.HIGH,GPIO.LOW)) # first LOW, second HIGH
🌐
RasPi.TV
raspi.tv › 2013 › rpi-gpio-basics-5-setting-up-and-using-outputs-with-rpi-gpio
RPi.GPIO basics 5 – Setting up and using outputs with RPi.GPIO
June 22, 2015 - Input and Output, interfacing, python programming, raspberry pi Add comments · Jul 152013 · Today is output day. I’m going to show you how to switch things on and off using RPi.GPIO to control the output ports of the Raspberry Pi. P1 · Once you can control outputs, you can, with a few additional electronic components, switch virtually anything on and off.
Discussions

datetime - Python rpi GPIO output control based on GPIO input and time of day - Stack Overflow
I'm trying to write a little script to control two raspberry pi's gpio output pins based on two factors: the state of GPIO.input.17 and the time of day. I would like gpio.output.23 and gpio.output.... More on stackoverflow.com
🌐 stackoverflow.com
GPIO Code Problem
Could someone help me, please? My problem is when I call a GPIO function it freezes the program like it is in some endless loop. The following line of code shows how I am calling the GPIO functions. GPIO.output(Run_Pin… More on discuss.python.org
🌐 discuss.python.org
17
0
November 16, 2024
python - Toggling a GPIO pin set as output - Raspberry Pi Stack Exchange
I read here that I could toggle the state of a GPIO pin set to output in Python using the following command: More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
GPIO and Python - GPIO.output() not working - Raspberry Pi Stack Exchange
In a similar vein, GPIO.setup(20, GPIO.OUT, initial=0) does indeed setup the pin for output, but it's automatically on, despite the initial=0... More on raspberrypi.stackexchange.com
🌐 raspberrypi.stackexchange.com
July 14, 2019
🌐
SparkFun Learn
learn.sparkfun.com › tutorials › raspberry-gpio › python-rpigpio-api
Python (RPi.GPIO) API - Raspberry gPIo - SparkFun Learn
To specify in your code which number-system is being used, use the GPIO.setmode() function. For example... ... Both the import and setmode lines of code are required, if you want to use Python. If you've used Arduino, you're probably familiar with the fact that you have to declare a "pin mode" before you can use it as either an input or output.
🌐
ICS
ics.com › blog › control-raspberry-pi-gpio-pins-python
Control Raspberry Pi GPIO Pins from Python | ICS
July 31, 2019 - Here is a very simple standalone example that toggles an output pin on and off for 200 milliseconds, ten times. It also reports the level on input pin 31. If you put the commands in a file and make it executable, you can directly run it as a program. ... for i in range(10): GPIO.output(led, GPIO.HIGH) time.sleep(0.2) GPIO.output(led, GPIO.LOW) time.sleep(0.2) print('Switch status = ', GPIO.input(switch))
🌐
Stack Overflow
stackoverflow.com › questions › 64480895 › python-rpi-gpio-output-control-based-on-gpio-input-and-time-of-day
datetime - Python rpi GPIO output control based on GPIO input and time of day - Stack Overflow
I've managed to work this issue out... my original else statement was invalid, so i've added a third elif with my 'night time' conditions and finished the statement with an else that sets both GPIO.out pins to 1. I've also inverted the 'resting' state of the outputs because i think the relay unit I've got is neg applied ... #!/usr/bin/python import time from time import sleep import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # Setup GPIO pins GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # set GPIO 17 as input GPIO.setup(23, GPIO.OUT) # set GPIO 23 as output GPIO.set
🌐
Python.org
discuss.python.org › python help
GPIO Code Problem - Python Help - Discussions on Python.org
November 16, 2024 - Could someone help me, please? My problem is when I call a GPIO function it freezes the program like it is in some endless loop. The following line of code shows how I am calling the GPIO functions. GPIO.output(Run_Pin,GPIO.HIGH) I tracked the problem to the GPIO function ( both input and output) by commenting out the GPIO functions; the code runs correctly and does not freeze.
🌐
SparkFun Learn
learn.sparkfun.com › tutorials › raspberry-gpio › python-rpigpio-example
Python (RPi.GPIO) Example - Raspberry gPIo - SparkFun Learn
It does a little input and output, and even handles some PWM. This assumes you've set up the circuit as arranged on the Hardware Setup page. language:Python # External module imports import RPi.GPIO as GPIO import time # Pin Definitons: pwmPin = 18 # Broadcom pin 18 (P1 pin 12) ledPin = 23 # Broadcom pin 23 (P1 pin 16) butPin = 17 # Broadcom pin 17 (P1 pin 11) dc = 95 # duty cycle (0-100) for PWM pin # Pin Setup: GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme GPIO.setup(ledPin, GPIO.OUT) # LED pin set as output GPIO.setup(pwmPin, GPIO.OUT) # PWM pin set as output pwm = GPIO.PWM(pwmPin, 50) # Initialize PWM on pwmPin 100Hz frequency GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up # Initial state for LEDs: GPIO.output(ledPin, GPIO.LOW) pwm.start(dc) print("Here we go!
Find elsewhere
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › troubleshooting
GPIO.setup(pin,GPIO.OUT) turn pin on - Raspberry Pi Forums
November 11, 2021 - Maybe more of a Python forum question? @rpiMike Thanks for trying it! And I apologize if I said things incorrect. The code listed should work, but that's my work around, having to run the cleanup on every pin I call in order for them to shutoff. As soon as I enter GPIO.setup(AA,GPIO.OUT) the pin turns on. I thought that line just told the Pi that this will at some point in the future be an output and will not engage the pin until it sees the line GPIO.output(AA,1).
🌐
SourceForge
sourceforge.net › home › browse › raspberry-gpio-python › wiki
raspberry-gpio-python / Wiki / BasicUsage
You can also specify an initial value for your output channel: ... You can set up more than one channel per call (release 0.5.8 onwards). For example: chan_list = [11,12] # add as many channels as you want! # you can tuples instead i.e.: # chan_list = (11,12) GPIO.setup(chan_list, GPIO.OUT)
🌐
Electropeak
electropeak.com › learn › tutorial-raspberry-pi-gpio-programming-using-python-full-guide
Raspberry Pi GPIO Pins Programming Using Python [Full Guide]
March 3, 2024 - In this tutorial, you will explore the input and output pins of the Raspberry Pi and learn how to control them using the powerful Python 3 programming language. We will focus on two widely used libraries, Gpiozero and Rpi.GPIO, to facilitate GPIO (General Purpose Input/Output) pin control and ...
🌐
Instructables
instructables.com › circuits › raspberry pi
Raspberry Pi: Python Scripting the GPIO : 8 Steps (with Pictures) - Instructables
October 17, 2017 - Raspberry Pi: Python Scripting the GPIO: The GPIO: General Purpose Input/Output lets you interface your Raspberry Pi with the outside world, making it a powerful interactive device for just $40-$50.
🌐
Instructables
instructables.com › circuits › raspberry pi
GPIOs + More Python : 16 Steps - Instructables
May 29, 2020 - GPIOs + More Python : This lesson teaches you how to use the General Purpose Input/Outputs (GPIOs) on your Raspberry Pi to control an LED and read a button’s state. The circuit you build in this lesson will be used in the photo booth final project. You will be introduced…
🌐
Cmac-duke
cmac-duke.github.io › physical-computing › tutorials › pi-gpio
Raspberry Pi Zero and GPIO
We can interact with the pin we defined above with ‘GPIO.output’. Here we’re referencing the pin, and setting the output of the pin to high, much like we would with the Particle Photons. This will output 3.3v to pin 23 ... We can start to set up our program much like we would with the Photons, with a “setup” function and a “loop” function. Since there is no set syntax for python and no “special functions”, we could call these functions anything we want, but for now we’ll stick with “setup” and “loop”
🌐
GeeksforGeeks
geeksforgeeks.org › python › introduction-to-python-raspberry-pi-rpigpio-library
Introduction to Python Raspberry Pi (RPiGPIO) Library - GeeksforGeeks
July 23, 2025 - The RPi.GPIO module is a Python library that allows us to easily control the GPIO pins on a Raspberry Pi. It provides a simple interface for configuring the pins as inputs or outputs, reading their state, and controlling them.
Top answer
1 of 2
2

You need to replace ventein with GPIO.output(20, 1) and ventaus with GPIO.output(20, 0).

You seem to think you have declared them as functions - you have not.

2 of 2
6

As joan's answer has already pointed out the misunderstanding here is likely how to define and use a function in Python. Joan's approach will sure solve the immediate problem and make the program work. I will however address the underlying issue that is not so much related to the Pi but general Python programming.

So how to go about defining and using a function, from here:

  • Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
  • Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses.
  • The first statement of a function can be an optional statement - the documentation string of the function or docstring.
  • The code block within every function starts with a colon (:) and is indented.
  • The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.

So instead of

ventein = GPIO.output(20, 1)

this is what you're looking for:

def ventein():
    GPIO.output(20, 1)

Note the def keyword, the function name (ventein), the parentheses (empty in this case as no arguments are required), and the colon. The final return is ommitted in this case as it is optional if you do not want to pass anything back to the caller.

And when calling this new function instead of:

try:
    while True:
        if murotemp > 20:
            ventein

it should read:

try:
    while True:
        if murotemp > 20:
            ventein()
🌐
SparkFun Learn
learn.sparkfun.com › tutorials › raspberry-gpio › all
Raspberry gPIo - SparkFun Learn
It does a little input and output, and even handles some PWM. This assumes you've set up the circuit as arranged on the Hardware Setup page. language:Python # External module imports import RPi.GPIO as GPIO import time # Pin Definitons: pwmPin = 18 # Broadcom pin 18 (P1 pin 12) ledPin = 23 # Broadcom pin 23 (P1 pin 16) butPin = 17 # Broadcom pin 17 (P1 pin 11) dc = 95 # duty cycle (0-100) for PWM pin # Pin Setup: GPIO.setmode(GPIO.BCM) # Broadcom pin-numbering scheme GPIO.setup(ledPin, GPIO.OUT) # LED pin set as output GPIO.setup(pwmPin, GPIO.OUT) # PWM pin set as output pwm = GPIO.PWM(pwmPin, 50) # Initialize PWM on pwmPin 100Hz frequency GPIO.setup(butPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Button pin set as input w/ pull-up # Initial state for LEDs: GPIO.output(ledPin, GPIO.LOW) pwm.start(dc) print("Here we go!
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › community › general discussion
How to configure some GPIO pins as output - Raspberry Pi Forums
Yes. You'd probably still want to do it in your program in case something else was touching the GPIO. You should be able to use the /boot/config.txt gpio directive (NOT the wiringPi gpio command) which may be used to set the GPIO as OUTPUTs at the earliest possible moment in the boot process.