Created
November 8, 2012 16:53
-
-
Save TAUTIC/4040026 to your computer and use it in GitHub Desktop.
MAX31855 Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int CH1 = 5; // Channel 1 CS | |
const int mDataPin = 6; // SO | |
const int mClockPin = 7; // SCK | |
void setup() { | |
Serial.begin(9600); | |
pinMode(CH1, OUTPUT); //CS is an Output | |
pinMode(mDataPin, INPUT); //SO is an Input | |
pinMode(mClockPin, OUTPUT); //SCK is an Output | |
digitalWrite(CH1, 1); | |
digitalWrite(mClockPin, 0); | |
} | |
void loop () | |
{ | |
// Output temperature from the two boards in the format of: [CH1],[CH2]\n | |
// Example: 123.45,678.90\n | |
Serial.println(getTemp(CH1)); | |
delay(1000); // Delay 1 seconds, so we get new readings sent to the terminal once per second | |
} | |
float getTemp(int ch) | |
{ | |
unsigned long value = 0; | |
float temp = 0; | |
char bita; | |
digitalWrite(ch, 0); | |
for (int i = 0; i < 32; i++) //Get 32 bits from the MAX31855 - see datasheet for specifics. | |
{ | |
digitalWrite(mClockPin, 1); //set clock pin low | |
bita = digitalRead(mDataPin); | |
if (bita==1) value = value | 1; // If bit ==1 set lowest bit in value | |
digitalWrite(mClockPin, 0); | |
if (i != 31) value = value << 1;// If we're not done yet, shift bits left by 1 to make room for next loop | |
} | |
digitalWrite(ch, 1); | |
value = value >> 18; //shift out all but tc temp data and sign bit | |
temp = (((value * 0.25) * 9) / 5) + 32; //Convert to Degrees F | |
return temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment