Documentation ¶
Index ¶
- Constants
- func ScaleMinMax(fs Scale) (min, max float64)
- func ScaleRange(fs Scale) float64
- type ADC
- func (adc *ADC) Close() error
- func (adc *ADC) ComparatorLatching() (ComparatorLatching, error)
- func (adc *ADC) ComparatorMode() (ComparatorMode, error)
- func (adc *ADC) ComparatorPolarity() (ComparatorPolarity, error)
- func (adc *ADC) ComparatorQueue() (ComparatorQueue, error)
- func (adc *ADC) Config() (uint16, error)
- func (adc *ADC) DataRate() (DataRate, error)
- func (adc *ADC) Mode() (Mode, error)
- func (adc *ADC) Read(buf []byte) error
- func (adc *ADC) ReadAIN(input AIN) (uint16, error)
- func (adc *ADC) ReadReg(reg byte, buf []byte) error
- func (adc *ADC) ReadRegUint16(reg byte) (uint16, error)
- func (adc *ADC) ReadVolts(input AIN) (float64, error)
- func (adc *ADC) Scale() (Scale, error)
- func (adc *ADC) SetComparatorLatching(cl ComparatorLatching) error
- func (adc *ADC) SetComparatorMode(cm ComparatorMode) error
- func (adc *ADC) SetComparatorPolarity(cp ComparatorPolarity) error
- func (adc *ADC) SetComparatorQueue(cq ComparatorQueue) error
- func (adc *ADC) SetDataRate(dr DataRate) error
- func (adc *ADC) SetMode(m Mode) error
- func (adc *ADC) SetScale(fs Scale) error
- func (adc *ADC) Status() (Status, error)
- func (adc *ADC) Write(buf []byte) error
- func (adc *ADC) WriteConfig(cfg uint16) error
- func (adc *ADC) WriteReg(reg byte, data interface{}) error
- type AIN
- type ComparatorLatching
- type ComparatorMode
- type ComparatorPolarity
- type ComparatorQueue
- type DataRate
- type I2CAddress
- type Mode
- type Scale
- type Status
Constants ¶
const ( Addr48 I2CAddress = 0x48 Addr49 = 0x49 Addr4A = 0x4A Addr4B = 0x4B )
const ( // ConversionReg is the address of the conversion register. ConversionReg byte = iota // ConfigReg is the address of the config register. ConfigReg // LoThresReg is the address of the Lo_thresh register. LoThreshReg // HiThreshReg is the address of the Hi_thresh register. HiThreshReg )
const ( Status_LSB uint8 = 15 Status_Mask uint16 = uint16(1 << Status_LSB) )
const ( // Busy means a conversion is currently being performed. Busy = iota << Status_LSB // Idle means a conversion is not currently being performed. Idle )
const ( AIN_LSB uint8 = 12 AIN_Mask uint16 = uint16(7 << AIN_LSB) )
const ( Scale_LSB uint8 = 9 Scale_Mask uint16 = uint16(7 << Scale_LSB) )
const ( Mode_LSB uint8 = 8 Mode_Mask uint16 = uint16(1 << Mode_LSB) )
const ( DataRate_LSB uint8 = 5 DataRate_Mask uint16 = uint16(7 << DataRate_LSB) )
const ( ComparatorMode_LSB uint8 = 4 ComparatorMode_Mask uint16 = uint16(1 << ComparatorMode_LSB) )
const ( ComparatorPolarity_LSB uint8 = 3 ComparatorPolarity_Mask uint16 = uint16(1 << ComparatorPolarity_LSB) )
const ( ComparatorLatching_LSB uint8 = 2 ComparatorLatching_Mask uint16 = uint16(1 << ComparatorLatching_LSB) )
const ( ComparatorQueue_LSB uint8 = 0 ComparatorQueue_Mask uint16 = uint16(3 << ComparatorQueue_LSB) )
const DefaultConfig = uint16(0x8583)
DefaultConfig is the configuration the device boots with.
const Resolution = 1 << 16
Resolution is the resolution of the ADC.
Variables ¶
This section is empty.
Functions ¶
func ScaleMinMax ¶
ScaleMinMax returns the min and max voltages for the given full scale value.
func ScaleRange ¶
ScaleRange returns the difference between max and min for the full scale value.
Types ¶
type ADC ¶
type ADC struct {
// contains filtered or unexported fields
}
ADC represents an ADS1113, ADS1114, or ADS1115 analog to digital converter.
func Open ¶
func Open(dev string, addr I2CAddress) (*ADC, error)
Open returns a new ADC initialized and ready for use. dev is the I2C bus device, e.g., /dev/i2c-1
func (*ADC) ComparatorLatching ¶
func (adc *ADC) ComparatorLatching() (ComparatorLatching, error)
ComparatorLatching returns the comparator latching.
func (*ADC) ComparatorMode ¶
func (adc *ADC) ComparatorMode() (ComparatorMode, error)
ComparatorMode returns the comparator mode.
func (*ADC) ComparatorPolarity ¶
func (adc *ADC) ComparatorPolarity() (ComparatorPolarity, error)
ComparatorPolarity returns the comparator polarity.
func (*ADC) ComparatorQueue ¶
func (adc *ADC) ComparatorQueue() (ComparatorQueue, error)
ComparatorQueue returns the comparator queuing mode.
func (*ADC) ReadRegUint16 ¶
ReadRegUint16 reads a register and returns the result as a uint16.
func (*ADC) SetComparatorLatching ¶
func (adc *ADC) SetComparatorLatching(cl ComparatorLatching) error
SetComparatorLatching sets the comparator latching.
func (*ADC) SetComparatorMode ¶
func (adc *ADC) SetComparatorMode(cm ComparatorMode) error
SetComparatorMode sets the comparator mode to Traditional or Window.
func (*ADC) SetComparatorPolarity ¶
func (adc *ADC) SetComparatorPolarity(cp ComparatorPolarity) error
SetComparatorPolarity sets the comparator polarity.
func (*ADC) SetComparatorQueue ¶
func (adc *ADC) SetComparatorQueue(cq ComparatorQueue) error
SetComparatorQueue sets the comparator queuing mode.
func (*ADC) SetDataRate ¶
SetDataRate sets the number of samples per second.
func (*ADC) Status ¶
Status returns the current status. A Busy status indicates that it is currently performing a conversion and Idle means it's not.
func (*ADC) WriteConfig ¶
WriteConfig writes a new config to the device.
type AIN ¶
type AIN uint16
const ( // AIN_0_1 is used to select AIN0 (pos) & AIN1 (neg) inputs (default). AIN_0_1 AIN = iota << AIN_LSB // AIN_0_3 is used to select AIN0 (pos) & AIN3 (neg) inputs. AIN_0_3 // AIN_1_3 is used to select AIN1 (pos) & AIN3 (neg) inputs. AIN_1_3 // AIN_2_3 is used to select AIN2 (pos) & AIN3 (neg) inputs. AIN_2_3 // AIN_0_GND is used to select AIN0 (pos) & GND (neg) inputs. AIN_0_GND // AIN_1_GND is used to select AIN1 (pos) & GND (neg) inputs. AIN_1_GND // AIN_2_GND is used to select AIN2 (pos) & GND (neg) inputs. AIN_2_GND // AIN_3_GND is used to select AIN3 (pos) & GND (neg) inputs. AIN_3_GND )
type ComparatorLatching ¶
type ComparatorLatching uint16
const ( // Off is used to set the comparator to non-latching (default). Off ComparatorLatching = iota << ComparatorLatching_LSB //On is used to set the comparator to latching. On )
type ComparatorMode ¶
type ComparatorMode uint16
const ( // Traditional is used to set traditional comparator with histeresis (default). Traditional ComparatorMode = iota << ComparatorMode_LSB // Window is used to set window comparator mode. Window )
type ComparatorPolarity ¶
type ComparatorPolarity uint16
const ( // ActiveLow is used to set polarity of ALERT/RDY pin to active low (default). ActiveLow ComparatorPolarity = iota << ComparatorPolarity_LSB // ActiveHigh is used to set polarity of ALERT/RDY pin to active high. ActiveHigh )
type ComparatorQueue ¶
type ComparatorQueue uint16
const ( // CQ_AfterOne is used to set number of successive conversions exceeding upper or lower // thresholds before asserting ALERT/RDY pin. AfterOne ComparatorQueue = iota << ComparatorQueue_LSB AfterTwo AfterFour Disable // (default) )
type DataRate ¶
type DataRate uint16
const ( // DR_8SPS is used to set the data rate to 8 samples per second. DR_8SPS DataRate = iota << DataRate_LSB // DR_16SPS is used to set the data rate to 16 samples per second. DR_16SPS // DR_32SPS is used to set the data rate to 32 samples per second. DR_32SPS // DR_64SPS is used to set the data rate to 64 samples per second. DR_64SPS // DR_128SPS is used to set the data rate to 128 samples per second (default). DR_128SPS // DR_250SPS is used to set the data rate to 250 samples per second. DR_250SPS // DR_475SPS is used to set the data rate to 475 samples per second. DR_475SPS // DR_860SPS is used to set the data rate to 860 samples per second. DR_860SPS )
type I2CAddress ¶
type I2CAddress uint8
I2CAddress represents one of the possible I2C bus addresses.
type Scale ¶
type Scale uint16
const ( // Scale_6_144V is used to set full scale range to +/- 6.144V. Scale_6_144V Scale = iota << Scale_LSB // Scale_4_096V is used to set full scale range to +/- 4.096V. Scale_4_096V // Scale_2_048V is used to set full scale range to +/- 2.048V (default). Scale_2_048V // Scale_1_024V is used to set full scale range to +/- 1.024V. Scale_1_024V // Scale_0_512V is used to set full scale range to +/- 0.512V. Scale_0_512V // Scale_0_256V is used to set full scale range to +/- 0.256V. Scale_0_256V )