首页 > 编程语言 >基于gobot框架在BBB Debian运行的GoLang程序

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

时间:2024-08-17 13:22:58浏览次数:6  
标签:slot gobot beaglebone BBB capemgr capemgr.9 GoLang bone

为了让GoLang与BBB(BeagleBoneBlack开发板)搭配使用,我们借助了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/

标签:slot,gobot,beaglebone,BBB,capemgr,capemgr.9,GoLang,bone
From: https://blog.csdn.net/guochongxin/article/details/141139923

相关文章

  • Golang使用Option设计模式优雅处理可选参数
    go语言不像其他语言函数的参数可以设置默认值以下是参考第三方库的写法packagemainimport"fmt"typeUserstruct{namestringageintidint}//Option代表可选参数typeOptionfunc(foo*User)//WithName为name字段提供一个设置器funcWithName(name......
  • golang json inline用法
    packagemainimport( "encoding/json" "fmt")typeProjectstruct{ Keystring`json:"key"` Valuestring`json:"value"`}typeJiraHttpReqFieldstruct{ Project`json:",inline"` Summarystring`jso......
  • 区块链编程-golang(三)
    文件目录主文件下有文件blockchain、go.mod、gosum、文件tmp、main.go文件blockhain下面有block.go、blockchain.go、proof.go part1:block.gopackageblockchainimport("bytes""encoding/gob""log")typeBlockstruct{Hash[]b......
  • 掌握Golang的html/template:打造动态网页的秘籍
    掌握Golang的html/template:打造动态网页的秘籍在Web开发的世界中,动态内容的生成是至关重要的。Golang以其简洁高效的特性,成为了后端开发的热门选择。而html/template包,则是Golang中用于创建HTML模板的官方工具,它不仅安全,而且功能强大。本文将带领你深入了解如何使用html/te......
  • 推荐项目:安企CMS - 一款使用 GoLang 开发的企业内容管理系统
    安企内容管理系统(AnqiCMS),是一款基于iris框架,使用GoLang开发的企业内容管理系统。https://gitcode.com/anqicms/anqicms/overview推荐理由安企内容管理系统(AnqiCMS),是一款基于iris框架,使用GoLang开发的企业内容管理系统。它部署简单,软件相对于传统的PHP开发......
  • golang gin框架中创建自定义中间件的2种方式总结 - func(*gin.Context)方式和闭包函数
    在gin框架中,我们可以通过2种方式创建自定义中间件:1.直接定义一个类型为 func(*gin.Context)的函数或者方法    这种方式是我们常用的方式,也就是定义一个参数为*gin.Context的函数或者方法。定义的方法就是创建一个参数类型为gin.HandlerFunc【他的原型定义为t......
  • Golang文件操作秘籍:ioutil包的终极指南
    Golang文件操作秘籍:ioutil包的终极指南在Go语言的世界中,文件操作是一项基本而常见的任务。Go标准库中的ioutil包提供了一些简便的方法来执行常见的I/O操作,包括文件的读写。本文将深入探讨如何使用ioutil包进行文件读写操作,并提供详细的代码示例,帮助你快速掌握这一技能。io......
  • Golang httputil 包深度解析:HTTP请求与响应的操控艺术
    标题:Golanghttputil包深度解析:HTTP请求与响应的操控艺术引言在Go语言的丰富标准库中,net/http/httputil包是一个强大的工具集,它提供了操作HTTP请求和响应的高级功能。从创建自定义的HTTP代理到调试HTTP流量,httputil包都能提供必要的支持。本文将深入探讨httputil包的功能......
  • 我的Golang语言学习日记(简单快速易懂,保姆级包教会!)
    文章目录前言一、Golang是什么?二、Golang本地部署1.引入库2.读入数据总结前言随着云的不断发展,Golang这门语言也越来越重要,很多人都开启了学习Golang,本文就介绍了Golang的基础内容。一、Golang是什么?Golang,也被称为Go,是由Google公司于2009年发布的一种开源编......
  • Golang - goto语句
    用途可以无条件地转移到过程中指定的行。该语句通常与条件语句配合使用,可用来实现条件转移,构成循环,跳出循环体等功能,但在结构化程序设计中一般不主张使用goto语句,以免造成程序流程的混乱,使理解和调试程序都产生困难。语法gotolabel;...label:statement;注意:作用域......