More then one MAX6675 in one node? ...smoking meat and fish...



  • I'm using this example to have control over the temperature in the meat in my smoker, and it is working fine.
    The question:
    Can I have 6 temp sensors/MAX6675 connected to one node?
    How do I change the exemple?

    // this example is public domain. enjoy!
    // www.ladyada.net/learn/sensors/thermocouple
    
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    #include "max6675.h"
    
    #define MY_NODE_ID 10
    
    #define CHILD_ID_TEMP 10
    #define TEMP_SENSOR_DIGITAL_PIN 4
    
    
    int thermoDO = 4;
    int thermoCS = 5;
    int thermoCLK = 6;
    
    MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
    int vccPin = 3;
    int gndPin = 2;
    
    MyMessage msg(CHILD_ID_TEMP, V_TEMP);
    
    
    
    
    void presentation()  {
      
     
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temp Sensor", "0.1");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_TEMP, S_TEMP);
    }
      
    
    
    
    void setup() {
      Serial.begin(115200);
      // use Arduino pins 
      pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
      pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
      
      Serial.println("MAX6675 test");
      // wait for MAX chip to stabilize
      delay(500);
    }
    
    void loop() {
      // basic readout test, just print the current temp
      int tempCelsius = thermocouple.readCelsius();
       Serial.print("C = "); 
       Serial.println(thermocouple.readCelsius());
       Serial.print("F = ");
       Serial.println(thermocouple.readFahrenheit());
       send(msg.set(tempCelsius));
     
       delay(5000);
    }```


  • Where do you buy the sensors?




  • Mod

    @jonehr yes you can. You need different CS pins for each sensor, but the rest of the pins can be shared.



  • Thank you. I'll make a try.


  • Mod

    @jonehr great. Please report back on the progress.

    If you want to dive deeper i to how SPI works, sparkfun has a nice tutorial.



  • @mfalkvidd
    Thank you.
    I'll do so.



  • Now I've studied and done some copy pasting...I'm not a programmer as you can see.

    This code seems to work.. a bit...
    My problem now is that I don't know how to write the code to tell the controller/Domoticz that there are three sensors to the node. I only get one child in "the hardware list" in Domoticz.

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    #include "max6675.h"
    
    #define MY_NODE_ID AUTO
    
    #define CHILD_ID_TEMP AUTO
    #define TEMP_SENSOR_DIGITAL_PIN 4
    //#define NUMBER_OF_SENSORS 3 // Change this depending on how many sensors you connect.
    
    MyMessage msg(CHILD_ID_TEMP, V_TEMP);
    
    
    int thermoDO = 4;
    int thermoCS = 5;
    int thermoCS2 = 7;
    int thermoCS3 = 8;
    int thermoCLK = 6;
    
    MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
    MAX6675 thermocouple2(thermoCLK, thermoCS2, thermoDO);
    MAX6675 thermocouple3(thermoCLK, thermoCS3, thermoDO);
    
    int vccPin = 3;
    int gndPin = 2;
    
    
    
    void presentation()  {
      
     
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temp Sensor", "0.1");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_TEMP, S_TEMP);
    }
      
    
    
    
    void setup() {
      Serial.begin(115200);
      // use Arduino pins 
      pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
      pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
      
      Serial.println("MAX6675 test");
      // wait for MAX chip to stabilize
      delay(500);
    }
    
    void loop() {
      // basic readout test, just print the current temp
      int tempCelsius = thermocouple.readCelsius();
      int tempCelsius2 = thermocouple2.readCelsius();
      int tempCelsius3 = thermocouple3.readCelsius();
       
       Serial.print("prob1---C = "); 
       Serial.println(thermocouple.readCelsius());
    
       Serial.print("prob2---C = "); 
       Serial.println(thermocouple2.readCelsius());
    
       Serial.print("prob3---C = "); 
       Serial.println(thermocouple3.readCelsius());
       
        send(msg.set(tempCelsius));
        send(msg.set(tempCelsius2));
        send(msg.set(tempCelsius3));
     
       delay(5000);
    }```
    

    My Domotics log:

    2017-01-03 21:23:57.057 (Mysensor server) Temp (2.1.0)
    2017-01-03 21:23:57.083 (Mysensor server) Temp (2.1.0)
    2017-01-03 21:23:57.105 (Mysensor server) Temp (2.1.0) ```

    My serial log:

    prob1---C = 0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.0
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSF:SID:OK,ID=10
    14 TSM:FPAR
    51 TSF:MSG:SEND,10-10-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    521 TSF:MSG:READ,0-0-10,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    526 TSF:MSG:FPAR OK,ID=0,D=1
    1574 TSF:MSG:READ,8-8-10,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    2058 TSM:FPAR:OK
    2059 TSM:ID
    2060 TSM:ID:OK
    2062 TSM:UPL
    2067 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2077 TSF:MSG:READ,0-0-10,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2082 TSF:MSG:PONG RECV,HP=1
    2085 TSM:UPL:OK
    2086 TSM:READY:ID=10,PAR=0,DIS=1
    2092 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2101 TSF:MSG:READ,0-0-10,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2108 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    2116 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2130 TSF:MSG:READ,0-0-10,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    2138 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:Temp Sensor
    2147 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:0.1
    2155 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    2161 MCO:REG:REQ
    2165 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    2171 TSF:MSG:READ,0-0-10,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2177 MCO:PIM:NODE REG=1
    2179 MCO:BGN:STP
    MAX6675 test
    2680 MCO:BGN:INIT OK,TSP=1
    prob1---C = 0.00
    prob2---C = 0.00
    prob3---C = 23.75
    2891 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:256
    2909 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:32
    2917 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:23
    prob1---C = 0.00
    prob2---C = 16.00
    prob3---C = 23.50
    8130 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:0
    8138 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:0
    8146 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:23


  • Mod

    @jonehr great that you got them workin.

    All three sensors need to be presented, and the sensor number needs to be set when sending values. See the temperature example, especially this part:

      // Present all sensors to controller
      for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
         present(i, S_TEMP);
      }
    

    for presentation and this part for sending values:

    
          // Send in the new temperature
          send(msg.setSensor(i).set(temperature,1));
    


  • Now I've tried all day...I can't get it to work.
    Trying to follow your advice @mfalkvidd but only made small steps with "presentation". Very thankful for your help but unfortunately I don't get it right.
    I've specified 5 sensors to the node but Domoticz sees 6 . The only working child is child 255. There I see the temperature.

    0_1483629730258_domscreen.png
    The code looks like this now:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #include <SPI.h>
    #include <MySensors.h>
    #include "max6675.h"
    
    #define MY_NODE_ID AUTO
    
    #define CHILD_ID_TEMP AUTO
    
    
    
    #define TEMP_SENSOR_DIGITAL_PIN 4
    
    #define MAX_ATTACHED_SENSORS 5
    #define NUMBER_OF_SENSORS 5 // Change this depending on how many sensors you connect.
    
    MyMessage msg(CHILD_ID_TEMP, V_TEMP);
    
    
    int gndPin = 2;
    int vccPin = 3;
    int thermoDO = 4;
    int thermoCLK = 6;
    int thermoCS1 = 5;
    int thermoCS2 = 7;
    int thermoCS3 = 8;
    int thermoCS4 = 8;
    int thermoCS5 = 8;
    
    MAX6675 thermocouple1(thermoCLK, thermoCS1, thermoDO);
    MAX6675 thermocouple2(thermoCLK, thermoCS2, thermoDO);
    MAX6675 thermocouple3(thermoCLK, thermoCS3, thermoDO);
    MAX6675 thermocouple4(thermoCLK, thermoCS4, thermoDO);
    MAX6675 thermocouple5(thermoCLK, thermoCS5, thermoDO);
    
    
    
    
    void presentation()  {
      
      
     
        // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Temp Sensor", "0.1");
      
    
    
      // Present all sensors to controller
      for (int i=0; i<NUMBER_OF_SENSORS && i<MAX_ATTACHED_SENSORS; i++) {   
        present(i, S_TEMP);
    
      
         // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_TEMP, S_TEMP);
      }
    }
      
    
    
    
    void setup() {
      Serial.begin(115200);
      // use Arduino pins 
      pinMode(vccPin, OUTPUT); digitalWrite(vccPin, HIGH);
      pinMode(gndPin, OUTPUT); digitalWrite(gndPin, LOW);
      
      Serial.println("MAX6675 test");
      // wait for MAX chip to stabilize
      delay(500);
    }
    
    void loop() {
       //basic readout test, just print the current temp
      int tempCelsius1 = thermocouple1.readCelsius();
      int tempCelsius2 = thermocouple2.readCelsius();
      int tempCelsius3 = thermocouple3.readCelsius();
      int tempCelsius4 = thermocouple4.readCelsius();
      int tempCelsius5 = thermocouple5.readCelsius();
      
    
      
      
       
       Serial.print("prob1---C = "); 
       Serial.println(thermocouple1.readCelsius());
    
       Serial.print("prob2---C = "); 
       Serial.println(thermocouple2.readCelsius());
    
       Serial.print("prob3---C = "); 
       Serial.println(thermocouple3.readCelsius());
       
        send(msg.set(tempCelsius1));
        send(msg.set(tempCelsius2));
        send(msg.set(tempCelsius3));
        send(msg.set(tempCelsius4));
        send(msg.set(tempCelsius5));
     
    
         //for (int i=0; i<NUMBER_OF_SENSORS && i<MAX_ATTACHED_SENSORS; i++) {   
        // Send in the new temperature
          //  send(msg.setreadCelsius(i));}
    
     
       delay(5000);
    }
    

    And the serial log:
    prob1---C = 0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.0
    3 TSM:INIT
    4 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSF:SID:OK,ID=10
    14 TSM:FPAR
    51 TSF:MSG:SEND,10-10-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2058 !TSM:FPAR:NO REPLY
    2060 TSM:FPAR
    2096 TSF:MSG:SEND,10-10-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    3083 TSF:MSG:READ,0-0-10,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    3087 TSF:MSG:FPAR OK,ID=0,D=1
    3228 TSF:MSG:READ,5-5-10,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    3686 TSF:MSG:READ,8-8-10,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    3775 TSF:MSG:READ,1-1-10,s=255,c=3,t=8,pt=1,l=1,sg=0:1
    4104 TSM:FPAR:OK
    4105 TSM:ID
    4106 TSM:ID:OK
    4108 TSM:UPL
    4145 !TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    4152 TSF:MSG:READ,0-0-10,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    4157 TSF:MSG:PONG RECV,HP=1
    4159 TSM:UPL:OK
    4161 TSM:READY:ID=10,PAR=0,DIS=1
    4165 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    4179 TSF:MSG:READ,0-0-10,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    4205 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    4213 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    4229 TSF:MSG:READ,0-0-10,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    4236 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=11,pt=0,l=11,sg=0,ft=0,st=OK:Temp Sensor
    4245 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:0.1
    4282 TSF:MSG:SEND,10-10-0-0,s=0,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
    4325 !TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=NACK:2.1.0
    4334 TSF:MSG:SEND,10-10-0-0,s=1,c=0,t=6,pt=0,l=0,sg=0,ft=1,st=OK:
    4354 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    4362 TSF:MSG:SEND,10-10-0-0,s=2,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
    4370 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    4378 TSF:MSG:SEND,10-10-0-0,s=3,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
    4386 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    4397 TSF:MSG:SEND,10-10-0-0,s=4,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=OK:
    4425 TSF:MSG:SEND,10-10-0-0,s=255,c=0,t=6,pt=0,l=5,sg=0,ft=0,st=OK:2.1.0
    4432 MCO:REG:REQ
    4435 TSF:MSG:SEND,10-10-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
    4445 TSF:MSG:READ,0-0-10,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    4450 MCO:PIM:NODE REG=1
    4452 MCO:BGN:STP
    MAX6675 test
    4954 MCO:BGN:INIT OK,TSP=1
    prob1---C = 2.00
    prob2---C = nan
    prob3---C = 21.50
    5227 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:0
    5235 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:56
    5245 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:21
    5254 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:21
    5273 TSF:MSG:SEND,10-10-0-0,s=255,c=1,t=0,pt=2,l=2,sg=0,ft=0,st=OK:21


  • Mod

    Nice work. Some small adjustments:
    Remove this

       // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_TEMP, S_TEMP);
    

    The 5 temperature probes will get presented in the for loop above and will get numbers 0, 1, 2, 3, and 4.

    Also change

        send(msg.set(tempCelsius1));
        send(msg.set(tempCelsius2));
        send(msg.set(tempCelsius3));
        send(msg.set(tempCelsius4));
        send(msg.set(tempCelsius5));
    

    to

        send(msg.setSensor(0).set(tempCelsius1));
        send(msg.setSensor(1).set(tempCelsius2));
        send(msg.setSensor(2).set(tempCelsius3));
        send(msg.setSensor(3).set(tempCelsius4));
        send(msg.setSensor(4).set(tempCelsius5));
    

    That should be it. The code could be made a bit cleaner by using arrays but if you aren't familiar with that type if coding I suggest you keep it the way it is.



  • @mfalkvidd

    I'm very grateful...thank you! works fine.
    As you said, the code could be cleaner but I'm fully satisfied.
    When I get the time I'll do some basic coding studies.


Log in to reply
 

Suggested Topics

  • 3
  • 2
  • 6
  • 6
  • 1

62
Online

11.4k
Users

11.1k
Topics

112.7k
Posts