在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:kidoman/embd开源软件地址:https://github.com/kidoman/embd开源编程语言:Go 99.9%开源软件介绍:embdembd is a hardware abstraction layer (HAL) for embedded systems. It allows you to start your hardware hack on easily available hobby boards (like the Raspberry Pi, BeagleBone Black, C.H.I.P., etc.) by giving you straight-forward access to the board's capabilities as well as a plethora of sensors (like accelerometers, gyroscopes, thermometers, etc.) and controllers (PWM generators, digital-to-analog convertors) for which it includes drivers. If you move to custom designed boards you have to throw away your code: you carry forward the effort where the HAL abstraction of EMBD will save you precious time. The overall strategy used in embd is to use Linux device drivers to access gpio pins, SPI and I2C buses, as well as interrupts. This makes it easy to port from one platform to another and it enables kernel code to handle the devices as efficiently as possible. What embd then adds is first a Golang library interface on top of the various Linux devices and then another layer of user-level drivers for specific sensors and controllers that are connected to gpio pins or one of the buses. Development supported and sponsored by SoStronk and ThoughtWorks. Also, you might be interested in: Why Golang? Getting StartedInstall Go version 1.6 or later to make compiling for ARM easy.
The set up your GOPATH,
and create your first .go file. We'll call it package main
import (
"time"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/rpi" // This loads the RPi driver
)
func main() {
for {
embd.LEDToggle("LED0")
time.Sleep(250 * time.Millisecond)
}
} Then install the EMBD package:
Build the binary for linux/ARM:
Copy the cross-compiled binary to your RaspberryPi*:
Then on the rPi run the program with
You will now see the green LED (next to the always on power LED) blink every 1/4 sec. * Notes
Getting HelpJoin the slack channel Platforms Supported
The command line tool
will install a command line utility For example, if you run
Run How to use the frameworkPackage embd provides a hardware abstraction layer for doing embedded programming on supported platforms like the Raspberry Pi and BeagleBone Black. Most of the examples below will work without change (i.e. the same binary) on all supported platforms. How cool is that? Although samples are all present in the samples folder, we will show a few choice examples here. Use the LED driver to toggle LEDs on the BBB: import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
...
embd.InitLED()
defer embd.CloseLED()
...
led, err := embd.NewLED(3)
...
led.Toggle() Even shorter when quickly trying things out: import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
...
embd.InitLED()
defer embd.CloseLED()
...
embd.ToggleLED(3) 3 is the same as USR3 for all intents and purposes. The driver is smart enough to figure all this out. BBB + PWM: import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
pwm, _ := embd.NewPWMPin("P9_14")
defer pwm.Close()
...
pwm.SetDuty(1000) Control GPIO pins on the RaspberryPi / BeagleBone Black: import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
embd.SetDirection(10, embd.Out)
embd.DigitalWrite(10, embd.High) Could also do: import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
...
pin, err := embd.NewDigitalPin(10)
...
pin.SetDirection(embd.Out)
pin.Write(embd.High) Or read data from the Bosch BMP085 barometric sensor: import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/bmp085"
import _ "github.com/kidoman/embd/host/all"
...
bus := embd.NewI2CBus(1)
...
baro := bmp085.New(bus)
...
temp, err := baro.Temperature()
altitude, err := baro.Altitude() Even find out the heading from the LSM303 magnetometer: import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/lsm303"
import _ "github.com/kidoman/embd/host/all"
...
bus := embd.NewI2CBus(1)
...
mag := lsm303.New(bus)
...
heading, err := mag.Heading() The above two examples depend on I2C and therefore will work without change on almost all platforms. Protocols Supported
Sensors Supported
Interfaces
Controllers
Convertors
ContributingPull requests that follow the guidelines are very appreciated. If you find a problem but are not up to coding a fix please file an issue. Thank you! AboutEMBD is affectionately designed/developed by Karan Misra (kidoman), Kunal Powar (kunalpowar) and FRIENDS. We also have a list of CONTRIBUTORS. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论