Closed IvanSemin33 closed 3 years ago
Please post the output of the following commands:
node -v
uname -a
groups
ls -l /dev/spi*
Please post the complete contents of the file /boot/config.txt.
Please post a photo of the hardware which clearly shows the wires on the Raspberry Pi GPIO header and how they are connected to the MCP3008.
EDIT: Also, please please post a link to a description of the pulse sensor connected to channel 1 on the MCP3008.
ivan_semin@raspberrypi:~ $ node -v
v14.15.4
ivan_semin@raspberrypi:~ $ uname -a
Linux raspberrypi 5.4.83-v7l+ #1379 SMP Mon Dec 14 13:11:54 GMT 2020 armv7l GNU/Linux
ivan_semin@raspberrypi:~ $ groups
ivan_semin sudo video lpadmin gpio
ivan_semin@raspberrypi:/ $ ls -l /dev/spi*
crw-rw---- 1 root spi 153, 0 Jan 30 22:17 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Jan 30 22:17 /dev/spidev0.1
ivan_semin@raspberrypi:/boot $ cat config.txt
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82
start_x=1
gpu_mem=128
dtparam=spi=on
ivan_semin@raspberrypi:~ $ groups ivan_semin sudo video lpadmin gpio
The user, in this case
ivan_semin
, needs to be a member of groupspi
in order to use SPI. Add the user to groupspi
and try again.
Does it work for user pi
?
Please add user ivan_semin
to group spi
, this is required.
Try the following: Disconnect the sensor from channel 1 on the MCP3008 and then connect channel 1 to the 3V3 power rail on the breadboard. Then run the program. What does it output? Is rawValue
approximately 1023?
I checked the photos. It looks like everything is connected up correctly to me.
I added the user to the group
ivan_semin@raspberrypi:~ $ groups ivan_semin
ivan_semin : ivan_semin sudo video spi gpio lpadmin
And connect channel 0 to 3v3
Nothing changed(
In the last photo the wire appears to be connected to channel 1 but the text mentions channel 0. Was everything tested correctly here?
Have you tried with user pi to see If that works?
In the last photo the wire appears to be connected to channel 1 but the text mentions channel 0. Was everything tested correctly here?
Sorry, now it in channel 0
Have you tried with user pi to see If that works?
Yes I've tried but it still doesn't work
I'm not sure what the problem is. Here is what I see when I run the program from the first post with a temperature sensor connected to channel 5.
pi@raspberrypi:~/mcp-spi-adc $ node t.js
Opened
{ rawValue: 217, value: 0.21212121212121213 }
0.21212121212121213
{ rawValue: 217, value: 0.21212121212121213 }
0.21212121212121213
{ rawValue: 218, value: 0.2130987292277615 }
0.2130987292277615
{ rawValue: 218, value: 0.2130987292277615 }
0.2130987292277615
{ rawValue: 229, value: 0.2238514173998045 }
0.2238514173998045
...
I'm not sure what the problem is. Here is what I see when I run the program from the first post with a temperature sensor connected to channel 5.
Are u changed channel from 1 to 5? Like this:
mcpadc.openMcp3008(5, {speedHz: 1350000, busNumber: 0, deviceNumber: 0},...
Yes
I've tried channel 5. Still nothing works
EDIT: Also, please please post a link to a description of the pulse sensor connected to channel 1 on the MCP3008.
I don't think this is a software problem with the mcp-spi-adc module. It's more likely to be a hardware problem. To find out, let us try reading from the MCP3008 with gpiozero which is a simple Python interface to GPIO devices for the Raspberry Pi.
If you haven't got gpiozero installed already, please install it as described here: https://gpiozero.readthedocs.io/en/stable/installing.html
After installing gpiozero, start the Python interpreter and run the following 3 line program from the REPL:
from gpiozero import MCP3008
tmp36 = MCP3008(channel=5)
tmp36.value
Here is what I see when I run the program:
pi@raspberrypi:~ $ python
Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gpiozero import MCP3008
>>> tmp36 = MCP3008(channel=5)
>>> tmp36.value
0.21446018563751834
>>>
You can simply connect channel 5 on the MCP3008 directly to 3v3. The value printed should be approximately 1.0. What value do you see if you run this Python program?
I've connected channel 5 on the MCP3008 to 3v3
test-pins.py
from gpiozero import MCP3008
channels = [0,1,2,3,4,5,6,7]
for ch in channels:
tmp36 = MCP3008(channel=ch)
print(ch,tmp36.value)
Result:
(0, 0.0004885197850512668)
(1, 0.0004885197850512668)
(2, 0.0004885197850512668)
(3, 0.0004885197850512668)
(4, 0.0004885197850512668)
(5, 0.0004885197850512668)
(6, 0.0004885197850512668)
(7, 0.0004885197850512668)
EDIT: I've diconnected MCP3008 from breadboard and got the same result
Thank you for the feedback. This means that the problem is not in mcp-spi-adc and it's not in gpiozero. The problem is somewhere else. As mentioned above, I think it's a hardware problem, here are things that comes to mind:
Maybe the Linux SPI device driver is defect.
You'll need to perform further troubleshooting to figure out what the source of the problem is.
thanks for ur help 🙏
Why do I get these results while I have everything disconnected from my raspberry pi?
Code:
from gpiozero import MCP3008 channels = [0,1,2,3,4,5,6,7] for ch in channels: tmp36 = MCP3008(channel=ch) print(ch,tmp36.value)
Result:
(0, 0.0004885197850512668) (1, 0.0004885197850512668) (2, 0.0004885197850512668) (3, 0.0004885197850512668) (4, 0.0004885197850512668) (5, 0.0004885197850512668) (6, 0.0004885197850512668) (7, 0.0004885197850512668)
This is how SPI works. The Linux SPI driver can't determine whether or not an SPI device is actually connected to the SPI bus. It simply shifts data out on the MOSI pin and shifts data in on the MISO pin. It also generates the appropriate clock signal.
This is unlike I2C where the driver can detect whether or not a device is actually connected to the I2C bus.
You could perform an SPI loopback test to see if SPI on the Raspberry Pi is functioning correctly. A description of how to do this can be found at: https://importgeek.wordpress.com/2017/09/11/raspberry-pi-spi-loopback-testing/
This doesn't test the chip select or clock pins, but it should let you know if MOSI and MISO on the Pi are working.
You should disconnect the MCP3008 for the loopback test.
Hi
We’re trying to get an information stuff using pulse sensor. We use MCP3008, Raspberry Pi 4, Pulse Sensor and mcp-spi-adc.
Our code:
We always get 0
Result:
Please help🙏