美文网首页
基于gobot框架在BBB Debian运行的GoLang程序

基于gobot框架在BBB Debian运行的GoLang程序

作者: 网路元素 | 来源:发表于2018-04-07 08:10 被阅读40次

为了让GoLang与BBB搭配使用,我们借助了gobot机器上框架(查阅“参考资料”里的链接),在BBB Debian系统上运行go程序来控制硬件,下面是我们的整个入门配置和测试记录(在PC Ubuntu系统下进行):

1.获取gobot源码  

go get -d -u github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/beaglebone  

这里需要注意和碰到需处理的问题:  

a.需翻墙,同步代码过程会自动同步依赖库源码,有些需要VPN翻墙才能使用;  

b.同步源码过程中会碰到exec: "hg": executable file not found in $PATH 提示,此里需执行sudo apt-get install mercurial命令。  

同步代码后,会在$GOPATH目录下的src和pkg两个目录下存在相关的源码文件。  

2.交叉编译BBB的GOBOT  

a.配置ARM交叉编译的GO环境  

cd $GOROOT  

GOOS=linux GOARCH=arm ./make.bash --no-clean  

b.创建BBB上的测试程序及在BBB上验证  

创建beaglebone_blink.go文件,文件内容如下:  

package main  

import (  

"time"  

"github.com/hybridgroup/gobot"  

"github.com/hybridgroup/gobot/platforms/beaglebone"  

"github.com/hybridgroup/gobot/platforms/gpio"  

)  

func main() {  

gbot := gobot.NewGobot()  

beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")  

led := gpio.NewLedDriver(beagleboneAdaptor, "led", "usr1")  

work := func() {  

gobot.Every(1*time.Second, func() {  

led.Toggle()  

})  

}  

robot := gobot.NewRobot("blinkBot",  

[]gobot.Connection{beagleboneAdaptor},  

[]gobot.Device{led},  

work,  

)  

gbot.AddRobot(robot)  

gbot.Start()  

}  

编译上面的测试代码:  

GOARM=7 GOARCH=arm GOOS=linux go build beaglebone_blink.go 

此时会在当前目录下生成beaglebone_blink文件,使用file命令可查看到该文件属性:  

 xinu@slam:~/golang/examples$ file beaglebone_blink 

beaglebone_blink: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped  

将生成的可执行文件复制到BBB板卡存储器里,再执行./beaglebone_blink,有如下提示:  

 debian@arm:~$ sudo ./beaglebone_blink_usr_led 

We trust you have received the usual lecture from the local System  

Administrator. It usually boils down to these three things:  

#1) Respect the privacy of others.  

#2) Think before you type.  

#3) With great power comes great responsibility.  

[sudo] password for debian: 

此时输入用户名debian对应的密码temppwd后会有如下输出:  

sudo: unable to mkdir /var/lib/sudo/lectured: Read-only file system  

sudo: unable to mkdir /var/lib/sudo/ts: Read-only file system  

2014/07/03 18:47:46 Initializing[   91.044375] bone-capemgr bone_capemgr.9: part_number 'cape-bone-iio', version 'N/A' 

Robot blinkBot ...  

2014/07/03 18:47:46 Initial[   91.056612] bone-capemgr bone_capemgr.9: slot #7: generic override  

izing connection[   91.063936] bone-capemgr bone_capemgr.9: bone: Using override eeprom data at slot 7  

s...  

2014/07/03[   91.073430] bone-capemgr bone_capemgr.9: slot #7: 'Override Board Name,00A0,Override Manuf,cape-bone-iio'  

18:47:46 Initializing connection beaglebone ...  

2014/07/03 18:47:46 Initializi[   91.090829] bone-capemgr bone_capemgr.9: slot #7: Requesting part number/version based 'cape-bone-iio-00A0.dtbo  

ng devices...  

2014/07/03 18:47:46 Initializing device led ...  

[   91.107718] bone-capemgr bone_capemgr.9: slot #7: Requesting firmware 'cape-bone-iio-00A0.dtbo' for board-name 'Override Board Name', versio'  

2014/07/03 18:47:46 Starting Robot blinkBot ...  

2014/07/03 18:4[   91.127401] bone-capemgr bone_capemgr.9: slot #7: dtbo 'cape-bone-iio-00A0.dtbo' loaded; converting to live tree  

7:46 Starting connections...  

2014/07/03 18:47:46 Starting conne[   91.143345] bone-capemgr bone_capemgr.9: slot #7: #1 overlays  

ction beaglebone...  

[   91.165958] bone-iio-helper helper.15: ready  

[   91.180178] bone-capemgr bone_capemgr.9: slot #7: Applied #1 overlays.  

[   91.207658] bone-capemgr bone_capemgr.9: part_number 'am33xx_pwm', version 'N/A'  

[   91.227405] bone-capemgr bone_capemgr.9: slot #8: generic override  

[   91.234152] bone-capemgr bone_capemgr.9: bone: Using override eeprom data at slot 8  

[   91.242381] bone-capemgr bone_capemgr.9: slot #8: 'Override Board Name,00A0,Override Manuf,am33xx_pwm'  

[   91.262871] bone-capemgr bone_capemgr.9: slot #8: Requesting part number/version based 'am33xx_pwm-00A0.dtbo  

[   91.277644] bone-capemgr bone_capemgr.9: slot #8: Requesting firmware 'am33xx_pwm-00A0.dtbo' for board-name 'Override Board Name', version ''  

[   91.294162] bone-capemgr bone_capemgr.9: slot #8: dtbo 'am33xx_pwm-00A0.dtbo' loaded; converting to live tree  

[   91.308409] bone-capemgr bone_capemgr.9: slot #8: #8 overlays  

[   91.324218] ehrpwm 48300200.ehrpwm: unable to select pin group  

[   91.345215] ecap 48300100.ecap: unable to select pin group  

[   91.366683] ehrpwm 48302200.ehrpwm: unable to select pin group  

[   91.392535] ehrpwm 48304200.ehrpwm: unable to select pin group  

[   91.407299] ecap 48304100.ecap: unable to select pin group  

[   91.421773] bone-capemgr bone_capemgr.9: slot #8: Applied #8 overlays.  

2014/07/03 18:47:46 Starting devices...  

2014/07/03 18:47:46 Starting device led on pin usr1...  

2014/07/03 18:47:46 Starting work...  

此时,我们的BBB上面的usr1灯就会以1秒为周期的亮灭闪烁。  

3.参考网址  

http://gobot.io/documentation/platforms/beaglebone/

相关文章

网友评论

      本文标题:基于gobot框架在BBB Debian运行的GoLang程序

      本文链接:https://www.haomeiwen.com/subject/rhlshftx.html