PU2CLR MCP23008 Arduino Library  1.0.7
Arduino Library for MCP23008 Device - By Ricardo Lima Caratti
MCP23008 basic functions

Functions

bool MCP::isBitValueHigh (uint8_t byteValue, uint8_t bitNumber)
 Checks if the Bit Value of a given bit position is high. More...
 
void MCP::setClock (long freq)
 Sets I2C bus to a given frequency. More...
 
uint8_t MCP::lookForDevice ()
 Look for MCP23008 device I2C Address. More...
 
void MCP::reset ()
 Resets the MCP23008. More...
 
void MCP::setup (uint8_t i2c=0x20, uint8_t io=GPIO_OUTPUT, int reset_pint=-1, long i2c_freq=100000)
 Starts the MCP23008. More...
 

Detailed Description

Function Documentation

◆ isBitValueHigh()

bool MCP::isBitValueHigh ( uint8_t  byteValue,
uint8_t  bitNumber 
)
inline

Checks if the Bit Value of a given bit position is high.

This funcion is useful to extract a bit value (0 or 1) from a given MCP23008 register

Parameters
byteValuebyte or register value
bitNumberbit offset (number / possition from 0 to 7)
Returns
true if the bit position is 1 (high)

◆ setClock()

void MCP::setClock ( long  freq)
inline

Sets I2C bus to a given frequency.

100000 = 100KHz; 400000 = 400KHz etc

Plese check the property I2C bus frequency/speed of your board

Referenced by MCP::setup().

◆ lookForDevice()

uint8_t MCP::lookForDevice ( )

Look for MCP23008 device I2C Address.

This method will look for a valid MCP23008 device adress between 0x20 and 0x27

Returns
uint8_t the I2C address of the first MCP23008 device connect in the I2C bus

◆ reset()

void MCP::reset ( )

Resets the MCP23008.

this method can be used if you want to control the reset of the MCP23008 device. You need to select the Arduino pin via setup method.

You can used the MCP23008 RESET pin connected to the Arduino RESET pin. In this case, you not need to use this function.

See also
setup()

References MCP::reset_pin.

Referenced by MCP::setup().

◆ setup()

void MCP::setup ( uint8_t  i2c = 0x20,
uint8_t  io = GPIO_OUTPUT,
int  reset_pin = -1,
long  i2c_bus_freq = 100000 
)

Starts the MCP23008.

Starts the MCP23008 and sets the default values.

Parameters
i2cI2C address (0x20 ~ 0x27) - default 0x20; ports input / output setup; Arduino reset pin; and I2C clock frequency
ioIf GPIO_OUTPUT (0), all GPIO PINS will configured to output If GPIO_INPUT (255), all GPIO PINS will configured to input
You also can use a bitmask to configure some pins for input and other pins for output.
reset_pinif you want to control the reset, select an Arduino pin to do that.
i2c_bus_freqset the I2C bus frequency/speed (default 100000 = 100KHz)

References MCP::reset(), MCP::reset_pin, and MCP::setClock().