View: 6880|Reply: 4

GPIO with Python

[Copy link]

1

threads

1

posts

9

credits

Novice

Rank: 1

credits
9
Published in 2019-5-3 06:52:36 | Show all floors |Read mode
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

  1. import OPi.GPIO as GPIO
  2. import time
  3. GPIO.setmode(GPIO.BOARD)
  4. GPIO.setwarnings(False)

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

  7. try:
  8. While True:
  9.   print("High")
  10.   GPIO.output(pin, GPIO.HIGH)
  11.   time.sleep(1)
  12.   print("Low")
  13.   GPIO.output(pin, GPIO.LOW)
  14.   time.sleep(1)

  15. Except KeyboardInterrupt:
  16. print("Exit")
  17. exit()
Copy code
the program working and i press CTRL + C for exit and i watch in /sys/class/gpio
  1. ls /sys/class/gpio
  2. export gpio199 gpiochip0 gpiochip352 unexport
Copy code
the 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.

  1. sudo nano /sys/class/gpio/gpio199/active_low
Copy code
always contains 0 regardless of the initial setting (GPIO.LOW or GPIO.HIGH).

if i make

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




0

threads

3

posts

18

credits

Novice

Rank: 1

credits
18
Published in 2022-8-23 01:48:38 | Show all floors
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

0

threads

1

posts

12

credits

Novice

Rank: 1

credits
12
Published in 2022-9-15 18:20:55 | Show all floors
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.
At authors crew, we offer ghostwriting, editing, p

0

threads

2

posts

10

credits

Novice

Rank: 1

credits
10
Published in 2023-5-22 16:59:12 | Show all floors
Game with stunning graphics and impressive gameplay. I like it very much. I look forward to playing more games similar to Vampire Survivors

0

threads

28

posts

74

credits

Registered member

Rank: 2

credits
74
Published in 2024-1-3 11:58:09 | Show all floors
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.
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list