pmsa003i

package
v0.0.0-...-bd62a88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package pmsa003i 30 controls a PMSA003i particle sensor over I²C.

Datasheet

https://cdn-shop.adafruit.com/product-files/4632/4505_PMSA003I_series_data_manual_English_V2.6.pdf

Example
package main

import (
	"fmt"
	"log"
	"time"

	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/host"

	"github.com/bcl/air-sensors/pmsa003i"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	// Open a handle to the first available I²C bus:
	bus, err := i2creg.Open("")
	if err != nil {
		log.Fatal(err)
	}
	defer bus.Close()

	d, err := pmsa003i.New(bus)
	if err != nil {
		log.Fatal(err)
	}

	for {
		time.Sleep(1 * time.Second)

		// Read the PMSA003i sensor data
		r, err := d.ReadSensor()
		if err != nil {
			// Checksum failures could be transient
			fmt.Println(err)
		} else {
			fmt.Println()
			fmt.Printf("PM1.0  %3d μg/m3\n", r.EnvPm1)
			fmt.Printf("PM2.5  %3d μg/m3\n", r.EnvPm2_5)
			fmt.Printf("PM10   %3d μg/m3\n", r.EnvPm10)
			fmt.Println("Counters in 0.1L of air")
			fmt.Printf("%d > 0.3μm\n", r.Cnt0_3)
			fmt.Printf("%d > 0.5μm\n", r.Cnt0_5)
			fmt.Printf("%d > 1.0μm\n", r.Cnt1)
			fmt.Printf("%d > 2.5μm\n", r.Cnt2_5)
			fmt.Printf("%d > 5.0μm\n", r.Cnt5)
			fmt.Printf("%d > 10μm\n", r.Cnt10)
			fmt.Println()
		}
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	// contains filtered or unexported fields
}

Dev holds the connection and error details for the device

func New

func New(i i2c.Bus) (*Dev, error)

New returns a PMSA003I device struct for communicating with the device

func (*Dev) Halt

func (d *Dev) Halt() error

Halt implements conn.Resource.

func (*Dev) ReadSensor

func (d *Dev) ReadSensor() (Results, error)

ReadSensor returns particle measurement results

type Results

type Results struct {
	CfPm1    uint16 // PM1.0 in μg/m3 standard particle
	CfPm2_5  uint16 // PM2.5 in μg/m3 standard particle
	CfPm10   uint16 // PM10 in μg/m3 standard particle
	EnvPm1   uint16 // PM1.0 in μg/m3 atmospheric environment
	EnvPm2_5 uint16 // PM2.5 in μg/m3 atmospheric environment
	EnvPm10  uint16 // PM10 in μg/m3 atmospheric environment
	Cnt0_3   uint16 // Count of particles > 0.3μm in 0.1L of air
	Cnt0_5   uint16 // Count of particles > 0.5μm in 0.1L of air
	Cnt1     uint16 // Count of particles > 1.0μm in 0.1L of air
	Cnt2_5   uint16 // Count of particles > 2.5μm in 0.1L of air
	Cnt5     uint16 // Count of particles > 5.0μm in 0.1L of air
	Cnt10    uint16 // Count of particles > 10.0μm in 0.1L of air
	Version  uint8
}

Results contains the measurements from the PMSA003i

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL