C library for the MCP 3008 ADCClick here to get the code
To use the
mcp3008.hlibrary, you need to get the
gpio.hGPIO 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
- Get the library and the required gpio.h files. Put them in the directory in which you are working.
Include the library with
To read the MCP 3008's value, use this function:
int mcp3008_value(int input, int clock, int in, int out, int cs)
inputis the number of the input you want to use. It must be between 0 and 7.
clockis the pin number of the clock pin of your MCP 3008.
inis the number of the pin that is connected to your MCP 3008's output pin
outis the number of the pin that is connected to your MCP 3008's input pin
csis the number of the pin that is connected to your MCP 3008's chip select pin
- Compile your program