I am having a problem with a python3 script where xfer2() from spidev fails with no warning or error message.
- I am using Raspbian 8.0
- I am trying to use the spi bus to talk to an MCP3008
- When I do an ls /dev I see the spidev0.0 and spidev0.1 drivers so spi is enabled.
- I have tried several different versions of the python wrapper for spidev.
The following code is simplified/minimized to just show the problem:
import sys import spidev print('Starting test code') print('initializing the spi bus instance') spi_bus = spidev.SpiDev() print('opening the spi bus') spi_bus.open(0, 0) print('getting the adc output ') adc_output = spi_bus.xfer2(1, 240, 0 ) # The program never gets to the following print statement. # Instead it just exits and returns to the prompt with no error statement print('adc read complete')
This is what I get when I run the python script:
pi@raspberrypi: ~ software $sudo python3 spi_testcode.py starting test code initializing the spi bus instance opening the spi bus getting the adc output pi@raspberrypi: ~ software $
Notice the final print statement is never executed. The script just stops with no error and no warning during the xfer2() call. Without some kind of an error message it is hard to debug this. Any suggestions are welcome.