burdickjp

EGT sensing for MS with Arduino

Aug 15th, 2014
2,786
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None
  1. #include <MAX31855.h>
  2.  
  3. #include <mcp_can.h>
  4. #include <SPI.h>
  5.  
  6. // Pin connections to the Quad MAX31855 board  
  7. #define MISO 8
  8. #define SCK  9
  9. #define CS0  4
  10. #define CS1  5
  11. #define CS2  6
  12. #define CS3  7
  13.  
  14. // Create the temperature object, defining the pins used for communication
  15. MAX31855 *temp[4] = {new MAX31855(MISO, CS0, SCK), new MAX31855(MISO, CS1, SCK), new MAX31855(MISO, CS2, SCK), new MAX31855(MISO, CS3, SCK)};
  16.  
  17. byte stmp[8] = {};
  18.  
  19. void setup()
  20. {
  21.     Serial.begin(115200);
  22.  
  23. START_INIT:
  24.  
  25.     if(CAN_OK == CAN.begin(CAN_500KBPS))                   // init can bus : baudrate = 500k
  26.     {
  27.         Serial.println("CAN BUS Shield init ok!");
  28.     }
  29.     else
  30.     {
  31.         Serial.println("CAN BUS Shield init fail");
  32.         Serial.println("Init CAN BUS Shield again");
  33.         delay(100);
  34.         goto START_INIT;
  35.     }
  36. }
  37.  
  38.  
  39. void loop (){
  40.   for (int i=0; i<4; i++) {    
  41.     double temperature = (*temp[i]).readThermocouple(CELSIUS);
  42.     if (temperature == NO_MAX31855)
  43.       continue;
  44.     Serial.print("T");
  45.     Serial.print(i);
  46.     Serial.print("=");
  47.     printTemperature(temperature);
  48.     stmp[i *2] = temperature /255;
  49.     stmp[i *2 +1] = fmod(temperature, 255);
  50.   }
  51.   Serial.println();  
  52.   CAN.sendMsgBuf(0x00, 0, 8, stmp);   // send data:  id = 0x00, standrad flame, data len = 8, stmp: data buf
  53. }
  54.  
  55.  
  56. // Print the temperature, or the type of fault
  57. void printTemperature(double temperature) {
  58.   switch ((int) temperature) {
  59.     case FAULT_OPEN:
  60.       Serial.print("FAULT_OPEN");
  61.       break;
  62.     case FAULT_SHORT_GND:
  63.       Serial.print("FAULT_SHORT_GND");
  64.       break;
  65.     case FAULT_SHORT_VCC:
  66.       Serial.print("FAULT_SHORT_VCC");
  67.       break;
  68.     case NO_MAX31855:
  69.       Serial.print("NO_MAX31855");
  70.       break;
  71.     default:
  72.       Serial.print(temperature);
  73.       break;
  74.   }
  75.   Serial.print(" ");
  76. }
RAW Paste Data Copied