PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : MCP9700 Temperaturabfrage



Mechdoc
24.01.2013, 13:39
4 MCP9700 werden abgefragt und sollen in Grad Celsius Wert anzeigen.
zwei C++ Codes bringen 2x denselben Fehler.
Wert wird in Millivolt und nicht in Grad ausgegeben und ich finde den Fehler nicht.
Bitte um Hilfe
Code 1
#include <LiquidCrystal.h>

// Arduino pins used for LCD
LiquidCrystal lcd(8,9,4,5,6,7);// Pins Keypadshield
//Variablen
int ADC0,ADC1,ADC2,ADC3;
float temp0,temp1,temp2,temp3;

//Konstanten Offset setzen
int MCPoffset = 500;
int LM35offset = 0;

//Sensor Kalibration
int calibration0 = 0;
int calibration1 = 0;
int calibration2 = 0;
int calibration3 = 0;

void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop (){
getADC();
calcLoop();
serialPrint();
lcdPrint();
delay(1000);
}

void getADC(){
ADC0 = analogRead(A8);
ADC1 = analogRead(A9);
ADC2 = analogRead(A10);
ADC3 = analogRead(A11);
}
//
void calcLoop(){
temp0 =calcTemp(ADC0, MCPoffset, calibration0);
temp1 =calcTemp(ADC1, MCPoffset, calibration1);
temp2 =calcTemp(ADC2, MCPoffset, calibration2);
temp3 =calcTemp(ADC3, MCPoffset, calibration3);
}

float calcTemp (int val, int offset, int cal){
return(((val * 4.8828) - offset) / 10) + cal;
}
//------------------------------------------------------
void serialPrint(){
Serial.print(temp0,2);
Serial.print(" ");
Serial.print(temp1,2);
Serial.print(" ");
Serial.print(temp2,2);
Serial.print(" ");
Serial.print(temp3,2);
Serial.print(" ");
Serial.print(" ");
delay(10);
}
void lcdPrint(){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(temp0, 1);
lcd.print(" A ");
lcd.setCursor(9, 0);
lcd.print(temp1, 1);
lcd.print(" B ");
lcd.setCursor(0, 2);
lcd.print(temp2, 1);
lcd.print(" C ");
lcd.setCursor(9, 2);
lcd.print(temp3, 1);
lcd.print(" D ");
}
Code 2----------------------------
#include <LiquidCrystal.h>

// Arduino pins used for LCD
LiquidCrystal lcd(8,9,4,5,6,7);// Pins Keypadshield

void setup() {
// initialize the LCD display
lcd.begin(16, 2);
Serial.begin(9600);
pinMode (50, OUTPUT); //Ausgang definiert
}

void loop() {

// digitalWrite (50,LOW); // Ausgang ausgeschalten
//---- Messung T1 ----
float tempT1 = 0.0; // Berechnete Temperatur speichern
int sampleT1; // counts through ADC samples
float ten_samplesT1 = 0.0; // Speichern 10 Messungen
// 10 samples from the MCP9700 T1
for (sampleT1 = 0; sampleT1 < 10; sampleT1++) {
tempT1 = ((float)analogRead(A8) * 5.0 / 1024.0) - 0.5;// convert A8 value to temperature
tempT1 = tempT1 / 0.01;
delay(10);
ten_samplesT1 = ten_samplesT1 + tempT1; //Summe aller samplesT1
}
//----Messung T2 ----
float tempT2 = 0.0; // Berechnete Temperatur speichern
int sampleT2; // counts durch ADC
float ten_samplesT2 = 0.0; // Speichern 10 Messungen
// 10 samples from the MCP9700 T2
for (sampleT2 = 0; sampleT2 < 10; sampleT2++) {
tempT2 = ((float)analogRead(A9) * 5.0 / 1024.0) - 0.5;// convert A9 value to temperature
tempT2 = tempT2 / 0.01;
delay(10);
ten_samplesT2 = ten_samplesT2 + tempT2; //Summe aller samplesT2
}
//---- Messung T3 ----
float tempT3 = 0.0; // Berechnete Temperatur speichern
int sampleT3; // counts through ADC samples
float ten_samplesT3 = 0.0; // Speichern 10 Messungen
// take 10 samples from the MCP9700
for (sampleT3 = 0; sampleT3 < 10; sampleT3++) {
tempT3 = ((float)analogRead(A10) * 5.0 / 1024.0) - 0.5;// convert A10 value to temperature
tempT3 = tempT3 / 0.01;
delay(10);
ten_samplesT3 = ten_samplesT3 + tempT3;//Summe aller samplesT3
}
//----Messung T4 ----
float tempT4 = 0.0; // Berechnete Temperatur speichern
int sampleT4; // counts through ADC samples
float ten_samplesT4 = 0.0; // Speichern 10 Messungen
for (sampleT4 = 0; sampleT4 < 10; sampleT4++) {
tempT4 = ((float)analogRead(A11) * 5.0 / 1024.0) - 0.5; // convert A11 value to temperature
tempT4 = tempT4 / 0.01;
// sample every 0.1 sec0onds
delay(100);
ten_samplesT4 = ten_samplesT4 + tempT4;//Summe aller samplesT4
}

//-----------Temp-Vergleich-------------
if (tempT1 == tempT2);
{
digitalWrite (50,HIGH);
}
Serial.println(tempT1);

//Gesamttemperatur berechnen
float tempGesamt = 0.0;
tempGesamt = (float (tempT1 + tempT2 + tempT3 + tempT4));

//----Ausgabe auf LCD----


tempT1 = ten_samplesT1 / 10.0;
tempT2 = ten_samplesT2 / 10.0;
tempT3 = ten_samplesT3 / 10.0;
tempT4 = ten_samplesT4 / 10.0;
tempGesamt = tempGesamt/4;


lcd.setCursor(0, 0);
lcd.print(tempT1 );
lcd.print(" A ");
lcd.print(tempT2);
lcd.print(" B ");
lcd.setCursor(0, 1);
lcd.print(tempT3);
lcd.print(" C ");
lcd.print(tempT4);
lcd.print(" D ");
delay(5000);
lcd.clear();
lcd.print(tempGesamt);
lcd.print(" < Grad C >");

Serial.println(A8);
delay(1000);


ten_samplesT1 = 0.0;
ten_samplesT2 = 0.0;
ten_samplesT3 = 0.0;
ten_samplesT4 = 0.0;


}

Mechdoc
25.01.2013, 07:54
Fehler gefunden!
Sensoren hatten anderes Massepotential als Arduino.Trotz Mehrmaligen Aufbaus.
Nobody is perfect.