Hi there,
Since my particular board only has one analog input, I am using the MCP3008 to convert the analog input of a Carbon Monoxide Sensor (MQ-7) to a digital input. I have triple checked all of the connections, reassigned values to CS_Pin and others in the code just to make sure, and I am still unable to read any values from the MQ-7. I either get a 0 (this is when the wiring is incorrect) or I get a 2047 output. It doesn't matter if I have a sensor attached or not, it will only output that value. Here is my code:
#include <MCP3008.h>
//define pin connections
#define CS_PIN 0
#define CLOCK_PIN 3
#define MOSI_PIN 1
#define MISO_PIN 2
MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);
void setup()
{
// open serial port
Serial.begin(115200);
}
void loop()
{
int val = adc.readADC(0); // read Channel 0 from MCP3008 ADC (pin 1)
Serial.println(val);
//Serial.println(analogRead(0));
delay(1000);
}
I don't know if this matters or not, since the MQ-7 requires 5v power and my board only provides 3.3v, I am hooking up the 5v output of an Arduino Uno in order to power the sensor as well as the MCP3008. The NodeMCU board is powered by an external USB cable. Let me know if you need any more information or pictures.
Thanks in advance and let me know if you have any idea how I can fix this or work around it,
M2com