public class PCF8591 extends AbstractDeviceFactory implements AnalogInputDeviceFactoryInterface, AnalogOutputDeviceFactoryInterface
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:
From my experiments, the inputs / jumpers are configured as follows:
Removing a jumper allows an input channel to be fed from one of the external pins, labelled accordingly.
Modifier and Type | Class and Description |
---|---|
static class |
PCF8591.InputMode |
static class |
PCF8591.PCF8591BoardPinInfo |
closed, deviceStates
Constructor and Description |
---|
PCF8591() |
PCF8591(int controller) |
PCF8591(int controller,
int address,
PCF8591.InputMode inputMode,
boolean outputEnabled,
float vRef) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
AnalogInputDeviceInterface |
createAnalogInputDevice(String key,
PinInfo pinInfo) |
AnalogOutputDeviceInterface |
createAnalogOutputDevice(String key,
PinInfo pinInfo) |
BoardPinInfo |
getBoardPinInfo() |
String |
getName() |
int |
getNumPins() |
float |
getValue(int adcPin)
Read the analog value in the range 0..1
|
float |
getVRef() |
void |
setOutputEnabledFlag(boolean outputEnabled) |
void |
setValue(int dacPin,
float value)
Set the analog output value.
|
createI2CKey, createPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, getDevice, isClosed, isDeviceOpened
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
provisionAnalogInputDevice
provisionAnalogOutputDevice
createI2CKey, createPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, getDevice, isClosed, isDeviceOpened
public PCF8591()
public PCF8591(int controller)
public PCF8591(int controller, int address, PCF8591.InputMode inputMode, boolean outputEnabled, float vRef)
public float getVRef()
getVRef
in interface AnalogInputDeviceFactoryInterface
public BoardPinInfo getBoardPinInfo()
getBoardPinInfo
in interface DeviceFactoryInterface
public void close() throws RuntimeIOException
close
in interface DeviceFactoryInterface
close
in interface Closeable
close
in interface AutoCloseable
close
in class AbstractDeviceFactory
RuntimeIOException
public String getName()
getName
in interface DeviceFactoryInterface
public AnalogInputDeviceInterface createAnalogInputDevice(String key, PinInfo pinInfo) throws RuntimeIOException
createAnalogInputDevice
in interface AnalogInputDeviceFactoryInterface
RuntimeIOException
public AnalogOutputDeviceInterface createAnalogOutputDevice(String key, PinInfo pinInfo) throws RuntimeIOException
createAnalogOutputDevice
in interface AnalogOutputDeviceFactoryInterface
RuntimeIOException
public float getValue(int adcPin) throws RuntimeIOException
adcPin
- Pin on the MCP deviceRuntimeIOException
- if an I/O error occurspublic void setValue(int dacPin, float value) throws RuntimeIOException
dacPin
- The analog output channel.value
- Analogue output value (0..1).RuntimeIOException
- if an I/O error occurspublic int getNumPins()
public void setOutputEnabledFlag(boolean outputEnabled)
Copyright © 2016–2018 mattjlewis. All rights reserved.