Created
May 14, 2016 08:34
-
-
Save imrehg/18438bfaba2f8365ee2580b2920f991f to your computer and use it in GitHub Desktop.
OCTeleShield telemetry example
This file contains hidden or 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
#include <SPI.h> | |
#include <Adafruit_MAX31855.h> | |
// Example creating a thermocouple instance with hardware SPI (Uno/Mega only) | |
// on a given CS pin. | |
#define CS1 2 | |
#define CS2 3 | |
Adafruit_MAX31855 th1(CS1); | |
Adafruit_MAX31855 th2(CS2); | |
int v1pin = A0; | |
int v2pin = A1; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
delay(2000); | |
// Serial.println("MAX31855 test"); | |
// wait for MAX chip to stabilize | |
Serial.println("#Millis,TC1Internal(C),TC1External(C),TC2Internal(C),TC2External(C),Voltage1(V),Voltage2(V)"); | |
delay(500); | |
} | |
void loop() { | |
double c; | |
Serial.print(millis()); | |
Serial.print(","); | |
Serial.print(th1.readInternal()); | |
Serial.print(","); | |
c = th1.readCelsius(); | |
if (isnan(c)) { | |
Serial.print(""); | |
} else { | |
Serial.print(c); | |
} | |
Serial.print(","); | |
Serial.print(th2.readInternal()); | |
Serial.print(","); | |
c = th2.readCelsius(); | |
if (isnan(c)) { | |
Serial.print(""); | |
} else { | |
Serial.print(c); | |
} | |
Serial.print(","); | |
Serial.print(getVoltage(A0)); | |
Serial.print(","); | |
Serial.print(getVoltage(A1)); | |
Serial.println(""); | |
delay(100); | |
} | |
double getVoltage(int pin) { | |
int sensorValue; | |
sensorValue = analogRead(pin); | |
double multiplier = (10.0 + 33.2) / 10.0; | |
double reading; | |
reading = 5.0 * sensorValue / 1024.0 * multiplier; | |
return reading; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment