SPI MAX31855 - Anyone got it working?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

SPI MAX31855 - Anyone got it working?

Post by sjp770 » Thu Aug 31, 2017 2:04 am

Ive been trying to get this working, let me know if there are any major issues:

import machine
spi = machine.SPI(2, baudrate=5000000, polarity=0, phase=0)
cs = machine.Pin(5, machine.Pin.OUT)
cs.value(0)
data = spi.read(4)
print(data)
def temp_c(data):
temp = data[0] << 8 | data[1]
if temp & 0x0001:
return float('NaN') # Fault reading data.
temp >>= 2
if temp & 0x2000:
temp -= 16384 # Sign bit set, take 2's compliment.
return temp * 0.25
print(temp_c(data))


Pin wise im using GPIO 5 for the CS, GPIO 18 for Clock and GPIO 19 for MISO (connected to DO on the MAX31855)

I'm running the chip on 5v. The ESP32 board I have is a NodeMCU ESP-32S v1.1 so its labeled with P5, P18 and P19 for those pins. Using this Diagram: https://raw.githubusercontent.com/gojim ... pinout.png
I think im connected to the correct pins. It doesnt throw any errors but only reports 0.0 at time of boot.

What would be the best way to loop this so it reads data every few seconds? I am planning on connecting 4x MAX31855's and if I can 4x 128x32 SSD1306 OLEDS.
Last edited by sjp770 on Fri Sep 01, 2017 12:38 am, edited 3 times in total.

chrisb2
Posts: 28
Joined: Sat Apr 01, 2017 4:19 am

Re: SPI MAX31855 - Any got it working?

Post by chrisb2 » Thu Aug 31, 2017 7:03 am

The max31855 data sheet says operating voltage should be between 3.0 and 3.6V, with an absolute maximum of 4.0V, so using 5V may have damaged it?

sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

Re: SPI MAX31855 - Any got it working?

Post by sjp770 » Thu Aug 31, 2017 7:20 am

https://www.adafruit.com/product/269 - 5v compatible

This is the one im using, but that highlights why the cheaper ones I have on the way had less components probably only support 3.3v.

Thanks for the heads up.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: SPI MAX31855 - Any got it working?

Post by deshipu » Thu Aug 31, 2017 11:01 am

There is a ready library for that thermocouple: https://bitbucket.org/thesheep/micropython-max31855/src

sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

Re: SPI MAX31855 - Anyone got it working?

Post by sjp770 » Fri Sep 01, 2017 12:30 am

Ok, using that library I have to edit the max31855.py file to handle Pin control from cs.low() and cs.high() to cs.value(0) and cs.value(1), then it runs fine but still returns 0.0.

I'm now trying it on a Wemos Lolin32 1.0.0 board which is labelled much better. DO from the MAX31855 is connected to pin 19 labelled MISO, CLK is connected to pin 18 labelled SCLK, and CS is connected to pin 15.

Code: Select all

import max31855
from machine import SPI, Pin
spi = SPI(1, baudrate=1000000)
cs = Pin(15, Pin.OUT)
s = max31855.MAX31855(spi, cs)
print(s.read())
I confirmed the MAX31855 chip and thermocouple are working by running up an arduino UNO with sample code from adafruit.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: SPI MAX31855 - Anyone got it working?

Post by deshipu » Fri Sep 01, 2017 8:38 am

The ESP32 port is still experimental, it's possible the SPI peripheral handling is not yet perfect.

sjp770
Posts: 7
Joined: Thu Aug 24, 2017 12:50 am

Re: SPI MAX31855 - Anyone got it working?

Post by sjp770 » Mon Sep 04, 2017 3:51 am

Ok, i'll keep looking and post back if i ever get it working. Thanks

nmtb
Posts: 2
Joined: Tue Oct 17, 2017 1:34 pm

Re: SPI MAX31855 - Anyone got it working?

Post by nmtb » Tue Oct 17, 2017 1:43 pm

Hi,

First post, and a noob when it comes to micropython so not sure how much help I can be.
However I did manage to get MAX31855 working the ESP32 DevKit using the library which deshipu linked.
I got zero's as you did before I defined the miso and sck pins.

from machine import SPI, Pin
import MAX31855

miso = Pin(19, Pin.OUT)
sck = Pin(18, Pin.OUT)
cs = Pin(17, Pin.OUT)
spi = SPI(1, baudrate=1000000, sck=sck, miso=miso)
data = MAX31855.MAX31855(spi, cs)
print(data.read())

Post Reply