先确保已在树莓派上正确安装Python及Python GPIO模块,接下来,安装webiopi:
wget http://webiopi.googlecode.com/files/WebIOPi-0.6.0.tar.gz tar xvzf WebIOPi-0.6.0.tar.gz cd WebIOPi-0.6.0 sudo ./setup.sh
安装之后启动webiopi程序,命令如下:
sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port] Options: -h, --help Display this help -c, --config file Load config from file -l, --log file Log to file -s, --script file Load script from file -d, --debug Enable DEBUG Arguments: port Port to bind the HTTP Server
可以将此服务放在后台运行,命令如下:
sudo /etc/init.d/webiopi start sudo /etc/init.d/webiopi stop
开机启动:
sudo update-rc.d webiopi defaults
接下来,你可以通过输入http://localhost:端口号来访问webiopi服务并控制GPIO接口状态:
1、点击“IN/OUT”切换GPIO工作模式:输入/输出;
2、在输出状态下,点击引脚物理编号切换输出电平,高/低电平;
3、在输入状态下,引脚物理编号显示输出状态7;
4、由于树莓派默认只有8各GPIO引脚,请对照GPIO表设置;