Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <MAX31855.h>
- #include <mcp_can.h>
- #include <SPI.h>
- // Pin connections to the Quad MAX31855 board
- #define MISO 8
- #define SCK 9
- #define CS0 4
- #define CS1 5
- #define CS2 6
- #define CS3 7
- // Create the temperature object, defining the pins used for communication
- MAX31855 *temp[4] = {new MAX31855(MISO, CS0, SCK), new MAX31855(MISO, CS1, SCK), new MAX31855(MISO, CS2, SCK), new MAX31855(MISO, CS3, SCK)};
- byte stmp[8] = {};
- void setup()
- {
- Serial.begin(115200);
- START_INIT:
- if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
- {
- Serial.println("CAN BUS Shield init ok!");
- }
- else
- {
- Serial.println("CAN BUS Shield init fail");
- Serial.println("Init CAN BUS Shield again");
- delay(100);
- goto START_INIT;
- }
- }
- void loop (){
- for (int i=0; i<4; i++) {
- double temperature = (*temp[i]).readThermocouple(CELSIUS);
- if (temperature == NO_MAX31855)
- continue;
- Serial.print("T");
- Serial.print(i);
- Serial.print("=");
- printTemperature(temperature);
- stmp[i *2] = temperature /255;
- stmp[i *2 +1] = fmod(temperature, 255);
- }
- Serial.println();
- CAN.sendMsgBuf(0x00, 0, 8, stmp); // send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
- }
- // Print the temperature, or the type of fault
- void printTemperature(double temperature) {
- switch ((int) temperature) {
- case FAULT_OPEN:
- Serial.print("FAULT_OPEN");
- break;
- case FAULT_SHORT_GND:
- Serial.print("FAULT_SHORT_GND");
- break;
- case FAULT_SHORT_VCC:
- Serial.print("FAULT_SHORT_VCC");
- break;
- case NO_MAX31855:
- Serial.print("NO_MAX31855");
- break;
- default:
- Serial.print(temperature);
- break;
- }
- Serial.print(" ");
- }
Add Comment
Please, Sign In to add comment