java.lang.Object
com.diozero.internal.spi.AbstractDeviceFactory
com.diozero.devices.PCF8591
- All Implemented Interfaces:
DeviceInterface
,AnalogInputDeviceFactoryInterface
,AnalogOutputDeviceFactoryInterface
,DeviceFactoryInterface
,AutoCloseable
public class PCF8591
extends AbstractDeviceFactory
implements AnalogInputDeviceFactoryInterface, AnalogOutputDeviceFactoryInterface, DeviceInterface
Analog to Digital Converter. 4 analog in / 1 analog out.
Datasheet: http://www.nxp.com/documents/data_sheet/PCF8591.pdf.
Note the raspoid driver states there is a known bug when reading digital values from PCF8591 if analog output is disabled.
Instructions:
The jumpers control whether analog input channels of the IC are connected to the analog
sources:
- Jumper P4 for AIN1: The temperature sensed by the R6 thermister is provided to the ADC.
- Jumper P5 to AIN0: The R7 photocell voltage (resistance drop) is provided to the DAC.
- Jumper P6 to AIN3: The single turn 10K ohm trimpot voltage (resistance drop ? brighter light, lower resistance).
From my experiments, the inputs / jumpers are configured as follows:
- AIN0: trimpot (P6)
- AIN1: LDR (P5)
- AIN2: ?temp? (P4)
- AIN3: AIN3
Removing a jumper allows an input channel to be fed from one of the external pins, labelled accordingly.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static class
-
Field Summary
Fields inherited from class com.diozero.internal.spi.AbstractDeviceFactory
closed, deviceStates
-
Constructor Summary
ConstructorDescriptionPCF8591()
PCF8591
(int controller) PCF8591
(int controller, int address, PCF8591.InputMode inputMode, boolean outputEnabled, float vRef) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this device factory including all devices that have been provisioned by it.createAnalogInputDevice
(String key, PinInfo pinInfo) createAnalogOutputDevice
(String key, PinInfo pinInfo, float initialValue) Get information about pins that can be provisioned by this device factory.getName()
Get the name of this device factoryint
float
getValue
(int adcPin) Read the analog value in the range 0..1void
setOutputEnabledFlag
(boolean outputEnabled) void
setValue
(int dacPin, float value) Set the analog output value.Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.internal.spi.AnalogInputDeviceFactoryInterface
provisionAnalogInputDevice
Methods inherited from interface com.diozero.internal.spi.AnalogOutputDeviceFactoryInterface
provisionAnalogOutputDevice
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, registerDevice, registerPinDevice, reopen, start
-
Constructor Details
-
PCF8591
public PCF8591() -
PCF8591
public PCF8591(int controller) -
PCF8591
public PCF8591(int controller, int address, PCF8591.InputMode inputMode, boolean outputEnabled, float vRef)
-
-
Method Details
-
getBoardPinInfo
Description copied from interface:DeviceFactoryInterface
Get information about pins that can be provisioned by this device factory.- Specified by:
getBoardPinInfo
in interfaceDeviceFactoryInterface
- Returns:
- board pin info instance for this device factory
-
close
Description copied from interface:DeviceFactoryInterface
Close this device factory including all devices that have been provisioned by it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
- Specified by:
close
in interfaceDeviceInterface
- Overrides:
close
in classAbstractDeviceFactory
- Throws:
RuntimeIOException
-
getName
Description copied from interface:DeviceFactoryInterface
Get the name of this device factory- Specified by:
getName
in interfaceDeviceFactoryInterface
- Returns:
- the name of this device factory
-
createAnalogInputDevice
public AnalogInputDeviceInterface createAnalogInputDevice(String key, PinInfo pinInfo) throws RuntimeIOException - Specified by:
createAnalogInputDevice
in interfaceAnalogInputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createAnalogOutputDevice
public AnalogOutputDeviceInterface createAnalogOutputDevice(String key, PinInfo pinInfo, float initialValue) throws RuntimeIOException - Specified by:
createAnalogOutputDevice
in interfaceAnalogOutputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
getValue
Read the analog value in the range 0..1- Parameters:
adcPin
- Pin on the MCP device- Returns:
- The unscaled value (0..1)
- Throws:
RuntimeIOException
- if an I/O error occurs
-
setValue
Set the analog output value.- Parameters:
dacPin
- The analog output channel.value
- Analogue output value (0..1).- Throws:
RuntimeIOException
- if an I/O error occurs
-
getNumPins
public int getNumPins() -
setOutputEnabledFlag
public void setOutputEnabledFlag(boolean outputEnabled)
-