1 Install request (Requests is a Python HTTP client library): $ sudo apt-get install python-requests
2 Installing Python-pip (PIP is a tool that can replace Easy_install's installation and pipe Python packages): $sudo apt-get Install python-imaging PYTHON-IMAGING-TK Python-pip Python-dev git Note: Sometimes running this command will fail to install, then you need to enter: $sudo apt-get Update and then enter this command.
3 Install flask (Flask is a lightweight Web application framework, written in Python): $sudo pip Install flask
4to theGitHubDownload "Python-pcduino "This library file is placed inUbuntuunder, openSample, copy theblink_led"renamed to"Hello-gpio"and then in the inside will“blink_led"renamed to"hello-gpio.py ", "hello-gpio.pythe code is as follows:
- From flask import flask, render_template
- Import datetime
- Import Gpio
- App = Flask (__name__)
- Channel = {0: ' gpio0 ', 1: ' Gpio1 ', 2: ' Gpio2 ', 3: ' Gpio3 ', 4: ' Gpio4 ',
- 5: ' Gpio5 ', 6: ' Gpio6 ', 7: ' Gpio7 ', 8: ' Gpio8 ', 9: ' Gpio9 ',
- Ten: ' Gpio10 ', one: ' Gpio11 ', and: ' Gpio12 ', ' gpio13 '
- }
- @app. Route ("/")
- def hello ():
- now = Datetime.datetime.now ()
- TimeString = Now.strftime ("%y/%m/%d%h:%m:%s")
- TemplateData = {
- ' title ': ' Hello! ',
- ' Time ': timestring
- }
- Return render_template (' main.html ', **templatedata)
- @app. Route ("/readpin/<pin>")
- def readpin (PIN):
- Gpio.pinmode (Channel[int (PIN)],gpio. INPUT)
- Value = ""
- if (Gpio.digitalread (Channel[int (pin)) = = Gpio. High):
- Value = "Read GPIO" + Pin + "is high!"
- else:
- Value = "Read GPIO" + Pin + "is low!"
- TemplateData = {
- ' title ': ' Status of GPIO ' + PIN,
- ' Value ': value
- }
- Return render_template (' pin.html ', **templatedata)
- if __name__ = = "__main__":
- App.run (host= ' 0.0.0.0 ', port=80,debug=true)
Copy Code
5 Create a new folder named "templates" in the folder "hello-gpio", and the folder contains 2 files: " main.html, pin.html " <ignore_js_op> <ignore_js_op>
main.html content is as follows:
- <! DOCTYPE html>
-
- <title>{{Title}} </title>
-
- <body>
- <center>
-
-
- </center>
- </body>
-
Copy Codepin.html content is as follows:
- <! DOCTYPE html>
- <title>{{Title}} </title>
- <body>
- <center>
- nbsp <a href= "http://www.pcduino.org" >pcDuino.org</a>
- </center>
- </body>
Copy Code6 input : $sudo python./hello-gpio.py Run code: <ignore_js_op>
7 View pcduino IP address:$ifconfig : <ignore_js_op>
8 on another PC that shared the same network with Pcduino, open the browser input 192.168.35 you will see the following information:
"Go" Pcduino read gpio data with Python