2014-03-23 16:06:50 +05:30
|
|
|
# embd [![Build Status](https://travis-ci.org/kidoman/embd.svg?branch=master)](https://travis-ci.org/kidoman/embd) [![GoDoc](http://godoc.org/github.com/kidoman/embd?status.png)](http://godoc.org/github.com/kidoman/embd)
|
2013-12-07 23:11:06 +05:30
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
A superheroic hardware abstraction layer for doing embedded programming on supported platforms like the Raspberry Pi and BeagleBone Black.
|
2013-12-09 00:36:56 +05:30
|
|
|
|
2014-03-26 10:48:05 +05:30
|
|
|
Development sponsored by [**ThoughtWorks**](http://www.thoughtworks.com/)
|
|
|
|
|
2014-03-23 15:47:58 +05:30
|
|
|
## Platforms supported
|
2014-02-27 05:07:11 +05:30
|
|
|
|
|
|
|
* [RaspberryPi](http://www.raspberrypi.org/)
|
|
|
|
* [BeagleBone Black](http://beagleboard.org/Products/BeagleBone%20Black)
|
2014-03-23 15:47:58 +05:30
|
|
|
* [Intel Galileo](http://www.intel.com/content/www/us/en/do-it-yourself/galileo-maker-quark-board.html) **coming soon**
|
|
|
|
* [Radxa](http://radxa.com/) **coming soon**
|
|
|
|
* [Cubietruck](http://www.cubietruck.com/) **coming soon**
|
|
|
|
* Bring Your Own **coming soon**
|
|
|
|
|
|
|
|
## How to use
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
Package embd provides a superheroic hardware abstraction layer for doing embedded programming
|
2014-03-23 15:47:58 +05:30
|
|
|
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](https://github.com/kidoman/embd/tree/master/samples) folder,
|
|
|
|
we will show a few choice examples here.
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
Use the **LED** driver to toggle LEDs on the BBB:
|
2014-03-23 15:47:58 +05:30
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
...
|
|
|
|
embd.InitLED()
|
|
|
|
defer embd.CloseLED()
|
|
|
|
...
|
|
|
|
led, err := embd.NewLED("USR3")
|
|
|
|
...
|
|
|
|
led.Toggle()
|
|
|
|
|
|
|
|
Even shorter while prototyping:
|
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
...
|
|
|
|
embd.InitLED()
|
|
|
|
defer embd.CloseLED()
|
|
|
|
...
|
|
|
|
embd.ToggleLED(3)
|
|
|
|
|
2014-03-29 09:47:22 +05:30
|
|
|
NB: **3** == **USR3** for all intents and purposes. The driver is smart enough to figure all this out.
|
|
|
|
|
2014-03-28 08:39:36 +05:30
|
|
|
BBB + **PWM**:
|
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
...
|
|
|
|
embd.InitGPIO()
|
|
|
|
defer embd.CloseGPIO()
|
|
|
|
...
|
|
|
|
pwm, _ := embd.NewPWMPin("P9_14")
|
|
|
|
defer pwm.Close()
|
|
|
|
...
|
|
|
|
pwm.SetDuty(1000)
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
Control **GPIO** pins on the RaspberryPi / BeagleBone Black:
|
2014-03-23 15:47:58 +05:30
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
...
|
|
|
|
embd.InitGPIO()
|
|
|
|
defer embd.CloseGPIO()
|
|
|
|
...
|
|
|
|
embd.SetDirection(10, embd.Out)
|
|
|
|
embd.DigitalWrite(10, embd.High)
|
|
|
|
|
|
|
|
Could also do:
|
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
...
|
|
|
|
embd.InitGPIO()
|
|
|
|
defer embd.CloseGPIO()
|
|
|
|
...
|
|
|
|
pin, err := embd.NewDigitalPin(10)
|
|
|
|
...
|
|
|
|
pin.SetDirection(embd.Out)
|
|
|
|
pin.Write(embd.High)
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
Or read data from the **Bosch BMP085** barometric sensor:
|
2014-03-23 15:47:58 +05:30
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
import "github.com/kidoman/embd/sensor/bmp085"
|
|
|
|
...
|
|
|
|
bus := embd.NewI2CBus(1)
|
|
|
|
...
|
|
|
|
baro := bmp085.New(bus)
|
|
|
|
...
|
|
|
|
temp, err := baro.Temperature()
|
|
|
|
altitude, err := baro.Altitude()
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
Even find out the heading from the **LSM303** magnetometer:
|
2014-03-23 15:47:58 +05:30
|
|
|
|
|
|
|
import "github.com/kidoman/embd"
|
|
|
|
import "github.com/kidoman/embd/sensor/lsm303"
|
|
|
|
...
|
|
|
|
bus := embd.NewI2CBus(1)
|
|
|
|
...
|
|
|
|
mag := lsm303.New(bus)
|
|
|
|
...
|
|
|
|
heading, err := mag.Heading()
|
|
|
|
|
2014-03-26 10:10:57 +05:30
|
|
|
The above two examples depend on **I2C** and therefore will work without change on almost all
|
2014-03-23 15:47:58 +05:30
|
|
|
platforms.
|
2014-02-27 05:07:11 +05:30
|
|
|
|
2013-12-09 01:17:31 +05:30
|
|
|
## Protocols supported
|
|
|
|
|
2014-03-23 15:47:58 +05:30
|
|
|
* **Digital GPIO** [Documentation](http://godoc.org/github.com/kidoman/embd#DigitalPin)
|
|
|
|
* **Analog GPIO** [Documentation](http://godoc.org/github.com/kidoman/embd#AnalogPin)
|
2014-03-29 09:47:22 +05:30
|
|
|
* **PWM** [Documentation](http://godoc.org/github.com/kidoman/embd#PWMPin)
|
2014-03-23 15:47:58 +05:30
|
|
|
* **I2C** [Documentation](http://godoc.org/github.com/kidoman/embd#I2CBus)
|
|
|
|
* **LED** [Documentation](http://godoc.org/github.com/kidoman/embd#LED)
|
2013-12-09 01:17:31 +05:30
|
|
|
|
|
|
|
## Sensors supported
|
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **TMP006** Thermopile sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/tmp006), [Datasheet](http://www.adafruit.com/datasheets/tmp006.pdf), [Userguide](http://www.adafruit.com/datasheets/tmp006ug.pdf)
|
2013-12-21 02:06:06 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **BMP085** Barometric pressure sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/bmp085), [Datasheet](https://www.sparkfun.com/datasheets/Components/General/BST-BMP085-DS000-05.pdf)
|
2013-12-09 01:17:31 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **BMP180** Barometric pressure sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/bmp180), [Datasheet](http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf)
|
2013-12-13 05:51:22 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **LSM303** Accelerometer and magnetometer [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/lsm303), [Datasheet](https://www.sparkfun.com/datasheets/Sensors/Magneto/LSM303%20Datasheet.pdf)
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **L3GD20** Gyroscope [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/l3gd20), [Datasheet](http://www.adafruit.com/datasheets/L3GD20.pdf)
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **US020** Ultrasonic proximity sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/us020), [Product Page](http://www.digibay.in/sensor/object-detection-and-proximity?product_id=239)
|
2014-01-02 06:50:57 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **BH1750FVI** Luminosity sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/us020), [Datasheet](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)
|
2013-12-31 08:03:05 +05:30
|
|
|
|
2014-01-05 13:54:24 +05:30
|
|
|
## Interfaces
|
2013-12-31 08:03:05 +05:30
|
|
|
|
2014-01-06 02:47:25 +05:30
|
|
|
* **Keypad(4x3)** [Product Page](http://www.adafruit.com/products/419#Learn)
|
2014-01-05 13:54:24 +05:30
|
|
|
|
|
|
|
## Controllers
|
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **PCA9685** 16-channel, 12-bit PWM Controller with I2C protocol [Documentation](http://godoc.org/github.com/kidoman/embd/controller/pca9685), [Datasheet](http://www.adafruit.com/datasheets/PCA9685.pdf), [Product Page](http://www.adafruit.com/products/815)
|
2014-01-06 02:26:45 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **MCP4725** 12-bit DAC [Documentation](http://godoc.org/github.com/kidoman/embd/controller/mcp4725), [Datasheet](http://www.adafruit.com/datasheets/mcp4725.pdf), [Product Page](http://www.adafruit.com/products/935)
|
2014-01-09 02:35:18 +05:30
|
|
|
|
2014-02-10 05:05:41 +05:30
|
|
|
* **ServoBlaster** RPi PWM/PCM based PWM controller [Documentation](http://godoc.org/github.com/kidoman/embd/controller/servoblaster), [Product Page](https://github.com/richardghirst/PiBits/tree/master/ServoBlaster)
|