I am using wiringPi and C. I have a flame sensor and a MCP3004 ADC. Here is the program that I wrote, but I can't figure out why it won't read the analog values from the flame sensor.
#include <wiringPi.h>
#include <mcp3004.h>
#include <stdio.h>
#include <stdlib.h>
#define BASE 200
#define SPI_CHAN 0
int main(void) {
int channel;
int x;
if (wiringPiSetup () == -1)
exit(1);
mcp3004Setup(BASE, SPI_CHAN);
for (channel = 0; channel<8; ++channel) {
x=analogRead(BASE+channel);
printf("%d\n",x);
delay(1000);
}
return 0;
}
My program runs but it just outputs 0s. The wiring is correct and the sensors and MCP3004 work fine, I tested it with a python program and it gets the job done.
So the only problem is in my C code.
mcp3004Setup()
will return false on error and true on success, so perform a check there... for example:if ! mcp3004Setup(...){exit(1);}
– stevieb May 17 '17 at 12:30