Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from MichaelS11/input
Browse files Browse the repository at this point in the history
Added SetConfigInputMultiplexer
  • Loading branch information
MichaelS11 authored Oct 16, 2019
2 parents 4238d78 + 9a1c30d commit 9b714bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
16 changes: 12 additions & 4 deletions ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ func (ads *ADS) Close() error {
return busCloser.Close()
}

// SetConfigGain sets configGain
// SetConfigInputMultiplexer sets input multiplexer
func (ads *ADS) SetConfigInputMultiplexer(configInputMultiplexer ConfigInputMultiplexer) {
ads.configInputMultiplexer = uint16(configInputMultiplexer)
binary.BigEndian.PutUint16(ads.config, configDefault|ads.configInputMultiplexer|ads.configGain|ads.configDataRate)
ads.write[1] = ads.config[0]
ads.write[2] = ads.config[1]
}

// SetConfigGain sets gain
func (ads *ADS) SetConfigGain(configGain ConfigGain) {
ads.configGain = uint16(configGain)
binary.BigEndian.PutUint16(ads.config, configDefault|ads.configGain|ads.configDataRate)
binary.BigEndian.PutUint16(ads.config, configDefault|ads.configInputMultiplexer|ads.configGain|ads.configDataRate)
ads.write[1] = ads.config[0]
ads.write[2] = ads.config[1]
}

// SetConfigDataRate sets configDataRate
// SetConfigDataRate sets data rate
func (ads *ADS) SetConfigDataRate(configDataRate ConfigDataRate) {
ads.configDataRate = uint16(configDataRate)
binary.BigEndian.PutUint16(ads.config, configDefault|ads.configGain|ads.configDataRate)
binary.BigEndian.PutUint16(ads.config, configDefault|ads.configInputMultiplexer|ads.configGain|ads.configDataRate)
ads.write[1] = ads.config[0]
ads.write[2] = ads.config[1]
}
Expand Down
44 changes: 28 additions & 16 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
// https://cdn-shop.adafruit.com/datasheets/ads1115.pdf

type (
// ConfigInputMultiplexer config input multiplexer
ConfigInputMultiplexer uint16
// ConfigGain config gain amplifier
ConfigGain uint16
// ConfigDataRate config data rate
Expand All @@ -19,14 +21,23 @@ const (
configOperationSingle uint16 = 0x8000 // 1 : Begin a single conversion (when in power-down mode)

// Bits [14:12] MUX[2:0]: Input multiplexer configuration (ADS1115 only)
configInputMultiplexerDifferential01 uint16 = 0x0000 // 000 : AINP = AIN0 and AINN = AIN1 (default)
configInputMultiplexerDifferential03 uint16 = 0x1000 // 001 : AINP = AIN0 and AINN = AIN3
configInputMultiplexerDifferential13 uint16 = 0x2000 // 010 : AINP = AIN1 and AINN = AIN3
configInputMultiplexerDifferential23 uint16 = 0x3000 // 011 : AINP = AIN2 and AINN = AIN3
configInputMultiplexerSingle0 uint16 = 0x4000 // 100 : AINP = AIN0 and AINN = GND
configInputMultiplexerSingle1 uint16 = 0x5000 // 101 : AINP = AIN1 and AINN = GND
configInputMultiplexerSingle2 uint16 = 0x6000 // 110 : AINP = AIN2 and AINN = GND
configInputMultiplexerSingle3 uint16 = 0x7000 // 111 : AINP = AIN3 and AINN = GND

// ConfigInputMultiplexerDifferential01 000 : AINP = AIN0 and AINN = AIN1 (default)
ConfigInputMultiplexerDifferential01 ConfigInputMultiplexer = 0x0000
// ConfigInputMultiplexerDifferential03 001 : AINP = AIN0 and AINN = AIN3
ConfigInputMultiplexerDifferential03 ConfigInputMultiplexer = 0x1000
// ConfigInputMultiplexerDifferential13 010 : AINP = AIN1 and AINN = AIN3
ConfigInputMultiplexerDifferential13 ConfigInputMultiplexer = 0x2000
// ConfigInputMultiplexerDifferential23 011 : AINP = AIN2 and AINN = AIN3
ConfigInputMultiplexerDifferential23 ConfigInputMultiplexer = 0x3000
// ConfigInputMultiplexerSingle0 100 : AINP = AIN0 and AINN = GND
ConfigInputMultiplexerSingle0 ConfigInputMultiplexer = 0x4000
// ConfigInputMultiplexerSingle1 101 : AINP = AIN1 and AINN = GND
ConfigInputMultiplexerSingle1 ConfigInputMultiplexer = 0x5000
// ConfigInputMultiplexerSingle2 110 : AINP = AIN2 and AINN = GND
ConfigInputMultiplexerSingle2 ConfigInputMultiplexer = 0x6000
// ConfigInputMultiplexerSingle3 111 : AINP = AIN3 and AINN = GND
ConfigInputMultiplexerSingle3 ConfigInputMultiplexer = 0x7000

// Bits [11:9] PGA[2:0]: Programmable gain amplifier configuration (ADS1114 and ADS1115 only)

Expand Down Expand Up @@ -89,19 +100,20 @@ const (
registerPointerConfig byte = 0x0001

// configDefault is the default config
configDefault = configOperationSingle | configInputMultiplexerSingle0 | // missing ConfigGain
configDefault = configOperationSingle | // missing ConfigInputMultiplexer and ConfigGain
configOperatingModeSingle | // missing ConfigDataRate
configComparatorModeTraditional | configComparatorPolarityLow | configLatchingComparatorOff | configComparatorQueueOff
)

// ADS struct to interface with the Analog-to-Digital Converter.
// Call NewADS to create a new one.
type ADS struct {
busCloser *i2c.BusCloser
dev *i2c.Dev
configGain uint16
configDataRate uint16
config []byte
write []byte
read []byte
busCloser *i2c.BusCloser
dev *i2c.Dev
configInputMultiplexer uint16
configGain uint16
configDataRate uint16
config []byte
write []byte
read []byte
}

0 comments on commit 9b714bd

Please sign in to comment.