Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 953|Reply: 0

GPIO with Python

[Copy link]

1

Threads

1

Posts

9

Credits

Novice

Rank: 1

Credits
9
Post time 2019-5-3 06:52:36 | Show all posts |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 the 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 the 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 the 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 the Code
it's work outside the program.
i don't understand.
thanks for help.
I'm sorry for my english




You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-12-12 06:42 GMT+8 , Processed in 0.025761 second(s), 23 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list