0502-01 MCP23017 IO Expander

Example Projects > 0502 Generic I2C Communication > 0502-01 MCP23017 IO Expander

Using the MCP23017 I/O expander

This folder contains the source files for working with the GPIO pins of the MCP23017 16-bit I/O expander via I2C bus (e.g. on the Raspberry Pi or ALIX). The example is based on the REXLANG user-programmable function block of the REXYGEN System.

The GPIO port A is used for digital outputs. The GPIO port B is used for digital inputs with the internal pull-up resistors enabled.

Timing of the project

The algorithm runs each 200 milliseconds (0.2 s). See the EXEC function block,
tick x ntick0 = 0.1 x 2 = 0.2

Prerequisites

  • REXYGEN Runtime Core must be installed and running on the target device (Raspberry Pi).
  • I2C bus must be enabled and available (e.g. /dev/i2c-1).
  • The wiring must comply with the attached datasheet.

Running the example

  • The *exec.mdl file is the project main file.
  • Open it with REXYGEN Studio.
  • Specify the I2C bus by the p0 parameter of the REXLANG function block.
  • Compile and download it to the target device.
  • Switch to Watch mode and observe the algorithm.
  • Enable online monitoring of the CNB_GPA blocks (Target->Watch Selection) and the BDOCT_GPIOB block.
  • Toggle the CNB_GPA constants and observe the pins of the MCP23017 I/O expander.
  • Apply external voltage to GPIOB pins and observe the outputs of BDOCT_GPIOB block.

Documentation

Additional information

  • Raspberry Pi is a trademark of the Raspberry Pi Foundation.
  • Visit the REXYGEN webpage for more information about the example projects and developing advanced automation and control solutions using REXYGEN.