0503-02 MCP3008 ADC

Example Projects > 0503 Generic SPI Communication > 0503-02 MCP3008 ADC

Reading MCP3008 ADC data via SPI bus

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

The 10-bit data obtained from the ADC chip are converted to voltage readings using the LIN function block. The y2 parameters of all LIN function blocks must be changed according to the supplied voltage reference, which can be achieved using the SETPR function blocks to control the parameters "over the air".

The time plot of the measured data can be displayed in the REXYGEN Diagnostics diagnostic program.

Timing of the project

The algorithm runs each 100 milliseconds (0.1 s). See the EXEC function block,
tick x ntick0 = 0.01 x 10 = 0.1


  • REXYGEN Runtime Core must be installed and running on the target device (Raspberry Pi).
  • SPI bus must be enabled and available (e.g. /dev/spidev0.0 on the Raspberry Pi)
  • 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 SPI 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.