https://github.com/zaquestion/go-envirophat
https://github.com/zaquestion/go-envirophat
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/zaquestion/go-envirophat
- Owner: zaquestion
- Created: 2018-11-07T07:20:43.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-17T21:57:43.000Z (about 7 years ago)
- Last Synced: 2025-01-30T10:41:46.585Z (12 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
go-envirophat
==
`go-envirophat` is a port of the python library [enviro-phat](https://github.com/pimoroni/enviro-phat) with some design liberties taken. It allows you to interact with the [Enviro pHAT](https://shop.pimoroni.com/products/enviro-phat) on the Rasberry Pi.
### Leds
```
import "github.com/zaquestion/go-envirophat/leds"
```
```
leds.On()
```
### Light
```
import "github.com/zaquestion/go-envirophat/light"
```
```
i2c, err := light.InitI2C()
if err != nil {
log.Fatal(err)
}
defer i2c.Close()
data, err := light.Read()
if err != nil {
log.Fatal(err)
}
buf, err := json.Marshal(data)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(buf))
```
yields
```
{
"Red": 161,
"Green": 108,
"Blue": 98,
"RawLux": 1183,
"RawRed": 749,
"RawGreen": 505,
"RawBlue": 456,
"NormalRed": 0.6331360946745562,
"NormalGreen": 0.4268808114961961,
"NormalBlue": 0.38546069315300086
}
```
### Weather
```
i2c, err := weather.InitI2C()
if err != nil {
log.Fatal(err)
}
defer i2c.Close()
// Read temperature in celsius degree
t, err := weather.Temperature()
if err != nil {
log.Fatal(err)
}
log.Printf("Temperature = %v*C\n", t)
// Read atmospheric pressure in pascal
p, err := weather.Pressure()
if err != nil {
log.Fatal(err)
}
log.Printf("Pressure = %v Pa\n", p)
// Read atmospheric altitude in meters above sea level, if we assume
// that pressure at see level is equal to 101325 Pa.
a, err := weather.Altitude()
if err != nil {
log.Fatal(err)
}
log.Printf("Altitude = %v m\n", a)
```
### TODO:
- Remaining sensors
- Support raspberry pi 1?