Code Monkey home page Code Monkey logo

go-enviroplus's Introduction

Pimoroni Enviro+ Drivers

Go library to read data from Pimoroni's Enviro+ sensors.

⚠️ Experimental, API subject to change ⚠

BME250

Package to read pressure, relative humidity and temperature sensors.

package main

import (
	"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 from Pimoroni.

Reading data from the sensor

// Read proximity and light from the LTR559 sensor
package main

import (
	"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.

package main

import (
	"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)
	}
}

go-enviroplus's People

Contributors

rubiojr avatar sighmon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sighmon umetaman

go-enviroplus's Issues

Static Gas Readings

Hello! Hope this finds you well. I've just had a try using the enviro+ to get the gas measures using the MICS6814. I've copied the example out of the files into a test script.

Unfortunately, I'm seeing something weird, which is a a constant value for oxidising, reducing, and NH3.

Oxidising: 25193.96
Reducing:  25193.96
NH3:       25193.96

I've not had a chance to look into it properly, but wanted to post here just in case anyone would happen to know what's going on. The python version reading the sensor seems to deliver the correct results (again, I've yet to investigate).

My sample code is here. I've been running this on a Pi Zero W with Enviro+ (Air quality as well).

Any help would be much appreciated!! If I have time to look into this more, I'll be sure to update this issue

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.