MCP3008 Node not working

Hi All, I was hoping that someone out there in the community may be able to help out on this one.
I have setup a basic flow to test the MCP3008 ADC. This consists of an inject node, MCP3008 node and debug node. The MCP is connected to a RPI using pins 19 (MOSI), 21, (MISO), 23 (SCLK), 24 (CE0) and using power & ground from pins 1 & 6. A test voltage is applied to pin 1 (CH0)of the MCP3008 by setting up a voltage divider using 2 x 3K resistors. 1 resistor from CH0 to VCC (pin 1 rpi) and the other from CH0 to GND (pin 6 RPI).
The MCP3008 node is configured as input A0, Device ID CE0, SPI bus 0. When I trigger the inject I get only a 0 response from the node.
I have tested using spi_dump.js and get a response on this channel varying between 456 & 458.
Using spi_dump.js would seem to prove that this is not a hardware issue but perhaps something associated with Node-Red.
Does anyone have any ideas on this one?

Did you do the Pre-requisites to enable SPI on the Raspberry Pi?


You must ensure that SPI is enabled. For recent (2016) versions of Raspbian you can do this

  • Run sudo raspi-config
  • Select 5 - Interfacing Options
  • Select P4 - SPI
  • Select yes to enable SPI
  • Select OK to confirm
  • Select the Finish button

Yes, i guess we have to cover off the basics first.
The SPI interface is enabled in the RPI interfacing config.
I am getting expected results from the MCP3008 when i run spi_dump.js but not in node-red when running the mcp 3008 node.

Have you got all the MCP3008 pins set correctly? Acording to this article:

you should have six pins from the Pi connected to 8 pins on the MCP3008
Screen Shot 2021-06-05 at 3.45.50 AM

I have confirmed that the wiring i have is exactly as above with the addition of MCP3008 pin 1 via resistor divider (connected to the junction of 2 x 3K resistors in series between 3.3v and GND) to provide 1/2 vcc and pin 2 of MCP3008 to GND.
I have read through the tutorial you have suggested and installed the python dev tools, installed the SpiDev library and created the Python script to read from the MCP3008.
I am receiving 0 when i run the script, essentially the same result as per the Node-Red Node.

Why would both of these return 0 on ch0 of the mcp3008 and the spi_dump.js that I referred to in the initial post returns 456 - 458 which is around what i would expect?

To be honest, I haven’t a clue. I’ve never used the device and was just trying to cover the bases. You might post a question on the raspberry pi forum since the python code is returning 0 too.

Thanks zenofmud,
I have rebooted the RPI and my node is now working. Doing a bit more investigation, anytime I run spi_dump.js which is using the npm rpio node.js addon, the MCP3008 node in node-red will no longer work.
I am assuming that this must stop the library that node-red is using but I don't have enough expertise in this area to fully understand the why.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.