From 6281f36662a1a13b49d90074d195defb11dce6ff Mon Sep 17 00:00:00 2001 From: John Hobbs Date: Wed, 12 Feb 2025 17:10:32 -0600 Subject: [PATCH] MAX6675 example & smoke test --- examples/max6675/main.go | 34 ++++++++++++++++++++++++++++++++++ smoketest.sh | 1 + 2 files changed, 35 insertions(+) create mode 100644 examples/max6675/main.go diff --git a/examples/max6675/main.go b/examples/max6675/main.go new file mode 100644 index 0000000..b583088 --- /dev/null +++ b/examples/max6675/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "machine" + "time" + + "tinygo.org/x/drivers/max6675" +) + +// example for reading temperature from a thermocouple +func main() { + // Pins are for an Adafruit Feather nRF52840 Express + machine.D5.Configure(machine.PinConfig{Mode: machine.PinOutput}) + machine.D5.High() + + machine.SPI0.Configure(machine.SPIConfig{ + Frequency: 1_000_000, + SCK: machine.SPI0_SCK_PIN, + SDI: machine.SPI0_SDI_PIN, + }) + + thermocouple := max6675.NewDevice(machine.SPI0, machine.D5) + + for { + temp, err := thermocouple.Read() + if err != nil { + println(err) + return + } + fmt.Printf("%0.02f C : %0.02f F\n", temp, (temp*9/5)+32) + time.Sleep(time.Second) + } +} diff --git a/smoketest.sh b/smoketest.sh index 50a6440..eec70b1 100755 --- a/smoketest.sh +++ b/smoketest.sh @@ -139,6 +139,7 @@ tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/mai tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/tmc2209/main.go tinygo build -size short -o ./build/test.hex -target=pico ./examples/tmc5160/main.go tinygo build -size short -o ./build/test.uf2 -target=nicenano ./examples/sharpmem/main.go +tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/max6675/main.go # network examples (espat) tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/ # network examples (wifinina)