viss02
Posts: 6
Joined: Sun Aug 16, 2015 4:06 pm

MCP3008 and SPI - no output

Thu Feb 18, 2016 11:22 pm

Hello,

I'm trying to use mcp3008 to read signal form analog sensor.

For wiring I used instructions from this address: http://www.raspberrypi-spy.co.uk/2013/1 ... n-mcp3008/

I performed software and firmware update. SPI is enabled in raspi-config. Python libraries are installed.

My problem is that all examples returns 0 no mater what is happening with my ch0 input.

root@raspberrypi:/home/pi# uname -a
Linux raspberrypi 4.1.17+ #843 Mon Feb 15 23:17:46 GMT 2016 armv6l GNU/Linux

root@raspberrypi:/home/pi# ls /dev | grep spi
spidev0.0
spidev0.1

I can modprobe spi_bcm2835 and spi_bcm2708 without any problems.

In /boot/config.txt, on end I have this:

Code: Select all

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
dtparam=i2s=on
dtparam=spi=on
dtoverlay=spi-bcm2708-overlay

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

dtparam=i2c_arm=off
core_freq=500
sdram_freq=500
over_voltage=2
dtparam=spi=on

root@raspberrypi:/home/pi# lsmod

Code: Select all

Module                  Size  Used by
arc4                    1956  2
rtl8187                53210  0
eeprom_93cx6            4106  1 rtl8187
mac80211              595863  1 rtl8187
cfg80211              479279  2 mac80211,rtl8187
rfkill                 21544  2 cfg80211
snd_soc_bcm2708_i2s     7654  0
regmap_mmio             3556  1 snd_soc_bcm2708_i2s
snd_soc_core          167413  1 snd_soc_bcm2708_i2s
snd_compress            8861  1 snd_soc_core
snd_pcm_dmaengine       5794  1 snd_soc_core
spi_bcm2708             5685  0
bcm2835_gpiomem         3703  0
bcm2835_rng             2207  0
uio_pdrv_genirq         3526  0
uio                    10078  1 uio_pdrv_genirq
spi_bcm2835             7868  0
rtc_ds1307             10459  0
i2c_dev                 6386  0
snd_bcm2835            22502  6
snd_pcm                92829  3 snd_bcm2835,snd_soc_core,snd_pcm_dmaengine
snd_timer              21936  1 snd_pcm
snd                    67534  17 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_compress
fuse                   86348  5
ipv6                  358702  26
I preformed loopback test, documented here: https://www.raspberrypi.org/documentati ... /README.md

When I join MISO and MOSI:

Code: Select all

root@raspberrypi:/home/pi# ./spidev_test -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D
When chip is connected to MOSI and MISO:
root@raspberrypi:/home/pi# ./spidev_test -D

Code: Select all

/dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00 00 00 00 00
00 00
What can be wrong here? What else should I test?

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: MCP3008 and SPI - no output

Thu Feb 18, 2016 11:32 pm

Many things.

- List all the connections you have made between the Pi and the MCP3008
- list what you have connected to each pin of the MCP3008
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: MCP3008 and SPI - no output

Fri Feb 19, 2016 3:19 am

viss02 wrote:What can be wrong here? What else should I test?
You actually have to send a specific command to the MCP3008.
The data in the spidev_test program is just gibberish to the mcp3008 so even if you have everything connected properly it will ignore you. Check pages 19-20 of the mcp3004/8 data sheet, you need to send bits which instruct it which channels to sample and how. Its only looking at the the first byte or two so after that everything just gets ignored. You can shift the output around to line up with bytes better by shifting the input around.

viss02
Posts: 6
Joined: Sun Aug 16, 2015 4:06 pm

Re: MCP3008 and SPI - no output

Fri Feb 19, 2016 10:22 am

Hello,

This is my schematics:
MCP.png
MCP.png (15.87 KiB) Viewed 1837 times
Analog sensor is MQ-3: http://www.sigmaelectronica.net/mq-3-p-1956.html

I didn't said before, I have RasPiO Breakout Pro : http://rasp.io/breakoutpro

@fsr: I'm not sure that I figured out. I tested using python programs that I found on internet.

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: MCP3008 and SPI - no output

Fri Feb 19, 2016 4:53 pm

Your wiring is correct for 3v3 operation, however

the sensor requires 5VDC

Power the sensor from 5VDC, then use a voltage divider to convert the sensors output to 0-3v3
viss02 wrote:Hello,

This is my schematics:
MCP.png
Analog sensor is MQ-3: http://www.sigmaelectronica.net/mq-3-p-1956.html

I didn't said before, I have RasPiO Breakout Pro : http://rasp.io/breakoutpro

@fsr: I'm not sure that I figured out. I tested using python programs that I found on internet.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

viss02
Posts: 6
Joined: Sun Aug 16, 2015 4:06 pm

Re: MCP3008 and SPI - no output

Sun Feb 21, 2016 11:33 pm

Tested with instructions from here (http://jeremyblythe.blogspot.rs/2012/09 ... nputs.html) and results was 0.

Sensor is working with 5v, but it's giving output also on 3.3v (tested with multimeter).

Also, I have connected 3.3v to CH0 to test will something happen but there is nothing except 0.

I'm thinking that RasPiO Breakout Pro is blocking access and that maybe my real time clock module is making problem (connected to i2c).

Return to “Troubleshooting”