The LMT01 is a simple and accurate temperature sensor that does not require calibration which communicates the ambient temperature with current pulses, where the number of current pulses in a set indicates the current temperature. zeptoforth, specifically lmt01_test.fs, is used to process the temperature read by one to three LMT01's and convert them into human-readable values in degrees Celsius or degrees Fahrenheit.

These current pulses are converted with an NPN transistor and current pulses into voltage pulses which can be detected by a GPIO on the STM32F407. Note that the current code assumes that the output of the setup transmitting these voltage pulses is tied to PE2 on the STM32F407, which can be changed with source code changes to lmt01_test.fs. Note that one should use the latest source code in GitHub, as the code in the latest release tarball is not up to date.

The voltage pulses generated by the hardware setup, using the EXTI functionality of the STM32F407, are detected as falling edges which trigger interrupts. These interrupts increment a counter during a time window during which a LMT01 is enabled (by setting a GPIO pin, in this setup hard-coded to PE3, for sensor zero, PE4, for sensor one, and PE5, for sensor two, to output and high) is read as a temperature. These pins are tied to the VP pins on the LMT01 sensors accordingly, and can be reconfigured by editing the source of lmt01_test.fs. The formula for converting edge counts into a temperature is (pulse count / 16.0) - 50.0, which gets a temperature in degrees Celsius. Of course, to get a temperature from that in degrees Fahrenheit one does (°C * 1.8) + 32.0.

Using a temperature sensor to detect the ambient temperature, once the hardware is set up and zeptoforth 0.16.2 or later is installed on the STM32F407 DISCOVERY board one is using involves loading test/common/lmt01_test.fs onto the STM32F407 DISCOVERY board. If one is using serial to communicate, one can load it with one's chosen terminal emulator (115200 baud, and make sure to slow down each line's being loaded to give the MCU a chance to compile the last line loaded) or, if one has Python 3 and pySerial installed and is using a Unix-like OS, one can use codeload3.py (included with zeptoforth) to load it in a less tedious and error-prone fashion, as in:

$ utils/codeload3.py -p  -B 115200 serial test/common/lmt01_test.fs 

executed from the base directory containing zeptoforth, where <device file> is a device file for the serial dongle one is using (most likely /dev/ttyUSB0 or /dev/ttyACM0). If one is using swdcom (can be gotten from https://github.com/crest/swdcom), which enables one to use ST-Link to provide a terminal , which is recommended, execute the following:

$ cat test/common/lmt01_test.fs > <base dir>/upload.fs && pkill -QUIT swd2 

where <base dir> is the current directory when swd2 was executed.

Once this is complete simply execute the following, for a setup with three temperature sensors. import temp-module imports the LMT01 temperature sensor test into the current namespace. init-temp inititalizes the LMT01 temperature sensor test. read-temp-c, read-temp-f, and read-temp take a temperature sensor index, from zero to two, and outputs a temperature, in double-cell S31.32 fixed point format for read-temp-c and read-temp-f (as degrees Celsius and degrees Fahrenheit respectively), which needs f. to be printed, and as a number of pulses received as a single-cell unsigned integer for read-temp.

import temp-module  ok
init-temp  ok
0 read-temp-c f.  21,3125 ok
1 read-temp-c f.  21,5 ok
2 read-temp-c f.  21,3125 ok
0 read-temp-f f.  70,3624999958 ok
1 read-temp-f f.  70,6999999959 ok
2 read-temp-f f.  70,3624999958 ok
0 read-temp .  1141 ok
1 read-temp .  1144 ok
2 read-temp .  1141 ok 

Note that the "ok"s and the numbers preceding them are output by zeptoforth and not input by the user.

Using a setup with one temperature sensor is similar, and looks like:

import temp-module  ok
init-temp  ok
0 read-temp-c f.  21,3125 ok
0 read-temp-f f.  70,3624999958 ok
0 read-temp .  1141 ok 

Note that if one attempts to read from a nonexistent LMT01 sensor, an exception is raised.

A facility is provided to repeatedly read sensor data from one or more sensors, as seen in:

import temp-module  ok
init-temp  ok
3 start-display-temps  ok

Temperature 0: 1231 pulses 26,9375 °C 80,4874999949 °F
Temperature 1: 1228 pulses 26,75 °C 80,1499999950 °F
Temperature 2: 1231 pulses 26,9375 °C 80,4874999949 °F
Temperature 0: 1231 pulses 26,9375 °C 80,4874999949 °F
Temperature 1: 1228 pulses 26,75 °C 80,1499999950 °F
Temperature 2: 1231 pulses 26,9375 °C 80,4874999949 °F
Temperature 0: 1231 pulses 26,9375 °C 80,4874999949 °F
Temperature 1: 1228 pulses 26,75 °C 80,1499999950 °F
Temperature 2: 1231 pulses 26,9375 °C 80,4874999949 °F

The number before start-display-temps is the number of sensors to read data from. To read data from a single sensor, one can execute:

import temp-module  ok
init-temp  ok
1 start-display-temps  ok

Temperature 0: 1230 pulses 26,875 °C 80,3749999948 °F
Temperature 0: 1230 pulses 26,875 °C 80,3749999948 °F
Temperature 0: 1230 pulses 26,875 °C 80,3749999948 °F
Temperature 0: 1230 pulses 26,875 °C 80,3749999948 °F