MAX6675

#1
Evening all I have a question (don't we all)

I've used these MAX6675 thermocouple modules before but only on there own i.e 1 MAX6675 to 1 Picaxe chip. My question is, is it possible to run more than one as in address them or is it 1 on 1 as they are serial?
 

Pongo

Senior Member
#2
You can parallel the serial connection SCK and SO of multiple devices, and select the one you are addressing by setting the Chip Select (CS) pin of only that device LOW, and set the others HIGH. So for e.g. 3 devices you would need 5 pins on the picaxe, SCK, SO, CS #1, CS #2, CS #3. If you had a whole lot of MAX6675's you could use a binary decoder chip for the chip selects to minimize the number of picaxe pins needed.
 
#3
I get you. It might be better if I find something else, possibly an i2c thermocouple device if there is a thing.

Thanks for your reply.
 

hippy

Technical Support
Staff member
#4
If you cannot find an I2C version; one option is to use an 08M2 to do the reading and send that via serial to your main PICAXE. By using bit-banged SPI you should be able to handle three sensors with an 08M2 -
Code:
                 .-------.
 SO |--------.-->| I5 O0 |--->
 CK |----.  .|,  |       |
/CS |--. |  |_|  |       |
       | |  _|_  |       |
       | |       |       |
 SO |--|-|------>| X4    |
 CK |--|-{  -.-  |       |
/CS |--{ |  .|.  |       |
       | |  |_|  |       |
       | |   |   |       |
 SO |--|-|---|-->| I3    |
 CK |--|-^---|--<| X2    |
/CS |--^-----^--<| X1    |
                 `-------'
 
#5
Hi Hippy,

So you mean I could have several 08M2's each with 3 MAX6675 and then have them (some how) send there temp data to a Master? Interesting idea, this bit-bang stuff is a bit above me so will have to find some reading.
 
#6
Attached it the code of a single MAX6675 running on a 14M2 and displaying the temp over sertxt to the PE6 editor and it works fine. Im ok with setting up different output pins for the individual MAX6675 CS pins but how do you store/read the MISO and keep the data separate if all on the same input pin?
Then how would you send all the data back to a master and know which one your looking at?
Anything to put me in the right direction.
 

Attachments

Pongo

Senior Member
#7
Basically you would set all CS high, set CS #1 low, take a reading and store as temp1, Set CS #1 high, set CS #2 low, take a reading and store as temp2, Set CS #2 high, set CS #3 low, take a reading and store as temp3.
 

hippy

Technical Support
Staff member
#8
So you mean I could have several 08M2's each with 3 MAX6675 and then have them (some how) send there temp data to a Master?
That is correct. Though if you have more than three sensors it's probably better to use a PICAXE which can handle all sensors so there's only one signal going back to the master PICAXE.

Interesting idea, this bit-bang stuff is a bit above me so will have to find some reading.
I have included some code at the end, which is pretty similar to your own code, though untested..

Because I parallel CS and CK to all MAX6675 chips one can read the data from all sensors when CK is high and that data can be stored in its own word variable.

Then how would you send all the data back to a master and know which one your looking at?
You can send data back with -

SEROUT <pin>, <baud>, ( "T=", #w1, COMMA, #w2, COMMA, #w3, CR, LF )

And then read that on the master PICAXE with -

SERIN <pin>, <baud>, ( "T=" ), #w1, #w2, #w3

Code:
#Picaxe 08M2
#Terminal 4800
#No_Data

Symbol TX        = C.0
Symbol CS        = C.1
Symbol CK        = C.2

Symbol MAX6675_1 = pinC.3
Symbol MAX6675_2 = pinC.4
Symbol MAX6675_3 = pinC.5

Symbol COMMA = ","

Init:
  High CS
  Low  CK
  Pause 100

Main:
  Do
    Gosub ReadSensors
    SerOut TX, N4800,( "T=", #w1, COMMA, #w2, COMMA , #w3, CR, LF )
    Pause 1000
  Loop

ReadSensors:
  Low  CS
  For b0 = 15 To 0 Step -1
    High CK
    w1 = w1 * 2 + MAX6675_1
    w2 = w2 * 2 + MAX6675_2
    w3 = w3 * 2 + MAX6675_3
    Low CK
  Next
  High CS
  w1 = w1 / 32
  w2 = w2 / 32
  w3 = w3 / 32
  Return
 
#9
Pongo, Hippy thank you both for your tie on this, you given me a shove in the right direction and a good start for me to work from. I may be back in the future though haha.
 

Pongo

Senior Member
#11
Yes, you could.

How many sensors do you need?

If you used a 74HC138 3 to 8 line decoder to drive the CS lines you could run 8 thermocouples with a total of 5 picaxe pins.
 
Last edited:
#12
I'm un sure as yet but thinking of building a heating control/monitor for a central heating system I'm putting in. There's a large thermal store in the roof with solar tubes on the roof, a 12kw wood burner/boiler in the living room and a gas boiler and electric immersion as backups. The store will do the heating and hot water.

So the long term project is to have temp sensors local to the wood burner and gas boiler flow/return pips and in places on the tank, it would all then be displayed on a nextion touch screen.
 

lbenson

Senior Member
#13
... So the long term project is to have temp sensors local to the wood burner and gas boiler flow/return pipes and in places on the tank, it would all then be displayed on a nextion touch screen.
I use these waterproof DS18B20s strapped to boiler hot water supply and return pipes for 3 zones, with heat sink compound:
https://www.ebay.com/itm/10K1-3950-...mal-Probe-Waterproof-Probe-1M-2M/142721776571

I tried taping them with aluminum tape (for hot air systems), but the glue melted. Now I use hose clamps or tuck them inside the insulating foam which wraps the pipes in the basement.
 

hippy

Technical Support
Staff member
#14
If I didn't need all of my sensors to be high temp thermocouples I take it I could use DS18B20 temp sensors each with there own input?
Yes, and if you use an X2 PICAXE with OWIN and OWOUT support you can have multiple DS18B20 on single I/O lines. That's more complicated but may be worth it.
 

premelec

Senior Member
#17
FWIW I use 18B20s to monitor a boiler... occasionally I get the fault "185" reading... I suggest you indicate possible temp fault if you get this reading several successive times... It's probably a long wire hardware issue in my case.
 

Hemi345

Senior Member
#18
I would get that "185" reading as well with the old DS18B20. I had the 4K7 pullup resistor out at the sensor. This time around, I put the pullup right at the PCB:
return air sensor 4.jpg
The sensor is at the end of ~30ft of CAT5 ethernet cable.
ds18b20-outdoors.jpg
I fried one of the two weatherproof sensors I had (Lance posted a link to them above) with 9V so making do with this one for now weather-proofed with heatshrink :D
 
Last edited:

lbenson

Senior Member
#19
@Hemi345: your board says 3.3V--is that the voltage you are using to power the DS18B20 at the other end of the 30' cat5 cable?

I once used 40' of Dollar Store stereo cable (mini-stereo connector) to run one at 5V, so they can do OK with weedy cables (not recommended, though I had no problems).
 

Buzby

Senior Member
#20
.... I once used 40' of Dollar Store stereo cable (mini-stereo connector) to run one at 5V, so they can do OK with weedy cables (not recommended, though I had no problems).
One Wire comms over weedy cables is a hit and miss affair.

I've run 15m at 5v over weedy cables no problem, and then had endless problems on a 3m run.

It's just too unrepeatable, sometimes it works, sometimes it doesn't.

YMMV

Cheers,

Buzby
 

Hemi345

Senior Member
#21
Yes, I have two DS18B20s connected to that little PCB that runs at 3.3V. The naked one you see in the lower picture plus another like the weatherproof ones you linked above. The weatherproofed one does not have any additional cable added. I think it has 3ft pre-attached (it's the one on the right side with the green plug reading the supply air temp from the HVAC).

There's an Si7006 I2C-based temp and humidity sensor (limited to ~3.3V) that is mounted 90° to the bottom side of the PCB that reads the return air coming to the HVAC.
 

Hemi345

Senior Member
#22
FWIW, the 185 reading was on the old 5V system where I used two conductors for each pin and it happened very infrequently. This time around, I only used one conductor for each pin to reduce capacitance. Looking back, I should have used a twisted pair in the cable for the the data and ground lines but so far its been working flawlessly.
 
#23
On a slightly different subject to the temperature stuff we've been talking about but still on the idea of sending data between a master and slave over a cable. Is it possible to send control signals as well as or instead of data signals i.e. have push buttons on a master to control outputs or actions in a slave picaxe and then possibly have switch/sensor inputs read on a slave sent back to the master?
 

lbenson

Senior Member
#24
Is it possible to send control signals as well as or instead of data signals i.e. have push buttons on a master to control outputs or actions in a slave picaxe and then possibly have switch/sensor inputs read on a slave sent back to the master?
This is certainly possible over I2C with a picaxe master and X2 slave. Master puts a code (or codes) to a location in the slave memory, slave retrieves them, zeroes the location, acts on them, and possibly writes a response to another location, which the master monitors.
 

Hemi345

Senior Member
#25
On a slightly different subject to the temperature stuff we've been talking about but still on the idea of sending data between a master and slave over a cable. Is it possible to send control signals as well as or instead of data signals i.e. have push buttons on a master to control outputs or actions in a slave picaxe and then possibly have switch/sensor inputs read on a slave sent back to the master?
Yes, this is what I'm doing with my Humidistat project. A 20X2 is the master, while the 14M2 is the slave. They're connected together with two pins each with a 330ohm resistors between them (to protect them from damage should one pull the pin low while the other has it high). I call one pin "COMM", the other pin "RTS" (request to send). The 14M2 monitors the RTS pin. If the RTS is pulled high by the 20X2, the 14M2 sees that and listens for commands on the COMM pin using serin. 20X2 tells it what needs to be done. 14M2 acts on the commands and responds back to the 20X2 at which point the 20X2 pulls the RTS pin back low till it needs the 14M2 to do something again.
 
#26
Ok, thanks both. I'll keep reading. I just wondered if it would be possible to have inputs on ether the master and/or the slave unit control say the 8BITs in b0 and then send the whole byte over serial, then have the corresponding master/slave brake that byte back down to its BITs again to di something with, switch an output on or control a motor remotely?
 

lbenson

Senior Member
#27
If you send a byte by serial or using i2c, and receive it into b0 (or put it there from the X2 scratchpad), then you have access to bit0-bit7, the constituent bits of b0. You can also access the individual bits in b1, b2, and b3.
 
#28
Even on a 1-wire network with an PICAXE X1 or X2, it is possible to connect small (4x4) keypads and LCD displays.
Though sending data to an LCD is relatively slow.
If you need some information, see my past 1-wire networks thread.
 
#29
That is correct. Though if you have more than three sensors it's probably better to use a PICAXE which can handle all sensors so there's only one signal going back to the master PICAXE.


I have included some code at the end, which is pretty similar to your own code, though untested..

Because I parallel CS and CK to all MAX6675 chips one can read the data from all sensors when CK is high and that data can be stored in its own word variable.



You can send data back with -

SEROUT <pin>, <baud>, ( "T=", #w1, COMMA, #w2, COMMA, #w3, CR, LF )

And then read that on the master PICAXE with -

SERIN <pin>, <baud>, ( "T=" ), #w1, #w2, #w3

Code:
#Picaxe 08M2
#Terminal 4800
#No_Data

Symbol TX        = C.0
Symbol CS        = C.1
Symbol CK        = C.2

Symbol MAX6675_1 = pinC.3
Symbol MAX6675_2 = pinC.4
Symbol MAX6675_3 = pinC.5

Symbol COMMA = ","

Init:
  High CS
  Low  CK
  Pause 100

Main:
  Do
    Gosub ReadSensors
    SerOut TX, N4800,( "T=", #w1, COMMA, #w2, COMMA , #w3, CR, LF )
    Pause 1000
  Loop

ReadSensors:
  Low  CS
  For b0 = 15 To 0 Step -1
    High CK
    w1 = w1 * 2 + MAX6675_1
    w2 = w2 * 2 + MAX6675_2
    w3 = w3 * 2 + MAX6675_3
    Low CK
  Next
  High CS
  w1 = w1 / 32
  w2 = w2 / 32
  w3 = w3 / 32
  Return

Hippy, out of interest what are the CR, LF inside the brackets of the SerOut line for?
 

hippy

Technical Support
Staff member
#31
Hippy, out of interest what are the CR, LF inside the brackets of the SerOut line for?
Carriage Return and Line Feed. They move the cursor in the terminal display back to the start of the line and then down a line. So basically placed wherever you want one line to end and another to start.

They are a relic from how typewriters, telex machines and line printers are controlled.

They are pre-defined named constants to save having to remember what their ASCII code values are.
 

Aries

New Member
#33
Ok, thanks both. I'll keep reading. I just wondered if it would be possible to have inputs on ether the master and/or the slave unit control say the 8BITs in b0 and then send the whole byte over serial, then have the corresponding master/slave brake that byte back down to its BITs again to di something with, switch an output on or control a motor remotely?
If you don't want to access the bits by name, you can do something like this:

Code:
' assume data bits are in b0
b10 = 1
for b11 = 0 to 7
  b1 = b0 & b10  ' extract one bit into b1 (zero or nonzero)
  if b1 <> 0 then
      ' do something with it
  endif
  b10 = b10 * 2    ' shift b10 to next bit
next b11
 
#34
Morning Aries, thanks for you reply to this ever changing post of mine. I'm not sure I understand what you piece of cone does or where it would fit into a larger code for monitoring and sending input/output bits over serial, its out of my current depth I think.
 

Aries

New Member
#35
Sorry if it seems a bit obscure.
If you send a byte by serial or using i2c, and receive it into b0 (or put it there from the X2 scratchpad), then you have access to bit0-bit7, the constituent bits of b0. You can also access the individual bits in b1, b2, and b3.
So, if your data has arrived in b0, you can write code like
Code:
if bit0 = 1 then gosub Process0
if bit1 = 1 then gosub Process1
if bit2 = 1 then gosub Process2
etc
My alternative was to put the test within a loop which extracted one bit on each pass. It depends on what you want to do, as to whether it is "better" or more efficient.
Code:
b10 = 1               ' initialise to extract bit0
for b11 = 0 to 7      ' loop counts through bits
  b1 = b0 & b10       ' "AND" b0 with b1 to get either 0 (corresponding bit in b0 is zero)  or value of b1 (bit in b0 is nonzero)
  if b1 <> 0 then
    branch b11,(Process0,Process1,....)
  endif
  goto EndLoop

Process0:
 <...>
  goto EndLoop

Process1:
 <...>
  goto EndLoop

<...>
EndLoop:
next b11
Another way is to use SELECT CASE within the loop:
Code:
b10 = 1               ' initialise to extract bit0
for b11 = 0 to 7      ' loop counts through bits
  b1 = b0 & b10       ' "AND" b0 with b1 to get either 0 (corresponding bit in b0 is zero)  or value of b1 (bit in b0 is nonzero)
  if b1 <> 0 then
    select case b11

    Case 0:
     <...>

    Case 1:
     <...>

    <...>
    endselect
  endif
next b11
 
#36
If I managed in my master say to set each individual bits in b0 and b1 and then send the whole lot over serial as w0 to a slave picaxe how would you use them bits in the slave if you use your first code example above
eg

if bit0 = 1 then gosub Process0
if bit1 = 1 then gosub Process1
if bit2 = 1 then gosub Process2
etc

how would you know which bit0 or bit1 it is as you've got both inside b0 & b1

I've tried, "if b0 bit0 = 1 then gosub" and so on but the compiler doesn't like it.
 

hippy

Technical Support
Staff member
#37
how would you know which bit0 or bit1 it is as you've got both inside b0 & b1
The bits in 'b0' are 'bit0' through 'bit7' and the bits in 'b1' are 'bit8' through 'bit15'

So "If bit0 = 1" tests the lsb of 'b0' and "If bit8 = 1" tests the lsb of 'b1'.

I've tried, "if b0 bit0 = 1 then gosub" and so on but the compiler doesn't like it.
If you prefer using that style you can do something like it, such as this -
Rich (BB code):
Symbol b0.bit0 = bit0
Symbol b0.bit1 = bit1
Symbol b0.bit2 = bit2
etc

Symbol b1.bit0 = bit8
Symbol b1.bit1 = bit9
Symbol b1.bit2 = bit10
etc

If b0.bit0 = 1 Then Gosub Process_b0_0
If b1.bit0 = 1 Then Gosub Process_b1_0
On the X2 and X1 one can also use the "IF <var> BIT <number> SET/CLEAR" commands -
Code:
If b0 Bit 0 Set Then Gosub Process_b0_0
If b1 Bit 0 Set Then Gosub Process_b1_0
 
Last edited:

hippy

Technical Support
Staff member
#39
Now I've just got to sort the other end out in my head i.e how to for example make input1 control bit1 and I think ill be there.
You could use -

bit1 = pinC.1

or something similar. If you end up having bit0 through bit7 representing pinC.0 through C.7 you can do that in one hit -

b0 = pinsC

Individual bit assignments are convenient when the inputs come form all over the place, from non-consecutive pins. Bulk 'pins' assignments when from consecutive pins. These can be mixed and matched depending on what one wants, for example to get bits as below -
Code:
; .-----------------------------------------------.
; |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
; |-----------------------------------------------|
; | B.7 | C.7 | C.6 | C.5 | C.4 | C.3 | B.1 | B.0 |
; `-----^-----------------------------^-----------^

b0   = pinsC & %11111000 / 2
b0   = pinsB & %00000011 | b0
bit7 = pinB.7
Optimisations like that mean the code is quicker to execute and uses less memory but makes it harder to figure out what the code is doing and harder to change, so there's a valid argument for always using individual bit assignments.
 
Top