# MCP3008 Node not working

**URL:** https://discourse.nodered.org/t/mcp3008-node-not-working/46712
**Category:** General
**Created:** [4 June 2021 23:20 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712 "2021-06-04T23:20:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)
#### Post date: [4 June 2021 23:20 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/1 "2021-06-04T23:20:03Z")

</div>

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](https://gist.github.com/mikaelleven/c3db08ae7837eb3c8698) 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?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [5 June 2021 07:29 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/2 "2021-06-05T07:29:46Z")

</div>

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

### Pre-requisites

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

---

<div class="post-metadata">

### Author: ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)
#### Post date: [5 June 2021 07:36 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/3 "2021-06-05T07:36:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [5 June 2021 07:48 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/4 "2021-06-05T07:48:01Z")

</div>

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

> **[MCP3008: Read out Analog Signals on the Raspberry Pi](https://tutorials-raspberrypi.com/mcp3008-read-out-analog-signals-on-the-raspberry-pi/)**
>
> 8 Channel Analog / Digital Converter ⚫ Implement Analog Arduino Projects on the Raspberry Pi ⚫ Python Library for the Use of Raspberry Pi & MCP3008

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a7430419901b56e3288db880d786122a689ccd1.png)

---

<div class="post-metadata">

### Author: ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)
#### Post date: [5 June 2021 22:32 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/5 "2021-06-05T22:32:12Z")

</div>

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?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e5a354655e1ee86614ed1482d8db79a6ed2904af.png)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [6 June 2021 01:21 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/6 "2021-06-06T01:21:30Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dmac101](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dmac101](https://discourse.nodered.org/u/dmac101)
#### Post date: [6 June 2021 06:35 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/7 "2021-06-06T06:35:12Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [5 August 2021 06:35 UTC](https://discourse.nodered.org/t/mcp3008-node-not-working/46712/8 "2021-08-05T06:35:41Z")

</div>

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