Raspberry Pi & Python remote control experiment

After seeing other universities are using online platform to perform basic physical experiments, such as measuring gravity, Prof Le want to build a remote experimet platform himself.

We are asked to figure out how to remote control first.

Raspberry is in fashion then, combined with python, which is a powerful tool in web coding, I tested and succeeded.

Python code:

import web
import os
import RPi.GPIO as GPIO
GPIO.setup(18, GPIO.OUT)
render = web.template.render('static/')

TAKE_PHOTO = "raspistill -o static/out.jpeg -w 500 -h 500 -n -t 1 -rot 180"

urls = (
        '/takephoto', 'TakePhoto', 
    	'/', 'index',

class index:
    def GET(self):
	return render.index()

def doMove(s):
    IO = '4310'
    for i in xrange(4):
        call(['gpio', 'write', IO[i], s[i]])

class TakePhoto:
    def GET(self):

class Light:
    def GET(self):
    	GPIO.output(18, True)

class Dark:
    def GET(self):
if __name__ == '__main__':
    app = web.application(urls, globals())

Main part of html code, used as interface to remote users:

    <img width="500" height="500" src="/static/out.jpeg" id="myimg">
    <br />

    <button onclick="$.post('/pythonweb/move?direction=stop')">stop</button>
    <br /> <br />
    <input type="text" id="content">
    <button onclick="$.post('/pythonweb/speak', {content: $('#content')[0].value})">Speak</button>
            $('#myimg').attr('src', '/static/out.jpeg?' + new Date().getTime());
        }, 2000);


Last Article Next article

Comment 评论

Share 分享

New Users 最新加入

  • hokurikustr

  • refrain

New comments 最新评论

test123: aasdas Details Apr 13 16:39
admin: Thanks! Details Apr 09 11:46
admin: Google map api Details Apr 09 11:46
lqj12: cooooooooool Details Apr 08 21:34
Yunhan Huang: 这个功能是如何实现的? Details Apr 08 13:23