Buonasera a tutti!
Ho una questione che non riesco a risolvere a cavallo, credo, tra software e hardware.
Dunque io sto cercando di leggere la temperautra tramite ntc (e per fare questo ho usato il tutorial:
http://learn.adafruit.com/thermistor?view=all). Con questo sistema faccio dieci letture, tolgo le due più alte e le due più basse (già discusso in un altro post) e calcolo la temperatura sulla media delle sei letture rimanenti. Fin qua tutto ok.
Questo però era solo un esercizio da mettere in pratica con la piattaforma Chameleon (
http://www.eurogi.it/portfolio/chameleon/). Il problema è che una volta che carico il programma in Chameleon (il quale va alimentato a 10V separatamente dal cavo usb per caricarci sopra il software) questo mi restituisce delle letture che non corrispondono affatto alla temperatura.
Io suppongo che questo sia dovuto ai parametri che vanno settati nel tutorial, cioè:
// which analog pin to connect
#define THERMISTORPIN 0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 10
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3470
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
però, visto che di elettronica ci capisco pochino (poco proprio!), non sono sicuro di essere sulla giusta strada! A me serve di leggere la temperatura (corretta!) dal Chameleon!
allego il codice
// which analog pin to connect
#define THERMISTORPIN 0
// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000
// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25
// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 10
// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3470
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
#define outputBedRoomOne 8
int n = 0;
int i = 0;
int arraysala[10];
float tempConverter(float average){
// convert the value to resistance
Serial.print("CONVERTO LA MEDIA ");
Serial.println(average);
average = 1023 / average - 1;
average = SERIESRESISTOR / average;
float steinhart;
steinhart = average / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert to C
Serial.print("temp rilevata ");
Serial.println(steinhart);
return steinhart;
}
void setup()
{
pinMode(n, INPUT);
Serial.begin(9600);
}
void loop()
{
int valore = analogRead(THERMISTORPIN);
Serial.print("read value ");
Serial.print(valore);
arraysala[i] = valore;
Serial.print(" array index number ");
Serial.print(i);
Serial.print(" save ");
Serial.println(arraysala[i]);
i = i+1;
if(i>9){
int indmin = 0;
int indmax = 0;
for(int j = 1; j<=2; j++){
int vmax = 0;
for(int k = 0; k<10; k++){
if(vmax < arraysala[k] && arraysala[k] != 10000){
vmax = arraysala[k];
indmax = k;
}
}
Serial.print("max ");
Serial.println(indmax);
arraysala[indmax] = -10000;
}
for(int j = 1; j<=2; j++){
int vmin = 1023;
for(int k = 0; k<10; k++){
if(vmin > arraysala[k] && arraysala[k] != -10000){
vmin = arraysala[k];
indmin = k;
}
}
Serial.print("min ");
Serial.println(indmin);
arraysala[indmin] = 10000;
}
i = 0;
float media = 0;
for(int l = 0 ; l<10; l++){
Serial.print(arraysala[l]);
Serial.print(" + ");
Serial.print(media);
Serial.print(" = ");
media = arraysala[l] + media;
Serial.println(media);
}
media = media / 6;
Serial.print("diviso 6 = ");
Serial.println(media);
tempConverter(media);
}
delay(1000);
}
Grazie a tutti!