0502-02 MCP3422 ADC

Example Projects > 0502 Generic I2C Communication > 0502-02 MCP3422 ADC

Reading MCP3422 ADC data

This folder contains the source files for reading ADC data from the MCP3422 2-channel ADC via I2C bus, which is available e.g. on the Raspberry Pi minicomputer. The example is based on the REXLANG user-programmable function block of REXYGEN.

Data from only one channel are read for keeping the example clear. See the source code for details on changing the channel and resolution.

The measured data is recorded in the TRND block which allows displaying of the trends (graphs) in the Watch mode of REXYGEN Studio or in the REXYGEN Diagnostics diagnostic tool.

Timing of the project

The algorithm runs each 1000 milliseconds (1 s). See the EXEC function block,
tick x ntick0 = 0.5 x 2 = 1.0


  • 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 REXLANG block (Target->Watch Selection).
  • Apply external voltage to the ADC pins and observe the received data.


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.