C library for the MCP 3008 ADC

Click here to get the code
To use the mcp3008.h library, you need to get the gpio.h GPIO library and copy it in the same directory. You also need a C compiler, like gcc.
You also need to export the GPIO pins to /sys/class/gpio/. Here is a script that does this.
Click here to get my GPIO starter package, which includes everything you need to use the mcp3008 C library.

How to use the MCP 3008 library

  1. Get the library and the required gpio.h files. Put them in the directory in which you are working.
  2. Include the library with #include "mcp3008.h".
  3. To read the MCP 3008's value, use this function:
    int mcp3008_value(int input, int clock, int in, int out, int cs)
    input is the number of the input you want to use. It must be between 0 and 7.
    clock is the pin number of the clock pin of your MCP 3008.
    in is the number of the pin that is connected to your MCP 3008's output pin
    out is the number of the pin that is connected to your MCP 3008's input pin
    cs is the number of the pin that is connected to your MCP 3008's chip select pin
  4. Compile your program
Here is a little example.