Attribute error on Circuitpython MAX31855

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
smooth_jamie
 
Posts: 8
Joined: Sat Jan 31, 2015 6:34 pm

Attribute error on Circuitpython MAX31855

Post by smooth_jamie »

Hi All,

I am using circuitpython 6.3.0 with Thonny on Raspberry Pico and I am trying to get the Adafruit example for the MAX31855 library to read temperature. However I get an attribute error as follows;

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
AttributeError: 'module' object has no attribute 'SPI'
The code being used is as follows (adafruit example);

Code: Select all

import time
import board
import digitalio
import adafruit_max31855

spi = board.SPI()
cs = digitalio.DigitalInOut(board.D5)

max31855 = adafruit_max31855.MAX31855(spi, cs)
while True:
    tempC = max31855.temperature
    tempF = tempC * 9 / 5 + 32
    print("Temperature: {} C {} F ".format(tempC, tempF))
    time.sleep(1)
it gives the error on line 10 where SPI is defined. I don't understand. I have the adafruit_bus_device library installed, and the max31855 library installed in the correct places. Can anyone explain where I am going wrong?

User avatar
smooth_jamie
 
Posts: 8
Joined: Sat Jan 31, 2015 6:34 pm

Re: Attribute error on Circuitpython MAX31855

Post by smooth_jamie »

OK sorry to bother you all, silly mistake. it now works, here is the working code.

Code: Select all

import time
import board
import busio
import digitalio
import adafruit_max31855

clk = board.GP2
miso = board.GP4
# cs = board.GP9
#spi = board.SPI()
cs = digitalio.DigitalInOut(board.GP5)
spi = busio.SPI(clock=clk, MISO=miso)


max31855 = adafruit_max31855.MAX31855(spi, cs)

while True:
    tempC = max31855.temperature
    tempF = tempC * 9 / 5 + 32
    print("Temperature: {} C {} F ".format(tempC, tempF))
    time.sleep(1)
It turns out the MAX31855 should be connected to MISO not MOSI! Doh!

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

Return to “Adafruit CircuitPython”