Documentation ¶
Overview ¶
Package ads1x15 controls ADS1015/ADS1115 Analog-Digital Converters (ADC) via I²C interface.
Datasheet ¶
ADS1015: http://www.ti.com/product/ADS1015
ADS1115: http://www.ti.com/product/ADS1115
Example ¶
package main import ( "fmt" "log" "periph.io/x/periph/conn/i2c/i2creg" "periph.io/x/periph/conn/physic" "periph.io/x/periph/experimental/devices/ads1x15" "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 ADS1115 ADC. adc, err := ads1x15.NewADS1115(bus, &ads1x15.DefaultOpts) if err != nil { log.Fatalln(err) } // Obtain an analog pin from the ADC. pin, err := adc.PinForChannel(ads1x15.Channel0Minus3, 5*physic.Volt, 1*physic.Hertz, ads1x15.SaveEnergy) if err != nil { log.Fatalln(err) } defer pin.Halt() // Read values from ADC. fmt.Println("Single reading") reading, err := pin.Read() if err != nil { log.Fatalln(err) } fmt.Println(reading) // Read values continously from ADC. fmt.Println("Continuous reading") c := pin.ReadContinuous() for reading := range c { fmt.Println(reading) } }
Output:
Index ¶
Examples ¶
Constants ¶
const I2CAddr uint16 = 0x48
I2CAddr is the default I2C address for the ADS1x15 components.
Variables ¶
var DefaultOpts = Opts{ I2cAddress: I2CAddr, }
DefaultOpts are the recommended default options.
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel int
Channel is the analog reading to do. It can be either an absolute reading or a differential reading between two pins.
type ConversionQuality ¶
type ConversionQuality int
ConversionQuality represents a request for a compromise between energy saving versus conversion quality.
const ( // SaveEnergy optimizes the power consumption of the ADC, at the expense of // the quality by converting at the highest possible rate. SaveEnergy ConversionQuality = 0 // BestQuality will use the lowest suitable data rate to reduce the impact of // the noise on the reading. BestQuality ConversionQuality = 1 )
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is an handle to an ADS1015/ADS1115 ADC.
func NewADS1015 ¶
NewADS1015 creates a new driver for the ADS1015 (12-bit ADC).
func NewADS1115 ¶
NewADS1115 creates a new driver for the ADS1115 (16-bit ADC).
func (*Dev) PinForChannel ¶
func (d *Dev) PinForChannel(c Channel, maxVoltage physic.ElectricPotential, f physic.Frequency, q ConversionQuality) (PinADC, error)
PinForChannel returns an AnalogPin for the requested channel at the requested frequency.
The channel can either be an absolute reading or a differential one.