Closed stacy-hunt closed 3 years ago
I expect that when I connect the 3.3V rail to pin 5 on the MCP3008, the value that the Pi logs should be 1023, right?
Correct, but not with the test program posted above. The test program above is for channel 0 (pin 1). For channel 4 (pin 5) it should be:
const sensor = mcpadc.open(4, {speedHz: 20000}, err => {
rather than:
const sensor = mcpadc.open(0, {speedHz: 20000}, err => {
One thing that I don't understand is that the Pi doesn't throw an error when I disconnect the MCP from it. I'd have thought that if it couldn't communicate with the MCP it would throw an error?
With SPI, if no device is connected everything still appears to work. In this case, the Linux SPI driver still reads from the SPI MISO line and every bit read is typically 0.
Do you have any suggestions about what steps I could take to troubleshoot it?
The code posted looks correct. The Linus SPI driver doesn't appear to see the MCP3008.
/boot/config.txt
.node -v
uname -a
ls -l /dev/spi*
The test program above is for channel 0 (pin 1). For channel 4 (pin 5) it should be:
Right - I changed it to channel 0, but I did try connecting 3.3V to each of the input pins one by one in case I had specified it incorrectly. But none of the pins produced any output other than 0.
With SPI, if no device is connected everything still appears to work
Ah OK.
Are you sure that the MCP3008 that you are using functions correctly?
Yes, but I don't know how to test it. I bought 4 of them and this one is fresh out of the box. I tried it with a second new one as well just in case it was faulty, but not difference.
Please post the output of the command node -v Please post the output of the command uname -a Please post the output of the command ls -l /dev/spi*
Here you are:
Oh yeah one more thing you asked for: config.txt
Ahhhh... Hey Brian, I got it working!
I hadn't realised that your Raspberry Pi has a different pinout pattern from mine. I traced each cable and checked the name of the pin and discovered that the pattern was different. So I had the connections going to the wrong pins on my Pi (which is a model 4). So I just had to look up each pin by name, find it on the Pi and connect to the right pins.
I hope I didn't waste your time, although just going through your list made me think of checking that so you did help a lot!
Problem solved. Your module is awesome, thanks for making it.
If you check the pin numbers on the Pi 4 and Pi 1 GPIO headers you'll see that they are the same. Anyway, good to hear that it's working now.
I'm trying to read analog signals with my Raspberry Pi 4 and Node js, and I'm following the instructions to get your module working
It seems like I'm almost there, but I wonder if you could help me with some final troubleshooting.
I have everything connected the same way as in your diagram, and I've enabled SPI on my Raspberry Pi and restarted it. I have an Express server running on the Pi, and running your sample code in there. It seems to be running fine, and it console.logs out the value every second. In my case, because I'm not using a temperature sensor I took out the math. I just log the raw value and I'll do the math later.
I expect that when I connect the 3.3V rail to pin 5 on the MCP3008, the value that the Pi logs should be 1023, right? But no matter what I try, it always outputs 0. I've tried connecting it to each of the input pins on the MCP one at a time in case I was mistaken about which pin I was using, but it always outputs 0. I also checked that I do have 3.3V on that rail, and it's being supplied to pins 15 and 16. I've double-checked all of the connections too.
One thing that I don't understand is that the Pi doesn't throw an error when I disconnect the MCP from it. I'd have thought that if it couldn't communicate with the MCP it would throw an error?
Do you have any suggestions about what steps I could take to troubleshoot it? I'm very stumped and I can't find any helpful resources about it on the internet. Thanks in advance for any help.
Here is the code I'm running, which is pretty much identical to yours except the math that operates on the value is removed: