MCP3008 analog-to-digital converter chip (SPI), providing 8 channels to read analog sensors on the Raspberry Pi.
More...
#include <MCP3008.h>
|
| | MCP3008 (const int basePinNum, const int spiChannel, const float adcVoltage=3.3f) |
| | Builds an MCP3008 ADC bound to the given base pin number, SPI channel, and reference voltage. More...
|
| |
| virtual | ~MCP3008 () |
| | Destroys the ADC. More...
|
| |
| virtual void | TurnOn () override |
| | Initializes the MCP3008 for analog reads via wiringPi, reporting a warning through the AlertManager on failure. More...
|
| |
| virtual void | TurnOff () override |
| | No-op: the MCP3008 holds no resources that need releasing when turned off. More...
|
| |
| virtual void | ProcessRawValues () override |
| | No-op: the MCP3008 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 number, SPI channel, and ADC voltage to a string. More...
|
| |
| virtual int | ReadAnalogValue (int adcIndex=0) override |
| | Reads an analog value from the given channel over SPI (8 possible ADCs, 0 through 7). More...
|
| |
| 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...
|
| |
| | 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...
|
| |
|
| 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...
|
| |
| | 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...
|
| |
| 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...
|
| |
| 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...
|
| |
MCP3008 analog-to-digital converter chip (SPI), providing 8 channels to read analog sensors on the Raspberry Pi.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ MCP3008()
| RumPi::MCP3008::MCP3008 |
( |
const int |
basePinNum, |
|
|
const int |
spiChannel, |
|
|
const float |
adcVoltage = 3.3f |
|
) |
| |
Builds an MCP3008 ADC bound to the given base pin number, SPI channel, and reference voltage.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
MCP3008(const int basePinNum, const int spiChannel, const float adcVoltage=3.3f)
Builds an MCP3008 ADC bound to the given base pin number, SPI channel, and reference voltage.
Definition: MCP3008.cpp:20
- Parameters
-
| [in] | basePinNum | The wiringPi base pin number for the chip's channels. |
| [in] | spiChannel | The SPI channel the chip is wired to. |
| [in] | adcVoltage | The ADC reference voltage. |
◆ ~MCP3008()
| RumPi::MCP3008::~MCP3008 |
( |
| ) |
|
|
virtual |
Destroys the ADC.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
◆ ProcessRawValues()
| void RumPi::MCP3008::ProcessRawValues |
( |
| ) |
|
|
overridevirtual |
No-op: the MCP3008 reads its channels on demand in ReadAnalogValue, so there are no raw values to process.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
Implements RumPi::BaseComponent.
◆ ReadAnalogValue()
| int RumPi::MCP3008::ReadAnalogValue |
( |
int |
adcIndex = 0 | ) |
|
|
overridevirtual |
Reads an analog value from the given channel over SPI (8 possible ADCs, 0 through 7).
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
int value = adc.ReadAnalogValue(3);
- Parameters
-
| [in] | adcIndex | The ADC channel index (0 to 7). |
- Returns
- The analog reading, or -1 if the channel index is out of bounds.
Implements RumPi::IAnalogDigitalConverterComponent.
◆ ToString()
| std::string RumPi::MCP3008::ToString |
( |
| ) |
const |
|
overridevirtual |
Serializes the chip's base pin number, SPI channel, 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::MCP3008::TurnOff |
( |
| ) |
|
|
overridevirtual |
No-op: the MCP3008 holds no resources that need releasing when turned off.
- Author
- Eddie O'Hagan
- Date
- 8/13/2026
Implements RumPi::BaseComponent.
◆ TurnOn()
| void RumPi::MCP3008::TurnOn |
( |
| ) |
|
|
overridevirtual |
◆ myBasePinNum
| int RumPi::MCP3008::myBasePinNum |
|
private |
The wiringPi base pin number for the chip's channels.
◆ mySpiChannel
| int RumPi::MCP3008::mySpiChannel |
|
private |
The SPI channel the chip is wired to.
The documentation for this class was generated from the following files: