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

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
12
Return to list New
Author: jacer

PYTHON lib for OrangePi -PC GIPO is out

[Copy link]

3

Threads

46

Posts

683

Credits

Senior member

Rank: 4

Credits
683
Post time 2016-3-20 22:54:24 | Show all posts
Edited by mswiniuch at 2016-3-21 23:48
marian.dubravka replied at 2016-3-16 16:43
hi, what I did wrong? I have orange pi pc

I can't compile it on OPI PC - debian Jessie:
  1. root@OrangePI:~/GPIO-Python# python setup.py install
  2. running install
  3. running build
  4. running build_py
  5. creating build
  6. creating build/lib.linux-armv7l-2.7
  7. creating build/lib.linux-armv7l-2.7/pyA20
  8. copying pyA20/__init__.py -> build/lib.linux-armv7l-2.7/pyA20
  9. creating build/lib.linux-armv7l-2.7/pyA20/gpio
  10. copying pyA20/gpio/__init__.py -> build/lib.linux-armv7l-2.7/pyA20/gpio
  11. running build_ext
  12. Detected processor:  sun8i (Probably Allwinner H3)
  13. building 'pyA20.gpio.gpio' extension
  14. creating build/temp.linux-armv7l-2.7
  15. creating build/temp.linux-armv7l-2.7/pyA20
  16. creating build/temp.linux-armv7l-2.7/pyA20/gpio
  17. arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio_lib.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio_lib.o
  18. arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio.o
  19. pyA20/gpio/gpio.c:25:20: fatal error: Python.h: No such file or directory
  20. #include "Python.h"
  21.                     ^
  22. compilation terminated.
  23. error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
Copy the Code
I know.. I have to install python-dev
sudo apt-get install python-dev


3

Threads

46

Posts

683

Credits

Senior member

Rank: 4

Credits
683
Post time 2016-3-22 02:03:36 | Show all posts
Edited by mswiniuch at 2016-3-22 23:07

Sorry for my english but i hope you can understand me
I have my first program for GPIO writen in Python. It controls three buttons and one led (button activity). It is used to switch playlist on MPD server by MPC - I use it for internet radio.

  1. #!/usr/bin/env python

  2. import os
  3. import sys
  4. import subprocess

  5. if not os.getegid() == 0:
  6.     sys.exit('Script must be run as root')

  7. from time import sleep
  8. from subprocess import *
  9. from pyA20.gpio import gpio
  10. from pyA20.gpio import connector
  11. from pyA20.gpio import port

  12. led = connector.gpio1p7    # PIN 7
  13. button_reset = connector.gpio1p36  #PIN 38
  14. button_prev = connector.gpio1p38  #PIN 38
  15. button_next = connector.gpio1p40  #PIN 40

  16. """Init gpio module"""
  17. gpio.init()

  18. """Set directions"""
  19. gpio.setcfg(led, gpio.OUTPUT)
  20. gpio.setcfg(button_reset, gpio.INPUT)
  21. gpio.setcfg(button_prev, gpio.INPUT)
  22. gpio.setcfg(button_next, gpio.INPUT)

  23. """Enable pullup resistor"""
  24. gpio.pullup(button_reset, gpio.PULLUP)
  25. gpio.pullup(button_prev, gpio.PULLUP)
  26. gpio.pullup(button_next, gpio.PULLUP)

  27. def delay_milliseconds(milliseconds):  
  28.     seconds = milliseconds / float(1000)
  29.     sleep(seconds)  

  30. def run_cmd(cmd):  
  31.    p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)  
  32.    output = p.communicate()[0]  
  33.    return output  

  34. reset_pressed = 1
  35. prev_pressed = 1
  36. next_pressed = 1
  37. while True:
  38.    value_out = 0
  39.    reset_pressed = gpio.input(button_reset)
  40.    prev_pressed = gpio.input(button_prev)
  41.    next_pressed = gpio.input(button_next)

  42.    if (reset_pressed == 0):
  43.       value_out = 1
  44.       run_cmd("/Public/rs")

  45.    if (prev_pressed == 0):
  46.       value_out = 1
  47.       run_cmd("mpc prev")

  48.    if (next_pressed == 0):
  49.       value_out = 1
  50.       run_cmd("mpc next")

  51.    gpio.output(led,  value_out)
  52.    delay_milliseconds(100)
Copy the Code

1

Threads

14

Posts

143

Credits

Registered member

Rank: 2

Credits
143
Post time 2016-4-25 06:52:19 | Show all posts
I haven't found any example running a 16x2 LCD display with this library, so I ported this one: http://www.raspberrypi-spy.co.uk ... ntrol-using-python/

  1. #!/usr/bin/python


  2. #import
  3. import time

  4. from pyA20.gpio import gpio
  5. from pyA20.gpio import port

  6. # Define gpio to LCD mapping
  7. LCD_RS = port.PA6
  8. LCD_E  = port.PD14
  9. LCD_D4 = port.PC4
  10. LCD_D5 = port.PC7

  11. LCD_D6 = port.PA21
  12. LCD_D7 = port.PA20

  13. # Define some device constants
  14. LCD_WIDTH = 16    # Maximum characters per line
  15. LCD_CHR = True
  16. LCD_CMD = False

  17. LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
  18. LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line

  19. # Timing constants
  20. E_PULSE = 0.0005
  21. E_DELAY = 0.0005

  22. def main():
  23.   # Main program block
  24.   gpio.init()
  25.   gpio.setcfg(LCD_RS, gpio.OUTPUT)
  26.   gpio.setcfg(LCD_E, gpio.OUTPUT)
  27.   gpio.setcfg(LCD_D4, gpio.OUTPUT)
  28.   gpio.setcfg(LCD_D5, gpio.OUTPUT)
  29.   gpio.setcfg(LCD_D6, gpio.OUTPUT)
  30.   gpio.setcfg(LCD_D7, gpio.OUTPUT)


  31.   # Initialise display
  32.   lcd_init()

  33.   while True:

  34.     # Send some test
  35.     lcd_string("Orange Pi",LCD_LINE_1)
  36.     lcd_string("16x2 LCD Test",LCD_LINE_2)

  37.     time.sleep(3) # 3 second delay

  38.     # Send some text
  39.     lcd_string("1234567890123456",LCD_LINE_1)
  40.     lcd_string("abcdefghijklmnop",LCD_LINE_2)

  41.     time.sleep(3) # 3 second delay

  42.     # Send some text
  43.     lcd_string("RaspberryPi-spy",LCD_LINE_1)
  44.     lcd_string(".co.uk",LCD_LINE_2)

  45.     time.sleep(3)

  46.     # Send some text
  47.     lcd_string("Follow me on",LCD_LINE_1)
  48.     lcd_string("Twitter @RPiSpy",LCD_LINE_2)

  49.     time.sleep(3)

  50. def lcd_init():
  51.   # Initialise display
  52.   lcd_byte(0x33,LCD_CMD) # 110011 Initialise
  53.   lcd_byte(0x32,LCD_CMD) # 110010 Initialise
  54.   lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
  55.   lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
  56.   lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
  57.   lcd_byte(0x01,LCD_CMD) # 000001 Clear display
  58.   time.sleep(E_DELAY)

  59. def lcd_byte(bits, mode):
  60.   # Send byte to data pins
  61.   # bits = data
  62.   # mode = True  for character
  63.   #        False for command

  64.   gpio.output(LCD_RS, mode) # RS

  65.   # High bits
  66.   gpio.output(LCD_D4, False)
  67.   gpio.output(LCD_D5, False)
  68.   gpio.output(LCD_D6, False)
  69.   gpio.output(LCD_D7, False)
  70.   if bits&0x10==0x10:
  71.     gpio.output(LCD_D4, True)
  72.   if bits&0x20==0x20:
  73.     gpio.output(LCD_D5, True)
  74.   if bits&0x40==0x40:
  75.     gpio.output(LCD_D6, True)
  76.   if bits&0x80==0x80:
  77.     gpio.output(LCD_D7, True)

  78.   # Toggle 'Enable' pin
  79.   lcd_toggle_enable()

  80.   # Low bits
  81.   gpio.output(LCD_D4, False)
  82.   gpio.output(LCD_D5, False)
  83.   gpio.output(LCD_D6, False)
  84.   gpio.output(LCD_D7, False)
  85.   if bits&0x01==0x01:
  86.     gpio.output(LCD_D4, True)
  87.   if bits&0x02==0x02:
  88.     gpio.output(LCD_D5, True)
  89.   if bits&0x04==0x04:
  90.     gpio.output(LCD_D6, True)
  91.   if bits&0x08==0x08:
  92.     gpio.output(LCD_D7, True)

  93.   # Toggle 'Enable' pin
  94.   lcd_toggle_enable()

  95. def lcd_toggle_enable():
  96.   # Toggle enable
  97.   time.sleep(E_DELAY)
  98.   gpio.output(LCD_E, True)
  99.   time.sleep(E_PULSE)
  100.   gpio.output(LCD_E, False)
  101.   time.sleep(E_DELAY)

  102. def lcd_string(message,line):
  103.   # Send string to display

  104.   message = message.ljust(LCD_WIDTH," ")

  105.   lcd_byte(line, LCD_CMD)

  106.   for i in range(LCD_WIDTH):
  107.     lcd_byte(ord(message[i]),LCD_CHR)

  108. if __name__ == '__main__':

  109.   try:
  110.     main()
  111.   except KeyboardInterrupt:
  112.     pass
  113.   finally:
  114.     lcd_byte(0x01, LCD_CMD)
  115.     lcd_string("Goodbye!",LCD_LINE_1)
Copy the Code

1

Threads

2

Posts

9

Credits

Novice

Rank: 1

Credits
9
Post time 2016-8-3 20:13:39 | Show all posts
Hello, i can not find any Python3 lib for GPIO control in Orange Pi. Does it exit's?

1

Threads

9

Posts

105

Credits

Registered member

Rank: 2

Credits
105
Post time 2016-9-5 13:22:00 | Show all posts
I try to convert raspberry GPIO function
Found in RPi code like this
    GPIO.add_event_detect(button, GPIO.FALLING, callback=detect_button, bouncetime=100)
Anybody can help me how to convert this to gpio python for H3 ?
12
Return to list New
You have to log in before you can reply Login | Register

Points Rules

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

2020-7-9 06:59 GMT+8 , Processed in 0.027247 second(s), 19 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list