dirdled
Posts: 4
Joined: Wed Aug 23, 2017 8:28 pm

Problem with SPI after updating to Stretch - RESOLVED

Wed Aug 23, 2017 8:31 pm

Hi, I've updated my trusty Raspberry pi 2 to stretch, and now I can't get one of my staple scripts to work. It's a python script that accesses an mcp3008 to monitor light and temperatures. the SPI interface says it's on, and the script runs without any errors, but the calls to the mcp3008 are all returning 0. If I put the SD card with jessie on it back in everything works, so It's not a programming or wiring error. I'm pretty sure it just something I missed and forgot to re-install after the update, but without an error I don't know where to look. Anyone have any ideas where I could start?
Last edited by dirdled on Thu Aug 24, 2017 1:34 am, edited 1 time in total.

bulletmark
Posts: 121
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia

Re: Problem with SPI after updating to Stretch

Wed Aug 23, 2017 11:57 pm

What kernel version and what SPI library are you using with your python app?

dirdled
Posts: 4
Joined: Wed Aug 23, 2017 8:28 pm

Re: Problem with SPI after updating to Stretch

Thu Aug 24, 2017 12:47 am

I hope this answers what you're asking
The kernel version is Kernel version: Linux 4.9.43-v7+ armv7l
and the SPI Lib Im using is

I'm not sure how to find a version of spidev

bulletmark
Posts: 121
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia

Re: Problem with SPI after updating to Stretch

Thu Aug 24, 2017 12:53 am

I use Arch Linux, not Raspbian but I bet your problem is the same as I experienced due to the recent upgrade to kernel version 4.9.43.

I fixed my problem with https://github.com/bulletmark/pifaceio/ ... 785221ff21.

You don't say what SPI library you are using but it needs the same fix, or you need to change your app to explicity set the SPI transfer speed if the SPI library allows you.

dirdled
Posts: 4
Joined: Wed Aug 23, 2017 8:28 pm

Re: Problem with SPI after updating to Stretch

Thu Aug 24, 2017 1:30 am

Very cool...All bow to the big brain on Bulletmark...That seems to have fixed it, I added one line

spi.max_speed_hz = 5000

Immediately following the spi.open command and it seems to be working now...I'll report back if I find out differently.

Just curious but how do I know what a good value would be? I played around and it was look like it worked with pretty much everything I threw at it I tried values from 50 to 1000000.

In case you can't tell I'm not a hardware person (yet)

bulletmark
Posts: 121
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia

Re: Problem with SPI after updating to Stretch

Thu Aug 24, 2017 1:34 am

I looked at the data sheet for the MCP23S17 chip I am using and see that it is spec'd for up to 10 MHz so used that.

dirdled
Posts: 4
Joined: Wed Aug 23, 2017 8:28 pm

Re: Problem with SPI after updating to Stretch - RESOLVED

Thu Aug 24, 2017 1:45 am

Hmm, I looked at your data sheet and it comes right out and says

High-SpeedSPIInterface(MCP23S17): - 10MHz(maximum)

for mine it's a little more cryptic for the MCP3008. If I'm looking at the right place it looks like it says the Clock Frequency is either 3.6 or 1.35 Mhz based on the Vdd

Is there a benefit to running it at a less than maximum speed? Like longer chip life, or lower energy consumption?

(When you get tired of answering stuff just tell me to go away, You already got it working for me so I'm grateful)

bulletmark
Posts: 121
Joined: Wed Oct 17, 2012 10:10 pm
Location: Brisbane Australia

Re: Problem with SPI after updating to Stretch - RESOLVED

Thu Aug 24, 2017 1:56 am

I'm not a hardware guy either sorry so can't comment. Google seems to give plenty of links about SPI speed and MCP3008 though.

Return to “Troubleshooting”