Class MCP230XX

Inheritance Relationships

Derived Types

Class Documentation

class MCP230XX

Represents MCP230XX base class for all electronics.

Subclassed by iplo::MCP23008, iplo::MCP23017

Public Functions

inline MCP230XX(I2C &bus, std::uint8_t address)

Construct a new MCP230XX object.

Parameters:
  • bus – The I2C bus object.

  • address – Address of the IC.

virtual bool begin() = 0

Begin interaction with the device.

Selects device on the I2C bus with address given on creation. Checks if device is connected and initialize it. Disable address increment and set all pins as INPUTS with internal PULLUP.

Returns:

Status of the device initialization.

virtual bool isConnected() = 0

Checks if device is connected and program can read a byte from it.

Returns:

Identifier whether device is connected.

virtual bool pinMode(std::uint8_t pin, PinMode mode) = 0

Set pin mode.

Reads whole pin direction register and change only specified pin value.

See also

PinMode

Parameters:
  • pin – Number of device pin.

  • mode – Pin mode. One of the PinMode enum values.

Returns:

Status of the pin setting.

virtual bool digitalWrite(std::uint8_t pin, std::uint8_t value) = 0

Write HIGH or LOW value to the device pin.

Reads whole register and make copy of that value. Change value of the specified pin and write new value to the register.

Parameters:
  • pin – Device pin number.

  • value – New value of the device pin. Must be one of {0, 1}.

Returns:

Status of the transmission.

virtual std::uint8_t digitalRead(std::uint8_t pin) = 0

Read specified pin value.

Reads whole register and check for value on given pin.

Parameters:

pin – Device pin number.

Returns:

High (1) or Low (0) state of the pin. On failure returns MCP23008Status::INVALID_READ.

virtual bool setPolarity(std::uint8_t pin, bool reversed) = 0

Set pin polarity.

Reads whole register and change only specified pin value.

Parameters:
  • pin – Device pin number.

  • reversed – Identifier if polarity on given pin should be reversed.

Returns:

Status of the transmission.

virtual bool getPolarity(std::uint8_t pin, bool &reversed) = 0

Read pin polarity and save result to the reversed function parameter.

Parameters:
  • pin – Device pin number.

  • reversed – Variable to store result of the pin polarity.

Returns:

Status of the transmission.

virtual bool setPullUp(std::uint8_t pin, bool pullUp) = 0

Set pull up on specified device pin.

Parameters:
  • pin – Device pin number.

  • pullUp – Identifier whether to set up pull up on given pin.

Returns:

Status of the transmission.

virtual bool getPullUp(std::uint8_t pin, bool &pullUp) = 0

Get pull up value in specified pin.

Parameters:
  • pin – Device pin number.

  • pullUp – Variable to store result of pin pull up value.

Returns:

Status of the transmission.

virtual std::uint16_t readAll() = 0

Read all values on pins on the IC.

Returns:

Value of the registers.

int lastError()

Read last error and clear with OK status.

Returns:

Last error status.

Protected Functions

bool writeRegister(std::uint8_t reg, uint8_t value)

Write byte to the given device register.

Wrapper function around low level bus transmissions methods.

Parameters:
  • reg – Device register address.

  • value – Value to be written to the register.

Returns:

Status of the transmission.

std::uint8_t readRegister(uint8_t reg)

Read a single byte from the device register.

Parameters:

reg – Device register address.

Returns:

Read byte from the device.

Protected Attributes

std::uint8_t _address = {}

Address of the IC on the I2C bus.

std::uint8_t _error = {}

Last error occurred in communication with the IC.

I2C &_bus

I2C bus handle