as7262

package
v3.6.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package as7262 controls an AMS 6 channel visible spectral sensor via an i2c interface. The as7262 features 6 spectral channels spaced at 450, 500, 550, 570, 600, 650 nm and includes 2 integrated LED drivers.

Datasheet

https://ams.com/documents/20143/36005/AS7262_DS000486_2-00.pdf

Example
package main

import (
	"fmt"
	"log"
	"time"

	"periph.io/x/periph/conn/physic"

	"periph.io/x/periph/conn/i2c/i2creg"
	"periph.io/x/periph/experimental/devices/as7262"
	"periph.io/x/periph/host"
)

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

	// Open default I²C bus.
	bus, err := i2creg.Open("")
	if err != nil {
		log.Fatalf("failed to open I²C: %v", err)
	}
	defer bus.Close()

	// Create a new spectrum sensor.
	sensor, err := as7262.New(bus, &as7262.DefaultOpts)
	if err != nil {
		log.Fatalln(err)
	}

	// Read values from sensor.
	spectrum, err := sensor.Sense(25*physic.MilliAmpere, 500*time.Millisecond)

	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(spectrum)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultOpts = Opts{
	InterruptPin: nil,
	Gain:         G1x,
}

DefaultOpts are the recommended default options.

Functions

This section is empty.

Types

type Band

type Band struct {
	Wavelength physic.Distance
	Value      float64
	Counts     uint16
	Name       string
}

Band has two types of measurement of relative spectral flux density.

Value

Value are the calibrated readings. The accuracy of the channel counts/μW/cm2 is ±12%.

Counts

Counts are the raw readings, there are approximately 45 counts/μW/cm2 with a gain of 16 (Gx16).

Wavelength

Wavelength is the nominal center of a band, with a ±40nm bandwidth around the center. Wavelengths for the as7262 are: 450nm, 500nm, 550nm, 570nm, 600nm and 650nm.

func (Band) String

func (b Band) String() string

type Dev

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

Dev is a handle to the as7262 sensor.

func New

func New(bus i2c.Bus, opts *Opts) (*Dev, error)

New opens a handle to an AS7262 sensor.

func (*Dev) Gain

func (d *Dev) Gain(gain Gain) error

Gain sets the gain of the sensor. There are four levels of gain 1x, 3.7x, 16x, and 64x.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt stops any pending operations. Repeated calls to Halt do nothing.

func (*Dev) Sense

func (d *Dev) Sense(ledDrive physic.ElectricCurrent, senseTime time.Duration) (Spectrum, error)

Sense preforms a reading of relative spectral radiance of all the sensor bands.

Led Drive Current

The AS7262 provides a current-limited integrated led drive circuit. Valid limits for the drive current are 0mA, 12.5mA, 25mA, 50mA and 100mA. If non valid values are given the next lowest valid value is used.

Resolution

For best resolution it is recommended that for a specific led drive current that the senseTime or gain is increased until at least one of the bands returns a count above 10000. The maximum senseTime time is 714ms senseTime will be quantised into intervals of of 2.8ms. Actual time taken to make a reading is twice the senseTime.

func (*Dev) String

func (d *Dev) String() string

type Gain

type Gain int

Gain is the sensor gain for all bands

const (
	// G1x is gain of 1
	G1x Gain = 0x00
	// G4x is gain of 3.7
	G4x Gain = 0x10
	// G16x is a gain of 16
	G16x Gain = 0x20
	// G64x us a gain of 64
	G64x Gain = 0x30
)

func (Gain) String

func (g Gain) String() string

type IOError

type IOError struct {
	Op  string
	Err error
}

IOError is a I/O specific error.

func (*IOError) Error

func (e *IOError) Error() string

type Opts

type Opts struct {
	InterruptPin gpio.PinIn
	Gain         Gain
}

Opts holds the configuration options.

type Spectrum

type Spectrum struct {
	Bands             []Band
	SensorTemperature physic.Temperature
	Gain              Gain
	LedDrive          physic.ElectricCurrent
	Integration       time.Duration
}

Spectrum is the reading from the sensor including the actual sensor state for the readings.

func (Spectrum) String

func (s Spectrum) String() string

Jump to

Keyboard shortcuts

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