'SPI' object has no attribute 'set_clock_hz'

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jhalpin
 
Posts: 14
Joined: Fri Jul 17, 2015 7:26 pm

'SPI' object has no attribute 'set_clock_hz'

Post by jhalpin »

I'm trying to get the sample code from https://github.com/adafruit/Adafruit_Python_MCP3008.git to work. I fixed a few apparently old references, but I'm stuck on trying to initialize the SPI interface. I get the error

bbb4g# ./simpletest.py
Traceback (most recent call last):
File "./simpletest.py", line 23, in <module>
mcp = Adafruit_MCP3008.MCP3008(spi=SPI(SPI_PORT, SPI_DEVICE))
File "build/bdist.linux-armv7l/egg/Adafruit_MCP3008/MCP3008.py", line 45, in __init__
AttributeError: 'SPI' object has no attribute 'set_clock_hz'

When I look at MCP3008.py, sure enough it doesn't have a set_clock_hz method. I just downloaded this from github, so I don't think I'm working with an old version of the code.

I've attached a diff which shows what I changed to get this far.

Thanks

Joe

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

I was able to run simpletest.py without error after I modified:
debian@beaglebone:~/Adafruit_Python_MCP3008$ git diff
diff --git a/examples/simpletest.py b/examples/simpletest.py
index 23f9f0c..53c100f 100644
--- a/examples/simpletest.py
+++ b/examples/simpletest.py
@@ -10,16 +10,16 @@ import Adafruit_MCP3008


# Software SPI configuration:
-CLK = 18
-MISO = 23
-MOSI = 24
-CS = 25
-mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
+#CLK = 18
+#MISO = 23
+#MOSI = 24
+#CS = 25
+#mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)

# Hardware SPI configuration:
-# SPI_PORT = 0
-# SPI_DEVICE = 0
-# mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
+SPI_PORT = 1
+SPI_DEVICE = 0
+mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))


Here is the output:
debian@beaglebone:~/Adafruit_Python_MCP3008$ sudo python examples/simpletest.py 2>&1
Reading MCP3008 values, press Ctrl-C to quit...
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---------------------------------------------------------
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
NOTE: I don't actually have the MCP3008 connected.

My system info:
debian@beaglebone:~$ cat /etc/debian_version
8.7
debian@beaglebone:~$ uname -a
Linux beaglebone 4.4.47-ti-r87 #1 SMP Mon Feb 6 22:21:49 UTC 2017 armv7l GNU/Linux
debian@beaglebone:~$ ls -la /dev/spidev*
crw-rw---- 1 root spi 153, 1 Apr 23 04:10 /dev/spidev1.0
crw-rw---- 1 root spi 153, 0 Apr 23 04:10 /dev/spidev1.1
crw-rw---- 1 root spi 153, 3 Apr 23 04:10 /dev/spidev2.0
crw-rw---- 1 root spi 153, 2 Apr 23 04:10 /dev/spidev2.1
Please try running with the attached simpletest.py

If it fails, please try running again with strace:
sudo strace -fF python examples/simpletest.py &> strace.txt
Attachments
mcp3008-install.txt
(4.5 KiB) Downloaded 297 times
simpletest-py.txt
(1.15 KiB) Downloaded 282 times

User avatar
jhalpin
 
Posts: 14
Joined: Fri Jul 17, 2015 7:26 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by jhalpin »

Hi, thanks for a reply on Sunday. It does run, but I get all values of 1023 (I have a potentiometer connected to channel 0 of the MCP3004).

I don't have the chip wired for SPI bus 1 though, which is confusing me. I don't see a chip select pin for SPI1. Which bus are you wired for?

I've enabled the overlays for both SPI0 and SPI1, but I don't seem to be able to access it.

Thanks

Joe

P.S. forgot the strace listing, attached
Attachments
strace.txt
(339.61 KiB) Downloaded 276 times

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

I see that it does open /dev/spidev1.0 OK on your system:
open("/dev/spidev1.0", O_RDWR|O_LARGEFILE) = 3
Please post the output of:
uname -a
cat /etc/debian_version
cat /etc/dogtag
cat /boot/uEnv.txt

If you don't have a Debian 8.x (Jessie) image with Linux kernel 4.4, then I would suggest downloading the latest image from BeagleBoard.org.

This is the SPI pins on the headers: cape-headers-spi.png

SPI0 on the P9 header should map to /dev/spi1.x. You should be able to configure the SPI0 pins with:
config-pin p9.17 spi #SPI0_CS0
config-pin p9.18 spi #SPI0_D1
config-pin p9.21 spi #SPI0_D0
config-pin p9.22 spi #SPI0_SCLK
Please post a photo of your wiring if you can.

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

I don't have a MCP3004 but I do have a MCP3008. I've wired it up according to this diagram from Chapter 8: Interfacing to the BeagleBone Buses:
Image

I have pot connected to channel 0 and get a reading:
debian@beaglebone:~/Adafruit_Python_MCP3008$ sudo python examples/simpletest.py
Reading MCP3008 values, press Ctrl-C to quit...
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---------------------------------------------------------
| 554 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 |
| 521 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 |
| 560 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 | 1023 |

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

Here is photos of the MCP3008 wired up to SPI0
Attachments
mcp3008-photo5.jpg
mcp3008-photo5.jpg (77.83 KiB) Viewed 2535 times
mcp3008-photo4.jpg
mcp3008-photo4.jpg (78.67 KiB) Viewed 2535 times
mcp3008-photo1.jpg
mcp3008-photo1.jpg (76.54 KiB) Viewed 2535 times

User avatar
jhalpin
 
Posts: 14
Joined: Fri Jul 17, 2015 7:26 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by jhalpin »

Please post the output of:
uname -a
cat /etc/debian_version
cat /etc/dogtag
cat /boot/uEnv.txt
bbb4g# uname -a
Linux bbb4g 4.4.54-ti-r93 #1 SMP Fri Mar 17 13:08:22 UTC 2017 armv7l GNU/Linux
bbb4g#
bbb4g# cat /etc/debian_version
8.7
bbb4g#
bbb4g#
bbb4g#
bbb4g# cat /etc/dogtag
BeagleBoard.org Debian Image 2017-03-19
bbb4g#
bbb4g#
bbb4g#
bbb4g# cat /boot/uEnv.txt
#Docs: http://elinux.org/Beagleboard:U-boot_pa ... layout_2.0

uname_r=4.4.54-ti-r93
#uuid=
#dtb=

##BeagleBone Black/Green dtb's for v4.1.x (BeagleBone White just works..)

##BeagleBone Black: HDMI (Audio/Video) disabled:
#dtb=am335x-boneblack-emmc-overlay.dtb

##BeagleBone Black: eMMC disabled:
#dtb=am335x-boneblack-hdmi-overlay.dtb

##BeagleBone Black: HDMI Audio/eMMC disabled:
#dtb=am335x-boneblack-nhdmi-overlay.dtb

##BeagleBone Black: HDMI (Audio/Video)/eMMC disabled:
#dtb=am335x-boneblack-overlay.dtb

##BeagleBone Black: wl1835
#dtb=am335x-boneblack-wl1835mod.dtb

##BeagleBone Green: eMMC disabled
#dtb=am335x-bonegreen-overlay.dtb

###U-Boot Overlays###
###Documentation: http://elinux.org/Beagleboard:BeagleBon ... t_Overlays
###Master Enable
#enable_uboot_overlays=1
###Overide capes with eeprom
#uboot_overlay_addr0=/lib/firmware/<file0>.dtbo
#uboot_overlay_addr1=/lib/firmware/<file1>.dtbo
#uboot_overlay_addr2=/lib/firmware/<file2>.dtbo
#uboot_overlay_addr3=/lib/firmware/<file3>.dtbo
###Custom Cape
#dtb_overlay=/lib/firmware/<file4>.dtbo
###Disable auto loading of virtual capes (emmc/video/wireless)
#disable_uboot_overlay_emmc=1
#disable_uboot_overlay_video=1
#disable_uboot_overlay_audio=1
#disable_uboot_overlay_wireless=1
###Cape Universal Enable
#enable_uboot_cape_universal=1
###U-Boot fdt tweaks...
#uboot_fdt_buffer=0x60000
###U-Boot Overlays###

cmdline=coherent_pool=1M net.ifnames=0 quiet cape_universal=enable

#In the event of edid real failures, uncomment this next line:
#cmdline=coherent_pool=1M net.ifnames=0 quiet cape_universal=enable video=HDMI-A-1:1024x768@60e

##Example v3.8.x
#cape_disable=capemgr.disable_partno=
#cape_enable=capemgr.enable_partno=

##Example v4.1.x
#cape_disable=bone_capemgr.disable_partno=
#cape_enable=bone_capemgr.enable_partno=

##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

optargs=quiet capemgr.disable_partno=BB-BONELT-HDMI,BB-BONELT-HDMIN
uuid=212139d5-3f4e-453d-a8b7-bb40485843a6
bbb4g#
bbb4g#
bbb4g#
bbb4g# cat /sys/devices/platform/bone_capemgr/slots
0: PF---- -1
1: PF---- -1
2: PF---- -1
3: PF---- -1
4: P-O-L- 0 Override Board Name,00A0,Override Manuf,cape-universaln
If you don't have a Debian 8.x (Jessie) image with Linux kernel 4.4, then I would suggest downloading the latest image from BeagleBoard.org.

This is the SPI pins on the headers: cape-headers-spi.png

SPI0 on the P9 header should map to /dev/spi1.x. You should be able to configure the SPI0 pins with:
config-pin p9.17 spi #SPI0_CS0
config-pin p9.18 spi #SPI0_D1
config-pin p9.21 spi #SPI0_D0
config-pin p9.22 spi #SPI0_SCLK
Please post a photo of your wiring if you can.

This isn't a real good picture, but it's wired as you described. The breadboard has 3 Volt rails.
ADC-Wiring.jpg
ADC-Wiring.jpg (188.94 KiB) Viewed 2517 times

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

Please check if the SPI0 pins are configured for spi mode:

config-pin -q p9.17 spi
config-pin -q p9.18 spi
config-pin -q p9.21 spi
config-pin -q p9.22 spi

For example:
debian@beaglebone:~$ config-pin -q p9.17 spi
P9_17 Mode: spi
debian@beaglebone:~$ config-pin -q p9.18 spi
P9_18 Mode: spi
debian@beaglebone:~$ config-pin -q p9.21 spi
P9_21 Mode: spi
debian@beaglebone:~$ config-pin -q p9.22 spi
P9_22 Mode: spi

User avatar
jhalpin
 
Posts: 14
Joined: Fri Jul 17, 2015 7:26 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by jhalpin »

drewfustini wrote:Please check if the SPI0 pins are configured for spi mode:

config-pin -q p9.17 spi
config-pin -q p9.18 spi
config-pin -q p9.21 spi
config-pin -q p9.22 spi
I think I'm starting to shave a yak. Originally I was trying to get this working on a Raspberry Pi, and wanted to check with a Beaglebone to be sure the ADC chip was working. Then I couldn't get that to work, and asked for help. After getting your reply I upgraded the Beaglebone to debian 8.7.

Now I can't find config-pin, or any compiled overlays. Any idea where I get those?

Thanks

Joe

Edit: I rebooted my Beaglebone, and now everything's there. I don't know what's happening now. At any rate the pins aree all setup for spi
bbb4g# config-pin -q p9.21
P9_21 Mode: spi
bbb4g# config-pin -q p9.22
P9_22 Mode: spi
bbb4g# config-pin -q p9.18
P9_18 Mode: spi
bbb4g# config-pin -q p9.17
P9_17 Mode: spi

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

What results do you get now when you run simpletest.py?

Did you wire anything to the channels like pin 1 (CH0)? I can't see that part in the photo.

Also, I noticed you have Vref and AGND connected to VCC and GND on the breadboard rails. I wired Vref and AGND to the ends of my pot with the wiper connected to CH0.

User avatar
jhalpin
 
Posts: 14
Joined: Fri Jul 17, 2015 7:26 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by jhalpin »

drewfustini wrote:What results do you get now when you run simpletest.py?
Same thing, all zeros
Did you wire anything to the channels like pin 1 (CH0)? I can't see that part in the photo.
Yes, I've attached another photo that shows a little more.
Also, I noticed you have Vref and AGND connected to VCC and GND on the breadboard rails. I wired Vref and AGND to the ends of my pot with the wiper connected to CH0.
I wired my setup like that, but still all zeros.

I'm spending too much time on this, and I'm not really sure my Beaglebone is entirely ok. I just ordered an ADC carrier board that uses I2C, and I'll use that.

Thanks for the help.

Joe
Attachments
DSC_0820.JPG
DSC_0820.JPG (184.61 KiB) Viewed 2477 times

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

Ok, the advantage of I2C is that the i2cdetect is useful to discover if the device is wired up to bus correctly.

In regards to the photo, I did notice that you have Vref (MCP3004 pin 13) and AGND (MCP3004 pin 12) connected to breadboard power rails. I do not have this connected like that. I've annotated your image to reflect this.
beaglebone.png
beaglebone.png (812.62 KiB) Viewed 2469 times

User avatar
Mujiwizard
 
Posts: 10
Joined: Sun Oct 23, 2016 5:22 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by Mujiwizard »

I have a general question regarding the MCP3008 python library from Adafruit. On the Adafruit's tutorial on BeagleBone Black the import for SPI object used is different from the import used in the MCP3008 library.

Do we need to make any changes to the library provided on GIT to port it to Beaglebone or does that automatically take place when we build the library using setup.py?

Also is there a way to know a list of attributes that are available in Adafruit_BBIO.SPI object?

User avatar
drewfustini
 
Posts: 944
Joined: Sat Dec 26, 2015 1:19 pm

Re: 'SPI' object has no attribute 'set_clock_hz'

Post by drewfustini »

Adafruit_BBIO.SPI is defined in setup.py

Code: Select all

Extension('Adafruit_BBIO.SPI', ['source/spimodule.c', 'source/constants.c', 'source/common.c'], **extension_args),
The relevant C source code file is:
adafruit-beaglebone-io-python/blob/master/source/spimodule.c

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”