https://github.com/rubiojr/go-enviroplus
Go module to read Pimoroni's Enviro+ sensors
https://github.com/rubiojr/go-enviroplus
enviroplus periphio pimoroni
Last synced: 3 months ago
JSON representation
Go module to read Pimoroni's Enviro+ sensors
- Host: GitHub
- URL: https://github.com/rubiojr/go-enviroplus
- Owner: rubiojr
- License: bsd-2-clause
- Created: 2021-01-24T17:40:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-02T20:42:10.000Z (over 3 years ago)
- Last Synced: 2025-01-26T11:09:10.582Z (4 months ago)
- Topics: enviroplus, periphio, pimoroni
- Language: HTML
- Homepage:
- Size: 4.38 MB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pimoroni Enviro+ Drivers
Go library to read data from [Pimoroni's Enviro+](https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-enviro-plus) sensors.
⚠️ Experimental, API subject to change ⚠
## BME250
Package to read pressure, relative humidity and temperature sensors.
```Go
package mainimport (
"fmt"
"log"
"periph.io/x/periph/conn/i2c/i2creg"
"periph.io/x/periph/conn/physic"
"periph.io/x/periph/devices/bmxx80"
"periph.io/x/periph/host"
)func main() {
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
log.Fatal(err)
}// Use i2creg I²C bus registry to find the first available I²C bus.
b, err := i2creg.Open("")
if err != nil {
log.Fatalf("failed to open I²C: %v", err)
}
defer b.Close()d, err := bmxx80.NewI2C(b, 0x76, &bmxx80.DefaultOpts)
if err != nil {
log.Fatalf("failed to initialize bme280: %v", err)
}
e := physic.Env{}
if err := d.Sense(&e); err != nil {
log.Fatal(err)
}
fmt.Printf("%8s %10s %9s\n", e.Temperature, e.Pressure, e.Humidity)
}
```## LTR559
Light/Proximity Sensor.
The driver is a port of [the Python driver](https://github.com/pimoroni/ltr559-python) from Pimoroni.
### Reading data from the sensor
```Go
// Read proximity and light from the LTR559 sensor
package mainimport (
"fmt"
"time""github.com/rubiojr/go-enviroplus/ltr559"
)func main() {
d := ltr559.New()fmt.Printf("Manufacturer ID: 0x%x\n", d.ManufacturerID())
fmt.Printf("Part ID: 0x%x\n", d.PartID())for {
fmt.Println("proximity: ", d.Proximity())
fmt.Println(" lux: ", d.Lux())
time.Sleep(1 * time.Second)
}
}
```### PMS5003
Particle concentration sensor.
```Go
package mainimport (
"fmt""github.com/rubiojr/go-enviroplus/pms5003"
)func main() {
dev, err := pms5003.New()
if err != nil {
panic(err)
}
go func() {
dev.StartReading()
}()
for {
r := dev.LastValue()
fmt.Println("-------")
fmt.Println("PM1.0 ug/m3 (ultrafine): ", r.Pm10Std)
fmt.Println("PM2.5 ug/m3 (combustion, organic comp, metals): ", r.Pm25Std)
fmt.Println("PM10 ug/m3 (dust, pollen, mould spores): ", r.Pm100Std)
fmt.Println("PM1.0 ug/m3 (atmos env): ", r.Pm10Env)
fmt.Println("PM2.5 ug/m3 (atmos env): ", r.Pm25Env)
fmt.Println("PM10 ug/m3 (atmos env): ", r.Pm100Env)
fmt.Println("0.3um 1 0.1L air: ", r.Particles3um)
fmt.Println("0.5um 1 0.1L air: ", r.Particles5um)
fmt.Println("1.0um 1 0.1L air: ", r.Particles10um)
fmt.Println("2.5um 1 0.1L air: ", r.Particles25um)
fmt.Println("5um 1 0.1L air: ", r.Particles50um)
fmt.Println("10um 1 0.1L air: ", r.Particles100um)
time.Sleep(1 * time.Second)
}
}
```