Você está na página 1de 13

2012

Controlling GPIO using GUI

Author: Praveen Kumar

Tkinter: The Tkinter module ("Tk interface") is the standard Python interface to the Tk GUI toolkit from Scriptics (formerly developed by Sun Labs). The former automatically imports the latter, so to use Tkinter, all you need to do is to import one module: import Tkinter Or, more often: from Tkinter import * Let us see how to use this Tkinter for accessing GPIO pins in Wandboard. Step 1: Type the following command to activate Tkinter: sudo apt-get install python python-tk idle python-pmw python-imaging

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Step 2: You can download the library file from the below link https://github.com/TenetTechnetronics/wandboardgpiolibrary Copy library file to the desktop or any other directory. Step 3: Coding for accessing gpio with GUI using Tkinter Open a terminal and type the following command for opening the editor with file name. gediteditor window .pypython extension

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Then type the following coding to access the gpio with gui.

#!/usr/bin/python from Tkinter import * import GPIO led = 4 GPIO.export(led) GPIO.setup(led,1) def ledon(): print "turn on" GPIO.write(led,1) def ledoff(): print "turn off" GPIO.write(led,0) root =Tk()

# importing GPIO library # assigning the gpio_4 to variable led # exporting the gpio_4 # make the gpio_4 as output pin by the value 1 # function for turning on an led

#function for turning off an led

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

button1 = Button(root,text="ON",command=ledon) to the button "ON"

#assigning the function ledon

button2 = Button(root,text="OFF",command=ledoff) #assigning the function ledoff to the button "OFF" button1.pack(side = LEFT ) #alignment for the button "ON" button2.pack(side = RIGHT) #alignment for the button "OFF" root.mainloop() PINOUT:

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

JP4

Sl.No 1 2 3 4 5 6 7 8

Pin Number GPIO75 GPIO91 GPIO191 GPIO24 GPIO200 GPIO90 GPIO72 GPIO101

GPIO GPIO_0 GPIO_1 GPIO_2 GPIO_3 GPIO_4 GPIO_5 GPIO_6 GPIO_7

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Step 5: For example i am connecting an led to the gpio_4.

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Step 6: Run your python file using the command below. sudo python gui.py guifile name .py python extension

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Step 7: Output window having the ON and OFF GUI

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Step 8: When you have click the button ON then the led will be turn on.

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

When you have the click the button OFF then the led will be turn off.

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

For more details kindly go through the following link: http://tenettech.com/category/265/wandboard http://blogspot.tenettech.com/ http://www.youtube.com/watch?v=5UmTDIUIRBs&feature=share&list=UUyRZXnQe h8xgmgDYxQfN8eA https://github.com/TenetTechnetronics/wandboardgpiolibrary
# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

# 9/3, 2nd floor, Sree Laksmi Complex, opp, to Vivekananda Park, Girinagar, Bangalore - 560085, Email: info@tenettech.com, Phone: 080 - 26722726

Você também pode gostar