#embedded-hal-driver #temperature #thermocouple #max6675

no-std max6675-hal

An embedded-hal driver for the MAX6675 digital thermocouple converter

3 releases (1 stable)

1.0.0 May 2, 2024
1.0.0-rc.1 Feb 2, 2024
0.4.0 May 1, 2024
0.3.1 Dec 20, 2023

#304 in Embedded development

Download history 4/week @ 2024-01-31 6/week @ 2024-02-14 22/week @ 2024-02-21 13/week @ 2024-02-28 2/week @ 2024-03-13 10/week @ 2024-03-27 20/week @ 2024-04-03 246/week @ 2024-05-01

246 downloads per month

MIT license

17KB
110 lines

max6675-hal

license badge docs.rs badge crates.io badge GitHub badge GitHub Actions badge

An embedded-hal driver for the MAX6675 digital thermocouple converter.

Usage

This example code will change depending on which HAL device driver you're using. An arduino-hal project's SPI isn't like that of an esp32-hal project.

However, you only have to focus on two parts:

  1. A CS (chip select) pin as an OutputPin
  2. Some SPI representation that doesn't exclusively own the CS pin (I'm looking at you, linux-embedded-hal!)

Your SPI settings should use MSB (most significant bit) first, target a clock speed of at least 4mhz, and utilize SPI Mode 1.

After both are good, pass them into the Max6675::new(spi, chip_select) constructor. Ta-da! Your MAX6675 gets put to good use.

// first, define what pins you're connecting to
let so_pin = pins.("your miso pin").into_pull_up_input();
let cs_pin = pins.("your cs pin").into_output();
let sck_pin = pins.("your sck/clock pin").into_output();

// you may need a mosi pin for your device's SPI, though the max6675 doesn't use one.
// if so, just pick some pin that you're not using ☺️
let dummy_mosi = pins.("some pin you're not using").into_output();

let (spi, cs) = device-hal::spi::Spi::new(
    sck_pin, dummy_mosi, so_pin, cs_pin,
    device-hal::spi::Settings {
        // pick some settings that roughly align like so:
        data_order: MostSignificantFirst,
        clock: 4MhzClockSpeed,
        mode: embedded_hal::spi::MODE_1,
    }
);
let mut max = Max6675::new(spi, cs)?; // your spi and chip select here

let temp = max.read_celsius()? // ayo! we got the temperature

Contributions

Contributions are welcome to this project! Since it's pretty small, feel free to submit a PR whenever. You can also make an issue - I'll likely get to it soon!

Help

Please don't hesitate to make an issue if you experience any problems!

If you can, please submit a hw-probe report alongside any error messages or useful logs you have!

Dependencies

~1.5MB
~37K SLoC