A simple 4-channel, 8-bit ADC and single-channel 8-bit DAC both integrated into one chip.
More...
#include <pcf8591.h>
|
enum | ADCChannel {
CHANNEL_0,
CHANNEL_1,
CHANNEL_2,
CHANNEL_3,
CHANNELS
} |
|
enum | ADCAutoIncrement {
AUTO_INC_OFF,
AUTO_INC_ON = 0x04
} |
|
enum | ReadMode {
AllSingleEnded,
ThreeDifferential = 0x10,
SingleAndDifferential = 0x20,
TwoDifferential = 0x30
} |
|
|
| PCF8591 (const uint8_t deviceAddress=DEFAULT_DEVICE_ADDRESS, const I2C *i2cBus=&pwI2c) |
| Constructor. More...
|
|
bool | ping () const |
| Ensure the device is responding on the I2C bus. More...
|
|
uint8_t | read_channel (const ADCChannel channel) |
| Read the ADC value from a given channel. More...
|
|
bool | read_next (uint8_t *data) const |
| Retrieve the next ADC value for the previously set channel. More...
|
|
bool | read_multi (uint8_t data[], const size_t size) const |
| Get multiple sequential readings from the same channel. More...
|
|
bool | set_channel (const ADCChannel channel) |
| Use the given channel for subsequent queries. More...
|
|
bool | set_auto_increment (const bool autoIncrement) |
| When enabled, auto increment will change to the next ADC channel with every query. This is normally off. More...
|
|
bool | set_read_mode (const ReadMode mode) |
| Switch between the different modes for the ADC. More...
|
|
bool | enable_dac () |
| Begin outputting the current value out the DAC line. More...
|
|
bool | disable_dac () |
| Turn off the DAC. More...
|
|
bool | write (const uint8_t dacValue) |
| Set the current value for the DAC. More...
|
|
bool | write_multi (const uint8_t dacValues[], const size_t size) |
| Write a series of values to the DAC sequentially. More...
|
|
|
static const uint8_t | DEFAULT_DEVICE_ADDRESS = 0x90 |
|
static const uint8_t | DAC_ENABLE = BIT_6 |
|
static const uint8_t | CHANNEL_BITS = BIT_1 | BIT_0 |
|
A simple 4-channel, 8-bit ADC and single-channel 8-bit DAC both integrated into one chip.
- Examples:
- PCF8591_Demo.cpp.
Definition at line 36 of file pcf8591.h.
PropWare::PCF8591::PCF8591 |
( |
const uint8_t |
deviceAddress = DEFAULT_DEVICE_ADDRESS , |
|
|
const I2C * |
i2cBus = &pwI2c |
|
) |
| |
Constructor.
- Parameters
-
[in] | deviceAddress | The PCF8591 supports variable different device addresses, which can be set here; The default address should satisfy most use cases |
[in] | *i2cBus | HUB memory address (as opposed to I2C address!) of the I2C instance that should be used for communication; Usually the default bus will be satisfactory |
Definition at line 71 of file pcf8591.h.
bool PropWare::PCF8591::disable_dac |
( |
| ) |
|
Turn off the DAC.
- Returns
- True if successful, false otherwise
Definition at line 184 of file pcf8591.h.
bool PropWare::PCF8591::enable_dac |
( |
| ) |
|
Begin outputting the current value out the DAC line.
- Returns
- True if successful, false otherwise
Definition at line 174 of file pcf8591.h.
bool PropWare::PCF8591::ping |
( |
| ) |
const |
Ensure the device is responding on the I2C bus.
- Returns
- True if device responded, false otherwise
- Examples:
- PCF8591_Demo.cpp.
Definition at line 82 of file pcf8591.h.
uint8_t PropWare::PCF8591::read_channel |
( |
const ADCChannel |
channel | ) |
|
Read the ADC value from a given channel.
- Parameters
-
[in] | channel | The channel to be read |
- Returns
- a value between 0 and 255 representing the analog voltage
- Examples:
- PCF8591_Demo.cpp.
Definition at line 93 of file pcf8591.h.
bool PropWare::PCF8591::read_multi |
( |
uint8_t |
data[], |
|
|
const size_t |
size |
|
) |
| const |
Get multiple sequential readings from the same channel.
- Parameters
-
[out] | data[] | Array where readings can be stored |
[in] | size | Length of the array and number readings that should be retrieved |
- Returns
- True if successfully, false if any errors occurred
Definition at line 123 of file pcf8591.h.
bool PropWare::PCF8591::read_next |
( |
uint8_t * |
data | ) |
const |
Retrieve the next ADC value for the previously set channel.
If you need sequential readings from the same channel, this method will more efficiently grab readings after the first versus multiple calls to PropWare::PCF8591::read_channel
.
- Parameters
-
[out] | *data | Address where the ADC result will be stored |
- Returns
- True if successful, false otherwise
Definition at line 111 of file pcf8591.h.
bool PropWare::PCF8591::set_auto_increment |
( |
const bool |
autoIncrement | ) |
|
When enabled, auto increment will change to the next ADC channel with every query. This is normally off.
- Parameters
-
[in] | autoIncrement | True to enable, false to disable |
- Returns
- True if successfully set, false otherwise
Definition at line 148 of file pcf8591.h.
bool PropWare::PCF8591::set_channel |
( |
const ADCChannel |
channel | ) |
|
Use the given channel for subsequent queries.
- Parameters
-
[in] | channel | Channel number that should be used |
- Returns
- True if successfully set, false otherwise
Definition at line 134 of file pcf8591.h.
bool PropWare::PCF8591::set_read_mode |
( |
const ReadMode |
mode | ) |
|
Switch between the different modes for the ADC.
- Parameters
-
[in] | mode | Switch between single channel (default) and various differential modes |
- Returns
- True if successfully set, false otherwise
Definition at line 163 of file pcf8591.h.
bool PropWare::PCF8591::write |
( |
const uint8_t |
dacValue | ) |
|
Set the current value for the DAC.
- Parameters
-
[in] | dacValue | Digital value which will be converted to an analog voltage |
- Returns
- True if successful, false otherwise
Definition at line 196 of file pcf8591.h.
bool PropWare::PCF8591::write_multi |
( |
const uint8_t |
dacValues[], |
|
|
const size_t |
size |
|
) |
| |
Write a series of values to the DAC sequentially.
- Parameters
-
[in] | dacValues | Array of values that should be sent out the DAC line |
[in] | size | Number of values in the array |
- Returns
- True if successful, false otherwise
Definition at line 209 of file pcf8591.h.
The documentation for this class was generated from the following file: