Skip to content

New dtoverlays for max6675 and max31855 thermocouples #3763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

New dtoverlays for max6675 and max31855 thermocouples #3763

wants to merge 1 commit into from

Conversation

DougieLawson
Copy link

@pelwell
Copy link
Contributor

pelwell commented Jul 28, 2020

There are few small issues with this PR:

  1. There is a max31885e overlay which isn't compiled or referenced.
  2. All the makefile entries are in order except max6675.
  3. The max38155 README entry still references MAX6675.
  4. The README file doesn't like trailing whitespace, even on blank lines.
  5. The dev and speed parameters aren't documented.

And there's a larger issue - although you've carefully given everything unique names, these overlays only differ functionally in their compatible strings. There are a few techniques you can use to shorten it (I won't say simplify):

i. Parameters can now include literal assignments - whatever value you give the parameter, it can also assign fixed values to properties. These can include label references.
ii. If you assign to the reg property of a node it will also change the address portion of the node name.

The combination of those two means you can create a single payload node that can be steered around by patching the target of the fragment:

...
    frag8: fragment@8 {
        target = <&spi0>;
        __overlay__ {
            thermocouple: thermocouple@0 {
                compatible = "maxim,max6675";
                reg = <0>;
                spi-max-frequency = <500000>;
            };
        };
    };
...
    __overrides {
        spi0-0 = <0>, "+0",
                 <&frag8>,"target:0=",<&spi0>,
                 <&thermocouple>,"reg:0=0";
        spi0-1 = <0>, "+1",
                 <&frag8>,"target:0=",<&spi0>,
                 <&thermocouple>,"reg:0=1";
        spi1-0 = <0>, "+2",
                 <&frag8>,"target:0=",<&spi1>,
                 <&thermocouple>,"reg:0=0";
        ...
        dev = <&thermocouple>,"compatible";
        max6675 = <&thermocouple>,"compatible=maxim,max6675";
        max31855 = <&thermocouple>,"compatible=maxim,max31855";
        max31855e = <&thermocouple>,"compatible=maxim,max31855e";
        max31855j = <&thermocouple>,"compatible=maxim,max31855j";
        ...
    };

Or is that too much magic, or too dependent on newer firmware for your needs?

@pelwell
Copy link
Contributor

pelwell commented Jul 28, 2020

And I forgot to add:

  1. Please don't include merge commits - we like downstream commits to be rebased, with merges only for upstream code.

@DougieLawson
Copy link
Author

Hi Phil,

You have a distinct head start, the DTS syntax stuff is terribly arcane & isn't well documented - that's why it's a lot of hacking from the anyspi overlay. The git pull request stuff has an ever worse level of documentation.

The SPI speed is set to a fixed value in the kernel driver and can't be overridden.

I don't understand point #6, if a "merge commit" bit me on the nose I wouldn't recognise it (I'm a git novice when it comes to this stuff and it took ten hours and two goes (on two different raspberries - my zero got into swapping hell) to clone the repo).

How do I fix points 1 through 6? Or is that something you can do? Or do I scrap this PR, scrap my forked & cloned copy of the repo and try again.

Rgds, Dougie

@pelwell
Copy link
Contributor

pelwell commented Jul 29, 2020

I've got a new version of this PR that I hope to share tomorrow.

@pelwell
Copy link
Contributor

pelwell commented Jul 30, 2020

I've pushed an update - can you take a look? The overlay name has changed to maxtherm, and the device name is passed as a parameter to select the correct compatible string. You'll also notice that for the 31855 variants I've given the vanilla "maxim,max31855" as a fallback compatible string so it could be used before the 5.7 - let me know if that is at all useful.

I've tested it to the extent that all the parameters decode and apply correctly, and the README follows the rules, but some confirmation that it still works in one or two combinations would be great.

Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

Signed-off-by: Phil Elwell <[email protected]>
@DougieLawson
Copy link
Author

Thanks Phil.

I'll drag the stuff down to my Zero with the thermocouples and give it a test drive.

@DougieLawson
Copy link
Author

Your overlay is working. I ran rpi-update to get #1330. Then updated my config.txt with

dtdebug=1
dtparam=audio=on
gpu_mem=16
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=81
dtoverlay=maxtherm,spi0-1,max6675
dtoverlay=maxtherm,spi0-0,max31855
dtparam=spi=on
dtparam=i2c_arm=on
disable_splash=1

Rebooted, and ran

#!/usr/bin/python3

# max31855 spi0-0
# /sys/bus/iio/devices/iio:device0/in_temp_scale
# /sys/bus/iio/devices/iio:device0/in_temp_raw
# max6675 spi0-1
# /sys/bus/iio/devices/iio:device1/in_temp_scale
# /sys/bus/iio/devices/iio:device1/in_temp_raw

from time import sleep
while True:
    with open('/sys/bus/iio/devices/iio:device0/in_temp_scale', 'r') as dev0scale:
                scale0 = float(dev0scale.read())

    with open('/sys/bus/iio/devices/iio:device0/in_temp_raw', 'r') as dev0raw:
                raw0 = float(dev0raw.read())
                dev0temp = (scale0 * raw0) / 1000.0


    with open('/sys/bus/iio/devices/iio:device1/in_temp_scale', 'r') as dev1scale:
                scale1 = float(dev1scale.read())

    with open('/sys/bus/iio/devices/iio:device1/in_temp_raw', 'r') as dev1raw:
                raw1 = float(dev1raw.read())
                dev1temp = (scale1 * raw1) / 1000.0

    print ("Max31855: ", dev0temp)
    print ("Max6675: ", dev1temp)
    sleep(2)

That gets

pi@viking:~/python/thermo$ ./readIIO.py
Max31855:  29.25
Max6675:  28.0
Max31855:  29.25
Max6675:  28.0
Max31855:  29.25
Max6675:  27.75
Max31855:  29.25
Max6675:  28.0
Max31855:  29.25
Max6675:  28.0
Max31855:  29.25
Max6675:  28.25
^CTraceback (most recent call last):
  File "./readIIO.py", line 29, in <module>
    sleep(2)
KeyboardInterrupt
pi@viking:~/python/thermo$

So a massive thank you for fixing my wonky attempt at a pull request.

pelwell pushed a commit that referenced this pull request Jul 30, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
@pelwell
Copy link
Contributor

pelwell commented Jul 30, 2020

Merged manually.

@pelwell pelwell closed this Jul 30, 2020
@DougieLawson DougieLawson deleted the patch-1 branch July 31, 2020 07:30
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jul 31, 2020
See: raspberrypi/linux#3765

kernel: overlays: Delete spi0-hw-cs
See: raspberrypi/linux#3355

kernel: backlight: gpio: Explicitly set the direction of the GPIO
See: raspberrypi/linux#3767

kernel: overlays: Add maxtherm overlay for MAX6675/31855
See: raspberrypi/linux#3763

firmware: arm_loader: Knock 1.7 seconds off boot time
See: #1375

firmware: Imx477 external sync signals
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jul 31, 2020
See: raspberrypi/linux#3765

kernel: overlays: Delete spi0-hw-cs
See: raspberrypi/linux#3355

kernel: backlight: gpio: Explicitly set the direction of the GPIO
See: raspberrypi/linux#3767

kernel: overlays: Add maxtherm overlay for MAX6675/31855
See: raspberrypi/linux#3763

firmware: arm_loader: Knock 1.7 seconds off boot time
See: raspberrypi/firmware#1375

firmware: Imx477 external sync signals
@popcornmix
Copy link
Collaborator

This is in latest rpi-update kernel

pelwell pushed a commit that referenced this pull request Aug 12, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 12, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
pelwell pushed a commit that referenced this pull request Aug 18, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 19, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Aug 19, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 1, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 1, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 11, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 15, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Sep 28, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Oct 2, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Oct 7, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Oct 16, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Oct 19, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
popcornmix pushed a commit that referenced this pull request Nov 4, 2020
Add an overlay - maxtherm - to support the MAX6675 and MAX31855 family
of thermocouples.

Developed from an original set of overlays by Dougie Lawson.

See: #3763

Signed-off-by: Phil Elwell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants