antares post at 2019-5-3 06:52:36

GPIO with Python

Edited by antares at 2019-5-3 07:17

Hello !

I'm sorry for my bad English, i'm French and i speak very bad in English.

I have an Orange Pi Zero and i would like to turn it into a connected object (IOT). I am therfore looking to drive a relays, read DHT22 probes, as well as communicate on the I2C bus and communicate with an MQTT broker.

To date, i manage to fly the map relays, communicate in mqtt with paho.mqtt, i realized a program that retrieves messages and runs different threads for my relays (tempo, etc...)

i'm having a problem with the GPIO port, i'm using OPi.GPIO for Python
https://opi-gpio.readthedocs.io/en/latest/api-documentation.html
import OPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

pin = 10
GPIO.setup (pin, GPIO.OUT, initial=GPIO.HIGH)

try:
While True:
print("High")
GPIO.output(pin, GPIO.HIGH)
time.sleep(1)
print("Low")
GPIO.output(pin, GPIO.LOW)
time.sleep(1)

Except KeyboardInterrupt:
print("Exit")
exit()the program working and i press CTRL + C for exit and i watch in /sys/class/gpio
ls /sys/class/gpio
export gpio199 gpiochip0 gpiochip352 unexportthe pin number 10 is PG07 in setmode BOARd (7-1)*32+7= 199 so gpio199 is my export.

If i comment the line #GPIO.setup (pin, GPIO.OUT, initial=GPIO.HIGH) in my program and i run it
i have a run time error Channel 10 is not configured.

Whereas the export has alreday been done, if i export my gpio into the /etc/rc.local for exportation on starting the pi.
My result is the same

Also, the parameter initial=GPIO.HIGH or GPIO.LOW not working. My gpio is always with a lower level = 3.3V and higher level = 0V
My relay card is higer level trigger so i'm contrain to used a GPIO.LOW for working relay and used GPIO.HIGH for shutdown.

sudo nano /sys/class/gpio/gpio199/active_lowalways contains 0 regardless of the initial setting (GPIO.LOW or GPIO.HIGH).

if i make

echo 1 > /sys/class/gpio/gpio199/active_low
echo 0 > /sys/class/gpio/gpio199/value (relay off)
echo 1 > /sys/class/gpio/gpio199/value (relay on)it's work outside the program.
i don't understand.
thanks for help.
I'm sorry for my english




charlesborough post at 2022-8-23 01:48:38

This is a GPIO interface board with a Python library. It has a Raspberry Pi B+ pinout, a 40-pin header with 0.1” spacing, and a 40-pin male header. The board also has a power and ground bus, 2x2 M2.5 screws, and 4x4 M2.5 screws. pay someone to take my online class

authorscrewuk post at 2022-9-15 18:20:55

This book is for anyone who wants to get started with the Raspberry Pi GPIO ghostwriting service and Python. With the help of this book, you will learn how to use the GPIO with Python in your projects.

mayo72218 post at 2023-5-22 16:59:12

Game with stunning graphics and impressive gameplay. I like it very much. I look forward to playing more games similar to Vampire Survivors

emmaorabelle post at 2024-1-3 11:58:09

This is a Python library-equipped GPIO interface board. It features a 40-pin male header, a 40-pin header with 0.1" spacing, and a Raspberry build now gg Pi B+ pinout. In addition, the board features four by four M2.5 screws, two by two M2.5 screws, and a power and ground bus.
page: [1]
View full version: GPIO with Python