{"id":806,"date":"2022-03-08T13:49:13","date_gmt":"2022-03-08T13:49:13","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=806"},"modified":"2022-03-08T13:49:15","modified_gmt":"2022-03-08T13:49:15","slug":"working-with-stm32-and-sensors-thermocouple-typek","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=806","title":{"rendered":"Working with STM32 and Sensors: Thermocouple TypeK"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/assets.omega.com\/resources\/how-thermocouples-work-1.jpg\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall take a look at the thermocouple and how this type of sensor works and use MAX6675 thermocouple to measure the temperature.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Thermocouple typeK<\/li><li>MAX6675.<\/li><li>Connection MAX6675 with STM32.<\/li><li>Code.<\/li><li>Result<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Thermocouple:<\/h2>\n\n\n\n<p>Type K Thermocouple provides widest operating temperature range. It consist of positive leg which is non-magnetic and negative leg which is magnetic.In K Type Thermocouple &nbsp;traditional base metal is used due to which it can work at high temperature and can provide widest operating temperature range. One of the constituent metal in K Type Thermocouple is&nbsp;Nickel, which is magnetic in nature.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/496721-1574127-3-raikfcquaxqncofqfm.stackpathdns.com\/pub\/media\/blog\/k-type-thermocouples.jpg\" alt=\"K Type Thermocouple\" \/><\/figure><\/div>\n\n\n\n<p>The characteristic shown by K Type Thermocouple is that they undergo a deviation in output when magnetic material reaches its Curie Point, at around &nbsp;185 \u00b0C. K Type &nbsp;thermocouple &nbsp;work very well in oxidizing atmosphere at temperatures up to 1260\u00b0C (2300\u00b0F) and its tolerance class is \u00b1 1.5 K between -40 and 375 \u00b0C.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/496721-1574127-3-raikfcquaxqncofqfm.stackpathdns.com\/pub\/media\/images\/image_2021_01_22T06_17_12_860Z.png\" alt=\"Type K Thermocouple International Color Code \" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Why To prefer K Type Thermocouple<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>One of the major advantage of K type thermocouple over other thermocouple&#8217;s is it can function in rugged environmental condition &amp; in various atmospheres<\/li><li>It has integrated composition of Chromel and Alumel wires has a range of -270 \u00b0C to 1260\u00b0C&nbsp;and&nbsp;an&nbsp;output&nbsp;of&nbsp;-6.4&nbsp;to&nbsp;9&nbsp;mV&nbsp;over&nbsp;maximum&nbsp;temperature&nbsp;range.<\/li><li>Also known as general purpose thermocouple due to its wide range of&nbsp; temperature<\/li><li>Type K has a longer life than Type J as in Type J Fe (iron) wire oxidizes rapidly, especially at higher temperature<\/li><li>They are inexpensive.<\/li><li>Have a fast response<\/li><li>Small in size and are reliable.<\/li><li>Generally used at temperatures above 540 degrees C<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Composition of K Type Thermocouple<\/h3>\n\n\n\n<p>In K Type Thermocouple positive leg is composed of 90% nickel, 10%chromium and a negative leg is composed of 95% nickel, 2% aluminum, 2% manganese and 1% silicon. These are the most common general purpose thermocouple with a sensitivity of approx 41\u00b5V\/\u00b0C.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Type K Insulation Material<\/h4>\n\n\n\n<p>In Type K Thermocouple mainly two type of insulation is used firstly Ceramic beads &nbsp;insulation is used as it is a lightweight insulating product. It is made from high purity alumino-silicate materials. It has low thermal mass which means that it does not retain heat, low thermal conductivity and is an extremely effective insulation material as it can withstand high&nbsp;temperature&nbsp;of&nbsp;1260&nbsp;\u00b0C&nbsp;so&nbsp;it&nbsp;it&nbsp;best&nbsp;suited&nbsp;material&nbsp;for&nbsp;Type&nbsp;K&nbsp;thermocouple.<\/p>\n\n\n\n<p>Secondly compacted mineral insulation and outer metal sheath (MgO) is used. Magnesium Oxide has a high dielectric strength, responds quickly to temperature changes and is very durable. It has typical Composition of the Standard Quality MgO (97%) and the High Purity MgO and AI2O3.<\/p>\n\n\n\n<p>Magnesium Oxide insulation is recommended for K Type thermocouple when Thermocouple are to be immersed in liquids, high moisture, corrosive gases or high pressures. The thermocouple can be formed to reach otherwise inaccessible areas.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/496721-1574127-3-raikfcquaxqncofqfm.stackpathdns.com\/pub\/media\/blog\/type-k-thermocouple-tolerance-class.jpg\" alt=\"Type K Thermocouple Tolerance Class\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Temperature Range<\/h3>\n\n\n\n<p>To find appropriate range of thermocouple we should use appropriate wire because different wires measure various temperature ranges. Of the four major thermocouple types, type K covers the widest range :<em>&#8211;<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Thermocouple grade wire, \u2013454 to 2,300F (\u2013270 to1260\u00b0C)<\/li><li>Extension wire, 32 to 392F (0 to200\u00b0C)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Accuracy (whichever is greater)<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Standard: +\/- 2.2\u00b0C or +\/-.75%<\/li><li>Special Limits of Error: +\/<em>&#8211;&nbsp;<\/em>l\u00b0C or0.4%<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Tolerance Class<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/496721-1574127-3-raikfcquaxqncofqfm.stackpathdns.com\/pub\/media\/blog\/type-k-insulation-material.jpg\" alt=\"Type K Insulation Material\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">EMF Vs Temperature Graph for K Type Thermocouple<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/496721-1574127-3-raikfcquaxqncofqfm.stackpathdns.com\/pub\/media\/blog\/emf-temperature-graph-k-type-thermocouple.jpg\" alt=\"EMF Vs Temperature Graph for K Type Thermocouple\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Pros And Cons:<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Pros<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>To measure temperature it provide good linearity of emf<\/li><li>It provide good resistance aganist oxidation below 1000 \u00b0C(1600\u00b0F).<\/li><li>Highly stable output<\/li><li>Comparitively cost effective than other thermocouple.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Cons<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Not suitable for reducing atmosphere but can withstand metallic<\/li><li>Aging of the emf characteristic, when compared to noble metal thermocouples (B, R, andS).<\/li><li>Not suitable for vacuum applications due to vaporization of chromium in the positive element.<\/li><li>Green-Rotis phenomenon may occur due to low oxygen level for the thermocouples which are used between 815\u00b0C to 1040\u00b0C (1500\u00b0F to1900\u00b0F).<\/li><li>Type K thermocouples should not be used in Sulphuric environment since both elements will rapidly corrode and the negative element will eventually fail mechanically due to becoming brittle.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Uses of K Type Thermocouple<\/h3>\n\n\n\n<p>They are mostly used for applications at temperatures above 550 \u00b0C up to the maximum working pressure of the thermocouple.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They are used in many industries like Steel &amp; Iron to monitor temperature &amp; chemistry through out the steel making process<\/li><li>Used for testing temperatures associated with process plants e.g. chemical production and petroleum refineries<\/li><li>Used for Testing of heating appliance safety<\/li><li>Type K is commonly used in nuclear applications because of its relative radiation hardness.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. MAX6675:<\/h2>\n\n\n\n<p>The MAX6675 performs cold-junction compensation and digitizes the signal from a type-K thermocouple. The data is output in a 12-bit resolution, SPI-compatible, read-only format.<\/p>\n\n\n\n<p>This converter resolves temperatures to 0.25\u00b0C, allows readings as high as +1024\u00b0C, and exhibits thermocouple accuracy of 8 LSBs for temperatures ranging from 0\u00b0C to +700\u00b0C.<\/p>\n\n\n\n<p><strong>Applications<\/strong><\/p>\n\n\n\n<p>\u25cf&nbsp;Industrial&nbsp;\u25cf&nbsp;Appliances&nbsp;\u25cf&nbsp;HVAC<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Features<\/strong><\/p>\n\n\n\n<p>\u25cf&nbsp;Direct Digital Conversion of Type -K Thermocouple Output<\/p>\n\n\n\n<p>\u25cf&nbsp;Cold-Junction Compensation<br>\u25cf&nbsp;Simple SPI-Compatible Serial Interface&nbsp;\u25cf&nbsp;12-Bit, 0.25\u00b0C Resolution<br>\u25cf&nbsp;Open Thermocouple Detection<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pin Configuration:<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"677\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-1024x677.png\" alt=\"\" class=\"wp-image-807\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-1024x677.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-300x198.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-768x508.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-750x496.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-400x264.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-250x165.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM.png 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Typical connection:<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"754\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-1024x754.png\" alt=\"\" class=\"wp-image-808\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-1024x754.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-300x221.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-768x566.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-750x553.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-400x295.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-250x184.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As seen, it requires minimal external components to make the converter works with our STM32.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Serial Output of MAX6675:<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1024x288.png\" alt=\"\" class=\"wp-image-809\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1024x288.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-300x84.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-768x216.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1536x432.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-2048x576.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1150x323.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-750x211.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-400x112.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-250x70.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As seen from the picture, the converter requires CLK, CS and SO.<\/p>\n\n\n\n<p>This can be achieved with software level.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Connection MAX6675 with STM32:<\/h2>\n\n\n\n<p>In this guide, we shall use OLED SSD1306 I2C to display the temperature (code from <a href=\"https:\/\/blog.embeddedexpert.io\/?p=613\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/?p=613\"> <\/a><a href=\"https:\/\/blog.embeddedexpert.io\/?p=613\" target=\"_blank\" rel=\"noreferrer noopener\">topic<\/a>)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"548\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-1024x548.png\" alt=\"\" class=\"wp-image-810\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-1024x548.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-300x161.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-768x411.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-1536x823.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-1150x616.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-750x402.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-400x214.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.25.59-PM-250x134.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-regular\"><table><tbody><tr><td>MAX6675<\/td><td>STM32F411<\/td><\/tr><tr><td>SCK<\/td><td>PA5<\/td><\/tr><tr><td>SO<\/td><td>PA6<\/td><\/tr><tr><td>CS<\/td><td>PA9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p>We start of by creating header file named MAX6675.h and the following the code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef __MAX6675__h\n#define __MAX6675__h\n#include &quot;stdint.h&quot;\n#define NAN \t\t -1000\nvoid max6675_init(void);\nfloat ReadMAX6675_C(void);\nfloat ReadMAX6675_F(void);\n\n#endif<\/pre><\/div>\n\n\n\n<p>For MAX6675.c as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;max6675.h&quot;\n#include &quot;stm32f4xx.h&quot;                  \/\/ Device header\n#include &quot;delay.h&quot;\n#include &quot;stdlib.h&quot;\n#include &quot;stdio.h&quot;\n\n#define SCK_HIGH GPIOA-&gt;BSRR=GPIO_BSRR_BS5\n#define SCK_LOW  GPIOA-&gt;BSRR=GPIO_BSRR_BR5\n\n#define CS_HIGH GPIOA-&gt;BSRR=GPIO_BSRR_BS9\n#define CS_LOW  GPIOA-&gt;BSRR=GPIO_BSRR_BR9\n\nstatic uint8_t read_sensor()\n\t{\n\tint i;\n  uint8_t d = 0;\nfor (i = 7; i &gt;= 0; i--) {\n    SCK_LOW;\n   delayuS(10);\n    if (GPIOA-&gt;IDR &amp;GPIO_IDR_ID6) {\n      \/\/ set the bit to 0 no matter what\n      d |= (1 &lt;&lt; i);\n    }\n\n    SCK_HIGH;\n    delayuS(10);\n  }\n\n  return d;\n\t\n\t}\n\n\nvoid max6675_init(void)\n\t{\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE5_0|GPIO_MODER_MODE9_0;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE5_1|GPIO_MODER_MODE9_1|GPIO_MODER_MODE6_0|GPIO_MODER_MODE6_1);\n\tCS_HIGH;\n\t}\n\t\nfloat ReadMAX6675_C(void)\n\t{\n\tuint16_t v;\n\tfloat temp;\n\tCS_LOW;\n\tv = read_sensor();\n  v &lt;&lt;= 8;\n  v |= read_sensor();\n\tCS_HIGH;\n\t\tif (v &amp; 0x4) {\n    \/\/ uh oh, no thermocouple attached!\n    return NAN;\n    \/\/ return -100;\n  }\n\n  v &gt;&gt;= 3;\n\n\ttemp=v*0.20;\n  return temp ;\n\t\n\t}\nfloat ReadMAX6675_F(void) { return (ReadMAX6675_C() * 9.0 \/ 5.0 + 32); }<\/pre><\/div>\n\n\n\n<p>In the main function,<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;oled.h&quot;\n#include &quot;test.h&quot;\n#include &quot;bitmap.h&quot;\n#include &quot;horse_anim.h&quot;\n#include &quot;stdio.h&quot;\n#include &quot;MAX6675.h&quot;\n\n\nfloat temperature;\nextern void SysClockConfig(void);\nint main(void)\n{\nSysClockConfig();\nSSD1306_Init();\nmax6675_init();\n\n\nwhile(1)\n{\n\tchar data[30];\n\ttemperature=ReadMAX6675_C();\n\tSSD1306_Clear();\n\tsprintf(data,&quot;%0.1f     &quot;,temperature);\n\tSSD1306_GotoXY(0,0);\n\tSSD1306_Puts(data,&amp;Font_11x18, 1);\n\tSSD1306_UpdateScreen();\n\tdelay(1000);\n\t\n}\n\n\n}<\/pre><\/div>\n\n\n\n<p>You may download the code from <a rel=\"noreferrer noopener\" href=\"https:\/\/www.dropbox.com\/s\/69fzjrei3pwcsvm\/MAX6675.zip?dl=0\" data-type=\"URL\" data-id=\"https:\/\/www.dropbox.com\/s\/69fzjrei3pwcsvm\/MAX6675.zip?dl=0\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5.Results:<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"83\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-1024x83.png\" alt=\"\" class=\"wp-image-811\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-1024x83.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-300x24.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-768x62.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-1536x125.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-2048x167.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-1150x94.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-750x61.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-400x33.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.43.21-PM-250x20.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"83\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-1024x83.png\" alt=\"\" class=\"wp-image-812\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-1024x83.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-300x24.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-768x62.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-1536x125.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-2048x167.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-1150x94.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-750x61.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-400x33.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.42.45-PM-250x20.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>It seems my OLED is no longer functioning correctly for one reason or another. However, if you run the code, it should display the temperature on the OLED.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall take a look at the thermocouple and how this type of sensor works and use MAX6675 thermocouple to measure the temperature. In this guide, we shall cover the following: Thermocouple typeK MAX6675. Connection MAX6675 with STM32. Code. Result 1. Thermocouple: Type K Thermocouple provides widest operating temperature range. It consist [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-806","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/806"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=806"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions"}],"predecessor-version":[{"id":814,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions\/814"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}