B4R Question [SOLVED] MAX6675 & esp8266 anyone?

giggetto71

Active Member
Licensed User
Longtime User
Hi,
does anyone have successfully connected a MAX6675 thermocouple board with a esp8266 (nodemcu or wemos)? I know that there is an arduino library but looking at the community that lib has not been wrapped yet. I have also seen that that the board can communicate over spi so I was tempted to make a test with the existing rSPI library but I never played with spi so I was wondering if anyone has anything I could start from.
thanks!
 

thetahsk

Active Member
Licensed User
Longtime User
First install the adafruit lib from here
https://github.com/adafruit/MAX6675-library and adapt D0,CS and CLK according to your board.

For the MAX6675 to update, you must delay AT LEAST 250ms between reads, use a timer or use CallSubPlus.

B4X:
Sub Process_Globals
    Public Serial1 As Serial
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Dim tc_f As Float = RunNative("read_tc_f",Null)
    '// For the MAX6675 to update, you must delay AT LEAST 250ms between reads!
    Dim tc_c As Float = RunNative("read_tc_c",Null)
    Log("Temp:[C]: ",tc_c)
    Log("Temp:[F]: ",tc_f)
End Sub

#if C
#include "max6675.h"

int thermoDO = 4;int thermoCS = 5;int thermoCLK = 6;
B4R::Object res;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);

B4R::Object* read_tc_f (B4R::Object* o) {
   return res.wrapNumber(thermocouple.readFahrenheit());
}

B4R::Object* read_tc_c (B4R::Object* o) {
   return res.wrapNumber(thermocouple.readCelsius());
}
#End if
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
thanks @thetahsk ! this really looks what I need! did not have time to test as I was out for work this week but as usual great support!
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Just to share in addition to the Inline C solution, a wrapped MAX6675 library rMAX6675 which I am using for Home Automation Solution reading the Heating Flow Temperature with PT100.

Example:
'This basic example reads the thermosensor every 10 seconds and logs the temperature in C. Tested with Arduino UNO.
Sub Process_Globals
    Public serialLine As Serial
    'MAX6675
    Private maxx As MAX6675
    Private PINSCK As Byte = 10
    Private PINCS As Byte = 9
    Private PINSO As Byte = 8
    'Timer for reading
    Private timerRead As Timer
    Private READ_INTERVAL As ULong = 10000
End Sub

Private Sub AppStart
    serialLine.Initialize(115200)
    maxx.Initialize(PINSCK, PINCS, PINSO)
    timerRead.Initialize("TimerRead_Tick", READ_INTERVAL)
    timerRead.Enabled = True
    TimerRead_Tick
End Sub

Sub TimerRead_Tick
    'Temperature=20.7 Celsius
    Log("Temperature=", NumberFormat(maxx.ReadCelsius, 0, 1), " Celsius")
End Sub
 

Attachments

  • rMAX6675-100.zip
    7.6 KB · Views: 210
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
thanks. just one (stupid) question. the above zip does contain the xml file. Did I miss something ?
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
thanks, but I guess I need some more help...
I have tried several combination of pins but I still get NaN from the ReadCelsius function.

Temperature=nan Celsius


the pin mapping that I am trying with the Wemos R1 Mini is the following:

SCK pin -> D5 (GPIO 14 / SCLK)
CS pin -> D8 (GPIO 15 / CS)
SO pin -> D6 (GPIO 12/ MISO)

I am assuming that the library needs the GPIO number so I am using 14,15,12.
Any clue?
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Tested on a WeMOS D1 Mini:

Wiring:
MAX6675 = WeMOS D1 Mini
GND = GND
VCC = 5v
SCK = Pin D5 (GPIO14)
CS  = Pin D6 (GPIO12)
SO  = Pin D7 (GPIO13)
Thermosensor: RED = +, BLUE = -

B4X:
Sub Process_Globals
    Public serialLine As Serial
    Private maxx As MAX6675
    Private PINSCK As Byte    = 14    'GPIO14 = Pin D5 
    Private PINCS As Byte    = 12    'GPIO12 = Pin D6
    Private PINSO As Byte    = 13    'GPIO13 = Pin D7
    Private timerRead As Timer
    Private READ_INTERVAL As ULong = 5000
End Sub

Private Sub AppStart
    serialLine.Initialize(115200)
    maxx.Initialize(PINSCK, PINCS, PINSO)
    timerRead.Initialize("TimerRead_Tick", READ_INTERVAL)
    timerRead.Enabled = True
    TimerRead_Tick
End Sub

Sub TimerRead_Tick

    Log("Temperature=", NumberFormat(maxx.ReadCelsius, 0, 1), " Celsius")
End Sub
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
Ok. I just found an issue with the ground pin badly soldered. Most probably i was not powering the max6675 board..later i will try again. Thank you very much for testing with the wemos. Appreciate it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…