MAX31865 micropython driver?

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
T-Wilko
Posts: 30
Joined: Thu Sep 19, 2019 8:08 am

MAX31865 micropython driver?

Post by T-Wilko » Sun Sep 22, 2019 11:50 am

Hi all,

This is my first post on this forum so please bear with me.
Does anybody have a micropython driver for the MAX31865 amplifier board? I've seen the CircuitPython code but am not quite proficient in differentiating cPy code from uPy to make a working uPy version.

For context, I'm a student building a sensor payload for the University of Western Australia's Aerospace club and I'm wanting to use micropython to program a multi-input datalogger.

Thank you in advance,
Thomas

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: MAX31865 micropython driver?

Post by jimmo » Sun Sep 22, 2019 1:49 pm

Hi,
T-Wilko wrote:
Sun Sep 22, 2019 11:50 am
Does anybody have a micropython driver for the MAX31865 amplifier board? I've seen the CircuitPython code but am not quite proficient in differentiating cPy code from uPy to make a working uPy version.
Which MicroPython board are you using? If it's a pyboard, then https://github.com/B3AU/micropython/blo ... AX31865.py might just work. It's 5 years old, so it has its own bit-bang SPI implementation, but here's roughly what I'd do to bring it up to date (or to make it work on other ports).

change the imports to:

Code: Select all

import time
import machine
import FIR
change the constructor's first few lines to

Code: Select all

 def __init__(self, spi, cs):
        self.spi = spi
        cs.init(mode=machine.Pin.OUT)
        cs.value(1)
        self.cs = cs
        self.fir = FIR.FIR(16)
(i.e. remove the DRDY_pin, add cs, and replace the self.spi line)

Replace usage of the pyb module.

Code: Select all

pyb.millis() --> time.ticks_ms()
Toggle the CS pin when reading/writing

Code: Select all

cs.value(0)
self.spi.write(buf)
cs.value(1)

Code: Select all

cs.value(0)
MSB = self.spi.read(0x01,1)[0]
LSB = self.spi.read(0x02,1)[0]
cs.value(1)
I _think_ that should just work? Copy MAX31865.py and FIR.py to your board, then

Code: Select all

spi = machine.SPI('X', polarity=0, phase=1)  # if you're using a Pyboard, other boards you'll have to look at https://docs.micropython.org/en/latest/library/machine.SPI.html for the alternatives to using 'X'
cs = machine.Pin('X5')
import MAX31865
max31865 = MAX31865.MAX31865(spi, cs)
You've probably already seen the more sophisticated CircuitPython driver at https://github.com/adafruit/Adafruit_Ci ... ax31865.py

You could adapt this to MicroPython too. In summary:
- Replace the use of SPIDevice with just using machine.SPI directly.
- Replacing the use of @property, @auto_convert, etc with just regular methods.

Let me know, can provide more detailed instructions.
T-Wilko wrote:
Sun Sep 22, 2019 11:50 am
student ... University of Western Australia
That was me once too! :)

User avatar
T-Wilko
Posts: 30
Joined: Thu Sep 19, 2019 8:08 am

Re: MAX31865 micropython driver?

Post by T-Wilko » Mon Sep 23, 2019 3:48 am

Thanks Jimmo for the quick and comprehensive reply!

[quote=jimmo post_id=39646 time=1569160199 user_id=3071]
Which MicroPython board are you using?
[/quote]

In between submitting this post, and now typing this reply, I've managed to find a thread ( viewtopic.php?t=5181 ) containing discussion on this amplifier board in relation to a very similar board to the one that I'm attempting to use (Lolin D32 Pro).

I think I'm going to edit just the pins in the lopy driver that's linked in that thread, then I'll give that a whirl tonight.

Since you seem fairly knowledgeable on external component related things, I was wondering if you'd know if the fact that my reference resistor is the *wrong* one on my amplifier board (as I bought the pt1000 version board, not the pt100 version which I need) will adversely affect the hardware? I understand that I'll have to change the value of the 'RefR' variable in the driver, but I can't find any discussion on whether there are any other compatibility issues due to the difference. I'd love to not fry this board as the launch is so soon!

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: MAX31865 micropython driver?

Post by jimmo » Tue Sep 24, 2019 7:16 am

T-Wilko wrote:
Mon Sep 23, 2019 3:48 am
Since you seem fairly knowledgeable on external component related things, I was wondering if you'd know if the fact that my reference resistor is the *wrong* one on my amplifier board (as I bought the pt1000 version board, not the pt100 version which I need) will adversely affect the hardware? I understand that I'll have to change the value of the 'RefR' variable in the driver, but I can't find any discussion on whether there are any other compatibility issues due to the difference. I'd love to not fry this board as the launch is so soon!
So you have a PT100 sensor, but you've got the PT1000 board? From a quick read of the adafruit page and the max31865 datasheet, yes all you have to do is replace the reference resistor (the boards are otherwise identical), and configure the driver appropriately.

Or are you asking if you can use the board with the 4300ohm resisitor with a PT100? It sounds like that might work but you'll loose accuracy. But I'm not 100% sure on that. I think the other way around is not so good though.

(I've never used this chip or a platinum rtd before, so all this is just what I could learn in a few mins of reading)

Post Reply