public class PCF8591 extends I2CComponent implements ADC
Some specifications:
Address, control and data to and from the device are transfered serially via the two-line bidirectional I2C-bus.
! NOTE ! known bug when reading digital values from PCF8591 if analog output disabled ! (independent of this framework)
Datasheet: PCF8591
Each PCF8591 device in an I2C-bus system is activated by sending a valid address to the device. The address (8 bits) consists of a fixed part (4 bits), a programmable part (3 bits) and a read/write-bit (1 bit) which sets the direction of the following data transfer.
Example of use: PCF8591Example
Modifier and Type | Class and Description |
---|---|
static class |
PCF8591.AnalogueInputProgrammingMode
There exists 4 different modes to deal with the four analog inputs.
|
Modifier and Type | Field and Description |
---|---|
static byte |
ANALOGUE_OUTPUT_ENABLE_FLAG
Analog output active if bit at position 2 in control byte is 1.
|
static byte |
AUTO_INCREMENT_FLAG
If the auto-increment flag is set to 1, the channel number
is incremented automatically after each A/D conversion.
|
static PCF8591InputChannel |
CHANNEL_0
A/D channel 0.
|
static PCF8591InputChannel |
CHANNEL_1
A/D channel 1.
|
static PCF8591InputChannel |
CHANNEL_2
A/D channel 2.
|
static PCF8591InputChannel |
CHANNEL_3
A/D channel 3.
|
static int |
DEFAULT_PCF8591_ADDRESS
Default i2c PCF8591 address.
|
device, MAX_I2C_ADDRESS, MIN_I2C_ADDRESS
Constructor and Description |
---|
PCF8591()
Default constructor for a PCF8591 using the default i2c address of the component,
the four single ended analogue input programming mode, enabling the analog output and disabling the auto increment flag.
|
PCF8591(int i2cAddress,
PCF8591.AnalogueInputProgrammingMode mode,
boolean enableAnalogOutput,
boolean enableAutoIncrement)
Constructor for a PCF8591 using a specific i2c address, a specific analog input programming mode,
a specific boolean to enable/disable the analogue output of the PCF8591 and a specific value for the auto increment flag.
|
Modifier and Type | Method and Description |
---|---|
int |
analogToDigital(ADCChannel inputChannel)
Read a digital value from the ADC through I2C.
|
int |
analogToDigital(PCF8591InputChannel inputChannel)
Read a digital value from the PCF8591 through i2c.
|
void |
digitalToAnalog(int value)
Send a digital value to the PCF8591 through i2c.
|
java.lang.String |
toString() |
getDevice, getType, readSignedRegisterValue, readTwoSignedRegsiters, readTwoUnsignedRegisters, readUnsignedRegisterValue, writeUnsignedValueDirectlyToI2CDevice, writeUnsignedValueToRegister
public static final int DEFAULT_PCF8591_ADDRESS
public static final byte ANALOGUE_OUTPUT_ENABLE_FLAG
public static final byte AUTO_INCREMENT_FLAG
public static final PCF8591InputChannel CHANNEL_0
Note: the output of each channel depends on the mode selected for the analogue input progamming.
public static final PCF8591InputChannel CHANNEL_1
Note: the output of each channel depends on the mode selected for the analogue input progamming.
public static final PCF8591InputChannel CHANNEL_2
Note: the output of each channel depends on the mode selected for the analogue input progamming.
public static final PCF8591InputChannel CHANNEL_3
Note: the output of each channel depends on the mode selected for the analogue input progamming.
public PCF8591()
public PCF8591(int i2cAddress, PCF8591.AnalogueInputProgrammingMode mode, boolean enableAnalogOutput, boolean enableAutoIncrement)
i2cAddress
- the i2c address of the PCF8591.mode
- the selected analog input programming mode.enableAnalogOutput
- true to enable the analog output of the PCF8591 (/!\ pay attention to bug described in class header (PCF8591
)). False to disable.enableAutoIncrement
- true to enable the auto increment flag. False to disable.public int analogToDigital(ADCChannel inputChannel)
ADC
analogToDigital
in interface ADC
inputChannel
- the input channel on the ADC from which to read the data.public int analogToDigital(PCF8591InputChannel inputChannel)
Note:
[datasheet] The first byte transmitted in a read cycle contains the conversion result code of the previous read cycle. After a POR condition, the first byte read is 80h.
inputChannel
- the input channel on the PCF8591 from which to read the data.public void digitalToAnalog(int value)
This value will be converted in an analog signal by the PCF8591, and this signal will output on the AOUT pin.
Note: the led on the sunfounder PCF8591 custom board will shine accordingly to the analog output voltage (led won't light up below 125).
[datasheet - p.7] The third byte sent to a PCF8591 device is stored in the DAC data register and is converted to the corresponding analog voltage using the on-chip D/A converter.
[datasheet - p.5-7] protocol: for D/A conversion, after the addressing byte, send the control byte and then the data byte. Note: we use a buffer to send the two consecutive bytes ! (otherwise: bug)
value
- the data value to send on the analog output, in the 0..255 range.public java.lang.String toString()
toString
in class java.lang.Object