Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensor: Added support for the BME280 from Bosch. #72

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions AUTHORS

This file was deleted.

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This actually is really simple. A few simple guidelines and we can break for dinner:

* EMBD is designed with a lot of affection, with utmost importance given to the dev experience (read: the API feel and style.) So always think from that angle when creating the pull request
* [Documentation](https://godoc.org/github.com/kidoman/embd) helps drive adoption. No exceptions
* [Documentation](https://godoc.org/github.com/cfreeman/embd) helps drive adoption. No exceptions

When it comes to the code:

Expand All @@ -23,7 +23,7 @@ When it comes to the code:
this is inspired by Dave Cheney's gpio library and his work on EPOLL
```

* Individual lines must be wrapped at the 70-char limit. Yeah, old school
* Individual lines must be wrapped at the 70-char limit. Yeah, old school
* No trailing '.'

And:
Expand Down
17 changes: 0 additions & 17 deletions CONTRIBUTORS

This file was deleted.

151 changes: 78 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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)
# embd [![GoDoc](http://godoc.org/github.com/cfreeman/embd?status.png)](http://godoc.org/github.com/cfreeman/embd)

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

Expand All @@ -18,11 +18,6 @@ What embd then adds is first a Golang library interface on top of the various Li
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**](https://www.sostronk.com) and
[**ThoughtWorks**](http://www.thoughtworks.com/).

Also, you might be interested in: [Why Golang?](https://github.com/kidoman/embd/wiki/Why-Go)

[Blog post introducing EMBD](http://kidoman.io/framework/embd.html)

## Getting Started
Expand All @@ -37,8 +32,8 @@ package main
import (
"time"

"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/rpi" // This loads the RPi driver
"github.com/cfreeman/embd"
_ "github.com/cfreeman/embd/host/rpi" // This loads the RPi driver
)

func main() {
Expand All @@ -51,7 +46,7 @@ func main() {

Then install the EMBD package:

$ go get github.com/kidoman/embd
$ go get github.com/cfreeman/embd

Build the binary for linux/ARM:

Expand All @@ -74,22 +69,57 @@ Then on the rPi run the program with ```sudo```*:
* 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](https://github.com/kidoman/embd/blob/master/samples/fullblinker.go)
see the [full version](https://github.com/cfreeman/embd/blob/master/samples/fullblinker.go)

## Getting Help
## Supported Platforms

Join the [slack channel](https://gophers.slack.com/archives/embd)
* [BeagleBone Black](http://beagleboard.org/Products/BeagleBone%20Black)
* [Intel Edison](https://software.intel.com/en-us/iot/hardware/edison)
* [NextThing C.H.I.P](https://www.nextthing.co/pages/chip)
* [RaspberryPi 1 A+](http://www.raspberrypi.org/products/model-a-plus/)
* [RaspberryPi 1 B+](https://www.raspberrypi.org/products/model-b-plus/)
* [RaspberryPi 2](https://www.raspberrypi.org/products/raspberry-pi-2-model-b/)
* [RaspberryPi 3](https://www.raspberrypi.org/products/raspberry-pi-3-model-b/)

## Supported Protocols

* **Digital GPIO** [Documentation](http://godoc.org/github.com/cfreeman/embd#DigitalPin)
* **Analog GPIO** [Documentation](http://godoc.org/github.com/cfreeman/embd#AnalogPin)
* **PWM** [Documentation](http://godoc.org/github.com/cfreeman/embd#PWMPin)
* **I2C** [Documentation](http://godoc.org/github.com/cfreeman/embd#I2CBus)
* **LED** [Documentation](http://godoc.org/github.com/cfreeman/embd#LED)
* **SPI** [Documentation](http://godoc.org/github.com/cfreeman/embd#SPIBus)

## Supported Sensors

* **BH1750FVI** Luminosity sensor [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/bh1750fvi), [Datasheet](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)
* **BME280** Pressure, Temperature and Humidity Sensor [Documentation](https://godoc.org/github.com/cfreeman/embd/sensor/bme280), [Datasheet](https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf)
* **BMP085** Barometric pressure sensor [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/bmp085), [Datasheet](https://www.sparkfun.com/datasheets/Components/General/BST-BMP085-DS000-05.pdf)
* **BMP180** Barometric pressure sensor [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/bmp180), [Datasheet](http://www.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf)
* **L3GD20** Gyroscope [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/l3gd20), [Datasheet](http://www.adafruit.com/datasheets/L3GD20.pdf)
* **LSM303** Accelerometer and magnetometer [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/lsm303), [Datasheet](https://www.sparkfun.com/datasheets/Sensors/Magneto/LSM303%20Datasheet.pdf)
* **TMP006** Thermopile sensor [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/tmp006), [Datasheet](http://www.adafruit.com/datasheets/tmp006.pdf)
* **US020** Ultrasonic proximity sensor [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/us020), [Product Page](http://www.digibay.in/sensor/object-detection-and-proximity?product_id=239)
* **Watersensor** Based on LM393 (currently only provides digital support) [Documentation](http://godoc.org/github.com/cfreeman/embd/sensor/watersensor)[Datasheet](http://www.ti.com/lit/ds/symlink/lm393-n.pdf)

## Platforms Supported
## Interfaces

* **Keypad(4x3)** [Product Page](http://www.adafruit.com/products/419#Learn)

## Controllers

* **PCA9685** 16-channel, 12-bit PWM Controller with I2C protocol [Documentation](http://godoc.org/github.com/cfreeman/embd/controller/pca9685), [Datasheet](http://www.adafruit.com/datasheets/PCA9685.pdf), [Product Page](http://www.adafruit.com/products/815)
* **MCP4725** 12-bit DAC [Documentation](http://godoc.org/github.com/cfreeman/embd/controller/mcp4725), [Datasheet](http://www.adafruit.com/datasheets/mcp4725.pdf), [Product Page](http://www.adafruit.com/products/935)
* **ServoBlaster** RPi PWM/PCM based PWM controller [Documentation](http://godoc.org/github.com/cfreeman/embd/controller/servoblaster), [Product Page](https://github.com/richardghirst/PiBits/tree/master/ServoBlaster)

## Convertors

* **MCP3008** 8-channel, 10-bit ADC with SPI protocol, [Datasheet](https://www.adafruit.com/datasheets/MCP3008.pdf)

* [RaspberryPi](http://www.raspberrypi.org/) (including [A+](http://www.raspberrypi.org/products/model-a-plus/) and [B+](http://www.raspberrypi.org/products/model-b-plus/))
* [RaspberryPi 2](http://www.raspberrypi.org/)
* [NextThing C.H.I.P](https://www.nextthing.co/pages/chip)
* [BeagleBone Black](http://beagleboard.org/Products/BeagleBone%20Black)

## The command line tool

go get github.com/kidoman/embd/embd
go get github.com/cfreeman/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.

Expand All @@ -107,14 +137,14 @@ Package **embd** provides a hardware abstraction layer for doing embedded progra
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,
Although samples are all present in the [samples](https://github.com/cfreeman/embd/tree/master/samples) folder,
we will show a few choice examples here.

Use the **LED** driver to toggle LEDs on the BBB:

```go
import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import _ "github.com/cfreeman/embd/host/all"
...
embd.InitLED()
defer embd.CloseLED()
Expand All @@ -127,8 +157,8 @@ led.Toggle()
Even shorter when quickly trying things out:

```go
import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import _ "github.com/cfreeman/embd/host/all"
...
embd.InitLED()
defer embd.CloseLED()
Expand All @@ -141,8 +171,8 @@ embd.ToggleLED(3)
BBB + **PWM**:

```go
import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import _ "github.com/cfreeman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
Expand All @@ -156,8 +186,8 @@ pwm.SetDuty(1000)
Control **GPIO** pins on the RaspberryPi / BeagleBone Black:

```go
import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import _ "github.com/cfreeman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
Expand All @@ -169,8 +199,8 @@ embd.DigitalWrite(10, embd.High)
Could also do:

```go
import "github.com/kidoman/embd"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import _ "github.com/cfreeman/embd/host/all"
...
embd.InitGPIO()
defer embd.CloseGPIO()
Expand All @@ -184,9 +214,9 @@ pin.Write(embd.High)
Or read data from the **Bosch BMP085** barometric sensor:

```go
import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/bmp085"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import "github.com/cfreeman/embd/sensor/bmp085"
import _ "github.com/cfreeman/embd/host/all"
...
bus := embd.NewI2CBus(1)
...
Expand All @@ -199,9 +229,9 @@ altitude, err := baro.Altitude()
Even find out the heading from the **LSM303** magnetometer:

```go
import "github.com/kidoman/embd"
import "github.com/kidoman/embd/sensor/lsm303"
import _ "github.com/kidoman/embd/host/all"
import "github.com/cfreeman/embd"
import "github.com/cfreeman/embd/sensor/lsm303"
import _ "github.com/cfreeman/embd/host/all"
...
bus := embd.NewI2CBus(1)
...
Expand All @@ -213,47 +243,22 @@ heading, err := mag.Heading()
The above two examples depend on **I2C** and therefore will work without change on almost all
platforms.

## Protocols Supported

* **Digital GPIO** [Documentation](http://godoc.org/github.com/kidoman/embd#DigitalPin)
* **Analog GPIO** [Documentation](http://godoc.org/github.com/kidoman/embd#AnalogPin)
* **PWM** [Documentation](http://godoc.org/github.com/kidoman/embd#PWMPin)
* **I2C** [Documentation](http://godoc.org/github.com/kidoman/embd#I2CBus)
* **LED** [Documentation](http://godoc.org/github.com/kidoman/embd#LED)
* **SPI** [Documentation](http://godoc.org/github.com/kidoman/embd#SPIBus)

## Sensors Supported

* **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)
* **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)
* **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)
* **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)
* **L3GD20** Gyroscope [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/l3gd20), [Datasheet](http://www.adafruit.com/datasheets/L3GD20.pdf)
* **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)
* **BH1750FVI** Luminosity sensor [Documentation](http://godoc.org/github.com/kidoman/embd/sensor/bh1750fvi), [Datasheet](http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf)

## Interfaces

* **Keypad(4x3)** [Product Page](http://www.adafruit.com/products/419#Learn)

## Controllers

* **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)
* **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)
* **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)

## Convertors

* **MCP3008** 8-channel, 10-bit ADC with SPI protocol, [Datasheet](https://www.adafruit.com/datasheets/MCP3008.pdf)

## Contributing

[Pull requests](https://github.com/kidoman/embd/pulls) that follow the
[guidelines](https://github.com/kidoman/embd/blob/master/CONTRIBUTING.md) are very appreciated.
[Pull requests](https://github.com/cfreeman/embd/pulls) that follow the
[guidelines](https://github.com/cfreeman/embd/blob/master/CONTRIBUTING.md) are very appreciated.

If you find a problem but are not up to coding a fix please file an
[issue](https://github.com/kidoman/embd/issues).
[issue](https://github.com/cfreeman/embd/issues).
Thank you!

## About
## ROADMAP

EMBD is affectionately designed/developed by Karan Misra ([kidoman](https://github.com/kidoman)), Kunal Powar ([kunalpowar](https://github.com/kunalpowar)) and [FRIENDS](https://github.com/kidoman/embd/blob/master/AUTHORS). We also have a list of [CONTRIBUTORS](https://github.com/kidoman/embd/blob/master/CONTRIBUTORS).
* Continue to tidy up the README and other documentation.
* move utils.go into util package
* Make sure there are samples for all supported hardware. Better organise samples move into godoc?
* Rummage through the old, largely abandoned parent repo and pull in as many of the requests as possible.
* A fully featured cli tool (**embd**)
* Continue to add support for additional sensors/controllers/convertors.
* Continue to add support for additional hosts (Cubietruck, Radxa, etc).
* Supporting something other than Linux
14 changes: 0 additions & 14 deletions ROADMAP.md

This file was deleted.

85 changes: 85 additions & 0 deletions controller/apa102/apa102.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) Clinton Freeman 2017
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package apa102

import (
"github.com/cfreeman/embd"
)

const (
MAX_BRIGHTNESS = 31
)

type APA102 struct {
Bus embd.SPIBus
LED []uint8
nLED int
}

func New(bus embd.SPIBus, numLEDs int) *APA102 {
res := &APA102{
Bus: bus,
LED: make([]uint8, numLEDs*4),
nLED: numLEDs,
}

// Init the intensity field for each LED which is
// 0b111 + 5 intensity bits.
for i := 0; i < (numLEDs * 4); i = i + 4 {
res.LED[i] = 224
}

return res
}

func (a *APA102) SetLED(index int, r uint8, g uint8, b uint8, i uint8) error {
intensity := i
if i > 31 {
intensity = 31
}

ind := index * 4

a.LED[ind+0] = 224 + intensity // Brightness is 0b111 + 5 intensity bits
a.LED[ind+1] = b
a.LED[ind+2] = g
a.LED[ind+3] = r

return a.Show()
}

func (a *APA102) Show() error {
// Start frame is 32 zero bits.
err := a.Bus.TransferAndReceiveData([]uint8{0, 0, 0, 0})

// LED data.
// 111+5bits(intensity) + 1byte(Red) + 1byte(Green) + 1byte(Blue)
err = a.Bus.TransferAndReceiveData(a.LED)
if err != nil {
return err
}

err = a.Bus.TransferAndReceiveData([]uint8{1, 1, 1, 1})
if err != nil {
return err
}

return nil
}
Loading