Go to file
Thorsten von Eicken 6cfa481f30 Support SPI minor devices >255 (PR #33) 2016-09-05 23:13:14 -07:00
controller removing failed Stat use 2015-10-10 23:58:24 -04:00
convertors Fix typo 2015-12-22 12:54:33 -05:00
embd cli: print the rev number in hex 2015-01-15 06:56:14 +05:30
host Support SPI minor devices >255 (PR #33) 2016-09-05 23:13:14 -07:00
interface interface: add an abstraction layer for character displays 2015-02-25 00:12:09 -08:00
motion/servo unified servo and analog output support for pwms 2014-04-02 17:25:28 +05:30
samples Println doesn't accept formatting. 2015-12-22 17:05:28 -05:00
sensor gpio: provide an api to allow performance timing of pulses 2014-04-05 04:06:40 +05:30
util add test for Map 2014-03-02 14:53:09 +05:30
.gitignore bring in the idea of a hardware abstraction layer 2014-02-27 04:24:53 +05:30
.travis.yml ci: update versions of go we build against 2015-01-15 02:43:28 +05:30
AUTHORS added support for us020 ultra sonic range finder 2013-12-13 05:51:22 +05:30
CONTRIBUTING.md doc: how to contribute 2014-04-11 07:58:38 +05:30
CONTRIBUTORS doc: updated contributors list 2015-01-15 05:39:26 +05:30
LICENSE initial commit 2013-12-08 17:39:41 +05:30
README.md Update README for CHIP support by TvE 2016-09-05 23:11:12 -07:00
ROADMAP.md doc: add roadmap 2014-04-07 02:45:20 +05:30
descriptor.go spi: added spi feature for all bbb and rpi 2014-04-28 01:18:14 +05:30
detect.go add minimal support for NextThing CHIP 2016-08-26 23:00:39 -07:00
detect_test.go simplify package structure 2014-03-03 00:51:23 +05:30
doc.go doc: -superheroic 2014-04-16 14:05:13 +05:30
gpio.go gpio: better docs 2015-01-15 05:59:03 +05:30
gpiodriver.go gpio: added pinmap accessor for introspection usage 2015-01-15 05:47:02 +05:30
gpiodriver_test.go gpio: added missing function in fakeDigitalPin 2014-09-02 23:33:07 -04:00
i2c.go removing failed Stat use 2015-10-10 23:58:24 -04:00
i2cdriver.go host specific drivers can now be loaded separately 2014-04-06 06:50:09 +05:30
led.go allow lazy initialisation of the drivers 2014-04-11 09:19:03 +05:30
leddriver.go host specific drivers can now be loaded separately 2014-04-06 06:50:09 +05:30
pin.go gpio: CapNormal -> CapAnalog 2014-03-23 14:11:09 +05:30
pin_test.go gpio: CapNormal -> CapAnalog 2014-03-23 14:11:09 +05:30
spi.go Fix typo 2015-12-22 12:54:33 -05:00
spidriver.go Support SPI minor devices >255 (PR #33) 2016-09-05 23:13:14 -07:00
update_contibutors.sh doc: list of contributors 2014-05-19 11:20:28 +05:30
utils.go host specific drivers can now be loaded separately 2014-04-06 06:50:09 +05:30

README.md

embd Build Status GoDoc

embd is a hardware abstraction layer (HAL) for embedded systems.

The github.com/tve/embd fork attempts to continue the work started by @kidoman and adds support for NextThing's C.H.I.P.

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 staight 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 we have written drivers. And when things get serious, you dont have to throw away the code. You carry forward the effort onto more custom designed boards where the HAL abstraction of EMBD will save you precious time.

Original development supported and sponsored by SoStronk and ThoughtWorks.

Also, you might be interested in: Why Golang?

Blog post introducing EMBD

Getting Started

After installing Go* and setting up your GOPATH, create your first .go file. We'll call it simpleblinker.go.

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 (go1.6 or greater is required):

$ go get github.com/tve/embd

Build the binary*:

$ export GOOS=linux
$ export GOARCH=arm
$ go build simpleblinker.go

Copy the cross-compiled binary to your RaspberryPi*:

$ scp simpleblinker pi@192.168.2.2:~

Then run the program with sudo*:

$ sudo ./simpleblinker

You will now see the green LED (next to the always on power LED) blink every 1/4 sec.

* Notes

  • We are instructing the go compiler to create a binary which will run on the RaspberryPi processor
  • Assuming your RaspberryPi has an IP address of 192.168.2.2. Substitute as necessary
  • sudo (root) permission is required as we are controlling the hardware by writing to special files
  • This sample program is optimized for brevity and does not clean up after itself. Click here to see the full version

Getting Help

Join the mailing list

Platforms Supported

The command line tool

go get github.com/kidoman/embd/embd

will install a command line utility embd which will allow you to quickly get started with prototyping. The binary should be available in your $GOPATH/bin. However, to be able to run this on a ARM based device, you will need to build it with GOOS=linux and GOARCH=arm environment variables set.

But, since I am feeling so generous, a prebuilt/tested version is available for direct download and deployment here.

For example, if you run embd detect on a BeagleBone Black:

root@beaglebone:~# embd detect

detected host BeagleBone Black (rev 0)

Run embd without any arguments to discover the various commands supported by the utility.

How to use the framework

Package 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.

Using embd on CHIP

The CHIP drivers support gpio, I2C, SPI, and pin interrupts. Not supported are PWM or LED. The names of the pins on chip have multiple aliases. The official CHIP pin names are supported, for example XIO-P1 or LCD-D2 and the pin number are also supported, such as U14-14 (same as XIO-P1) or U13-17. Some of the alternate function names are also supported, like "SPI2_MOSI", and the linux 4.4 kernel gpio pin numbers as well, e.g., 1017 for XIO-P1. Finally, the official GPIO pins (XIO-P0 thru XIO-P7) can be addressed as gpio0-gpio7.

A simple demo to blink an LED connected with a small resistor between XIO-P6 and 3.3V is

package main
import (
	"time"
	"github.com/kidoman/embd"
	_ "github.com/kidoman/embd/host/chip"
)

func main() {
	embd.InitGPIO()
	defer embd.CloseGPIO()

	embd.SetDirection("gpio6", embd.Out)
	on := 0
	for {
		embd.DigitalWrite("gpio6", on)
		on = 1 - on
		time.Sleep(250 * time.Millisecond)
	}
}

Run it as root: sudo ./blinky

Protocols Supported

Sensors Supported

Interfaces

Controllers

Convertors

  • MCP3008 8-channel, 10-bit ADC with SPI protocol, Datasheet

Contributing

We look forward to your pull requests, but contributions which abide by the guidelines will get a free beer!

File an issue, open a pull request. We are waiting.

About

EMBD is affectionately designed/developed by Karan Misra (kidoman), Kunal Powar (kunalpowar) and FRIENDS. We also have a list of CONTRIBUTORS.