RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
RumPi::PCF8591 Class Reference

PCF8591 analog-to-digital converter chip (I2C), used to read analog sensors on the Raspberry Pi. More...

#include <PCF8591.h>

Inheritance diagram for RumPi::PCF8591:
[legend]
Collaboration diagram for RumPi::PCF8591:
[legend]

Public Member Functions

 PCF8591 (unsigned int pcfBasePinNumber, int pcfI2cAddress, float adcVoltage=3.3f)
 Builds a PCF8591 ADC bound to the given base pin, I2C address, and reference voltage. More...
 
virtual ~PCF8591 ()
 Destroys the ADC, turning it off first. More...
 
virtual void TurnOn () override
 Initializes the PCF8591 for analog reads via wiringPi, reporting success or failure through the AlertManager. More...
 
virtual void TurnOff () override
 No-op: the PCF8591 holds no resources that need releasing when turned off. More...
 
virtual void ProcessRawValues () override
 No-op: the PCF8591 reads its channels on demand in ReadAnalogValue, so there are no raw values to process. More...
 
virtual std::string ToString () const override
 Serializes the chip's base pin (with its channel range) and ADC voltage to a string. More...
 
virtual int ReadAnalogValue (int adcIndex=0) override
 Reads a fresh analog value from the given ADC channel, performing a dummy read and settle delay first. More...
 
unsigned int GetPCFBasePinNumber () const
 Gets the wiringPi base pin; the chip's four ADC channels are read as base+0..base+3. More...
 
int GetPCFI2CAddress () const
 Gets the chip's I2C address. More...
 
- Public Member Functions inherited from RumPi::IAnalogDigitalConverterComponent
virtual ~IAnalogDigitalConverterComponent ()=0
 Pure virtual destructor, making this an abstract interface. More...
 
virtual int ReadAnalogValue (int adcIndex=0)=0
 Reads an analog value from the given channel. More...
 
float GetADCVoltage () const
 Gets the ADC's reference voltage. More...
 
int GetMaxRawValue () const
 Gets the ADC's full-scale raw count (e.g. More...
 
- Public Member Functions inherited from RumPi::BaseComponent
 BaseComponent ()
 Builds a base component with an unknown type and an empty name. More...
 
virtual ~BaseComponent ()
 Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More...
 
virtual void TurnOn ()=0
 Turns the component on (e.g. More...
 
virtual void TurnOff ()=0
 Turns the component off. More...
 
virtual std::string ToString () const =0
 Serializes the component's current readings to a string (usually JSON). More...
 
virtual void ProcessRawValues ()=0
 Reads and processes the component's latest raw values (called once per poll). More...
 
virtual EComponentType GetComponentType () const
 Gets the component's type. More...
 
const std::string & GetName () const
 Gets the component's unique per-instance name. More...
 
void SetName (const std::string &name)
 Sets the component's unique per-instance name. More...
 

Private Attributes

unsigned int myPCFBasePinNumber
 The wiringPi base pin; pcf8591Setup maps the four ADC channels to base+0..base+3. More...
 
int myPCFI2CAddress
 The chip's I2C address. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from RumPi::BaseComponent
static std::string ComponentTypeToString (const EComponentType theComponentTypeToConvert)
 Maps an EComponentType to its string name. More...
 
static EComponentType StringToComponentType (const std::string &theComponentTypeName)
 Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More...
 
- Protected Member Functions inherited from RumPi::IAnalogDigitalConverterComponent
 IAnalogDigitalConverterComponent ()
 Initializes the reference voltage and full-scale count to safe 10-bit defaults; concrete ADCs overwrite both in their own constructor, so a subclass that forgets to set them still yields sane (non-garbage) conversions rather than silently wrong volts. More...
 
- Protected Attributes inherited from RumPi::IAnalogDigitalConverterComponent
float myADCVoltage
 The ADC's reference voltage, used to convert raw readings to volts. More...
 
int myMaxRawValue
 The ADC's full-scale raw count (255 for an 8-bit chip, 1023 for a 10-bit chip). More...
 
- Protected Attributes inherited from RumPi::BaseComponent
EComponentType myComponentType
 The kind of component this is (set by each concrete subclass). More...
 
std::string myName
 A unique per-instance name, assigned when the component is added to the manager. More...
 

Detailed Description

PCF8591 analog-to-digital converter chip (I2C), used to read analog sensors on the Raspberry Pi.

Author
Eddie O'Hagan
Date
8/13/2026

Constructor & Destructor Documentation

◆ PCF8591()

RumPi::PCF8591::PCF8591 ( unsigned int  pcfBasePinNumber,
int  pcfI2CAddress,
float  adcVoltage = 3.3f 
)

Builds a PCF8591 ADC bound to the given base pin, I2C address, and reference voltage.

pcf8591Setup maps the chip's four ADC channels to consecutive wiringPi pins base+0..base+3, so only the base pin is stored.

Author
Eddie O'Hagan
Date
8/13/2026
PCF8591 adc(120, 0x48);
PCF8591(unsigned int pcfBasePinNumber, int pcfI2cAddress, float adcVoltage=3.3f)
Builds a PCF8591 ADC bound to the given base pin, I2C address, and reference voltage.
Definition: PCF8591.cpp:21
Parameters
[in]pcfBasePinNumberThe wiringPi base pin; channels are read as base+0..base+3.
[in]pcfI2CAddressThe chip's I2C address.
[in]adcVoltageThe ADC reference voltage.

◆ ~PCF8591()

RumPi::PCF8591::~PCF8591 ( )
virtual

Destroys the ADC, turning it off first.

Author
Eddie O'Hagan
Date
8/13/2026
PCF8591* adc = new PCF8591(120, 0x48);
delete adc;

Member Function Documentation

◆ GetPCFBasePinNumber()

unsigned int RumPi::PCF8591::GetPCFBasePinNumber ( ) const

Gets the wiringPi base pin; the chip's four ADC channels are read as base+0..base+3.

Author
Eddie O'Hagan
Date
8/13/2026
unsigned int basePin = adc.GetPCFBasePinNumber();
Returns
The chip's base pin.

◆ GetPCFI2CAddress()

int RumPi::PCF8591::GetPCFI2CAddress ( ) const

Gets the chip's I2C address.

Author
Eddie O'Hagan
Date
8/13/2026
int address = adc.GetPCFI2CAddress();
Returns
The chip's I2C address.

◆ ProcessRawValues()

void RumPi::PCF8591::ProcessRawValues ( )
overridevirtual

No-op: the PCF8591 reads its channels on demand in ReadAnalogValue, so there are no raw values to process.

Author
Eddie O'Hagan
Date
8/13/2026
adc.ProcessRawValues();

Implements RumPi::BaseComponent.

◆ ReadAnalogValue()

int RumPi::PCF8591::ReadAnalogValue ( int  adcIndex = 0)
overridevirtual

Reads a fresh analog value from the given ADC channel, performing a dummy read and settle delay first.

Author
Eddie O'Hagan
Date
8/13/2026
int value = adc.ReadAnalogValue(0);
Parameters
[in]adcIndexThe ADC channel index (0 to RUMPI_MAX_PCF8591_PINS - 1).
Returns
The analog reading, or -1 if the channel index is out of range.

Implements RumPi::IAnalogDigitalConverterComponent.

◆ ToString()

std::string RumPi::PCF8591::ToString ( ) const
overridevirtual

Serializes the chip's base pin (with its channel range) and ADC voltage to a string.

Author
Eddie O'Hagan
Date
8/13/2026
std::string data = adc.ToString();
Returns
A multi-line string describing the ADC.

Implements RumPi::BaseComponent.

◆ TurnOff()

void RumPi::PCF8591::TurnOff ( )
overridevirtual

No-op: the PCF8591 holds no resources that need releasing when turned off.

Author
Eddie O'Hagan
Date
8/13/2026
adc.TurnOff();

Implements RumPi::BaseComponent.

◆ TurnOn()

void RumPi::PCF8591::TurnOn ( )
overridevirtual

Initializes the PCF8591 for analog reads via wiringPi, reporting success or failure through the AlertManager.

Author
Eddie O'Hagan
Date
8/13/2026
adc.TurnOn();

Implements RumPi::BaseComponent.

Member Data Documentation

◆ myPCFBasePinNumber

unsigned int RumPi::PCF8591::myPCFBasePinNumber
private

The wiringPi base pin; pcf8591Setup maps the four ADC channels to base+0..base+3.

◆ myPCFI2CAddress

int RumPi::PCF8591::myPCFI2CAddress
private

The chip's I2C address.


The documentation for this class was generated from the following files: