Temperatur Sensor Logview Hilfe

Hallo Leute,
Ich habe hier ein Experiment aufgebaut bei dem 4 Infrarot Temperatur Sensoren zum Einsatz kommen.
Leider zeigen die Sensoren Teilweise einen Wert von ca. -120 Grad in Logview an. Das komische daran ist,
dass dieser Fehler immer rein zufällig bei einem Sensor auftritt. Teilweise gehen auch 2 oder sogar 3 nicht.
Es ist dabei auch rein zufällig welcher Sensor nicht funktioniert, ob Sensor 1 oder 3 spielt dabei keine Rolle.
Und wenn man oft genug probiert, klappen irgendwann alle 4 Sensoren.

getestet habe ich das auf 2 verschiedenen Laptops, einmal mit windows 7 und einmal windows 10.
Auch wurde getestet, beim einstecken und auch beim starten alle Sensoren auf die gleiche Oberfläche auszurichten.

Hardware: 4 Infrarotsensoren, Redboard,
Software Arduino und Logview (beide auf dem neusten Stand)

Ich möchte noch kurz anmerken, dass Ich nicht gerade viel Ahnung vom programmieren habe, also bitte nicht zu hart zu mir sein. :slight_smile:

Da Ich hier nur 9000 Zeichen benutzen darf, musste ich den Code leider als Anhang hinzufügen.

quellcode 4 sensoren.txt (12.6 KB)

Wenn du die überflüssigen und mehrfach ausgeführten Beschreibungen (die machen den Sketch nur unübersichtlich) löschst, dann sollte der kurze Sketch hier rein passen.

Verwende dazu die Schaltfläche </> oben links im Editorfenster.
Das kannst du auch nachträglich machen.
Dazu den Sketch markieren und die Schaltfläche klicken.

Damit wird dieser für alle besser lesbar.

Leider zeigen die Sensoren Teilweise einen Wert von ca. -120 Grad in Logview an.

Welche Temperatur zeigt ein nicht vorhandener Sensor an?

Die Sensoren sind alle vorhanden, ein nicht funktionierender Sensor zeigt ca. -120 Grad an.

Er reagiert ganz normal, nur sind die Temperaturen dann immer noch bei ca. -100 Grad. Es scheint fast so, dass er in Kelvin rechnet und dann teilweise einen komischen Faktor wie z.B. 0,3 noch multipliziert, bevor er das Ergebnis in Grad ausgibt.
Da viele Wege nach Rom führen Wäre Ich auch über eine alternative Codierung glücklich.

#include <i2cmaster.h>
#include <Wire.h> // I2C library, required for MLX90614
#include <SparkFunMLX90614.h> // SparkFunMLX90614 Arduino library

IRTherm therm;                                        // Create an IRTherm object to interact with throughout

const byte LED_PIN = 8;                               // LED attached to pin 8 (active low)

boolean changeEmissivity = true;                   // Change Emissivity of Sensors
boolean headersend = false;                                                                                

int device1Address = 0x5A<<1;                         // From MLX906114 datasheet's, 0x5A is
                                                      // the default address for I²C communication.
                                                      // Shift the address 1 bit right, the 
                                                      // I²Cmaster library only needs the 7 most 
                                                      // significant bits for the address.
int device2Address = 0x5B<<1;

int device3Address = 0x5C<<1;

int device4Address = 0x5D<<1;


float To_1 = 0;
float Ta_1 = 0;

float To_2 = 0;
float Ta_2 = 0;

float To_3 = 0;                                       // Variable to hold temperature in Celcius.
float Ta_3 = 0;

float To_4 = 0;
float Ta_4 = 0;

float newEmissivity_Sensor_1 = 0.99;                  
float newEmissivity_Sensor_2 = 0.99;
float newEmissivity_Sensor_3 = 0.99;
float newEmissivity_Sensor_4 = 0.99;


void setup() {
  
  Serial.begin(9600);                                 // Start serial communication at 9600bps.
  //Serial.begin(115200);                             // Start serial communication at 115200bps.
  Serial.println("Setup...");
  Serial.println("Initialise the i2c bus");
  i2c_init();                                         // Initialise the i2c bus.
  PORTC = (1 << PORTC4) | (1 << PORTC5);              // Enable pullups.
  delay(5000);
  Serial.println("Done");
  
  if(changeEmissivity)
    {
      Serial.println("Change emissivity");
      
      therm.begin(0x5A);                                                                //Init. sensor: 0x5A
      Serial.println("Old Emissivity of Sensor 1: " + String(therm.readEmissivity()));
      therm.setEmissivity(newEmissivity_Sensor_1);                                      //Change emissivity of sensor 0x5A
      delay(100);
      Serial.println("New Emissivity of Sensor 1: " + String(therm.readEmissivity()));
     
      therm.begin(0x5B);                                                                //Init. sensor: 0x5B
      Serial.println("Old Emissivity of Sensor 2: " + String(therm.readEmissivity()));
      therm.setEmissivity(newEmissivity_Sensor_2);                                      //Change emissivity of sensor 0x5B
      delay(100);
      Serial.println("New Emissivity of Sensor 2: " + String(therm.readEmissivity()));
      
      therm.begin(0x5C);                                                                //Init. sensor: 0x5C
      Serial.println("Old Emissivity of Sensor 3: " + String(therm.readEmissivity()));
      therm.setEmissivity(newEmissivity_Sensor_3);                                      //Change emissivity of sensor 0x5C
      delay(100);
      Serial.println("New Emissivity of Sensor 3: " + String(therm.readEmissivity()));
      
      therm.begin(0x5D);                                                                //Init. sensor: 0x5D
      Serial.println("Old Emissivity of Sensor 4: " + String(therm.readEmissivity()));
      therm.setEmissivity(newEmissivity_Sensor_4);                                      //Change emissivity of sensor 0x5D
      delay(100);
      Serial.println("New Emissivity of Sensor 4: " + String(therm.readEmissivity()));
      
      Serial.println("Done");
      Serial.println("Restart the Board and set changeEmissivity = false");
      
    }
    
  Serial.println("Start measurement..."); 
  pinMode(LED_PIN, OUTPUT); // LED pin as output
  setLED(LOW); // LED OFF
}

void loop() {
  setLED(HIGH); //LED on
  
  String tempst;

  //Temperature of Object/Ambient: ToTa = 0/1
  To_1 = temperatureCelcius(device1Address, 0);       // Read's data from MLX90614
                                                      // with the given address,
                                                      // transform's it into
                                                      // temperature in Celcius and
                                                      // store's it in the Celcius
                                                      // variable.
  //Temperature of Object/Ambient: ToTa = 0/1
  Ta_1 = temperatureCelcius(device1Address, 1);
                                                      
  //Temperature of Object/Ambient: ToTa = 0/1
  To_2 = temperatureCelcius(device2Address, 0);
                                                   
  //Temperature of Object/Ambient: ToTa = 0/1
  Ta_2 = temperatureCelcius(device2Address, 1);
                                                     

//Temperature of Object/Ambient: ToTa = 0/1
  To_3 = temperatureCelcius(device3Address, 0);
                                                     
  //Temperature of Object/Ambient: ToTa = 0/1
  Ta_3 = temperatureCelcius(device3Address, 1);
                                                  

//Temperature of Object/Ambient: ToTa = 0/1
  To_4 = temperatureCelcius(device4Address, 0);
                                                     
  //Temperature of Object/Ambient: ToTa = 0/1
  Ta_4 = temperatureCelcius(device4Address, 1);
                                                     
    char c = Serial.read();
    switch (c) 
    {
    case 83:                                   // "S" -> Start
      Serial.println("Start detected");
      // Send Header information
      tempst = "$N$;Room Temp Logging\r\n";
      Serial.print(tempst);
      tempst = "$C$;Temperatur 1[°C];Temperatur 2[°C];Temperatur 3[°C];Temperatur 4[°C];Temperatur 5[°C];Temperatur 6[°C];Temperatur 7[°C];Temperatur 8[°C]\r\n";
      Serial.print(tempst);
      headersend = true;
      break;
    case 69:                                   // "E" -> End
      Serial.println("Log ende");
      headersend = false;
      break;
    }
  
  if (headersend)
  {
   Serial.print("$");                        // Values for RS232 
   Serial.print(To_1);
   Serial.print(";");
   Serial.print(Ta_1);
   Serial.print(";");
   Serial.print(To_2);
   Serial.print(";");
   Serial.print(Ta_2);
   Serial.print(";");
   Serial.print(To_3);
   Serial.print(";");
   Serial.print(Ta_3);
   Serial.print(";"); 
   Serial.print(To_4);
   Serial.print(";");    
   Serial.print("\r\n");
  }
  setLED(LOW);
  delay(100);                         // Wait a second before printing again.
}

//Temperature of Object/Ambient: TaTo = 0/1 
float temperatureCelcius(int address, int ToTa) {
  int dev = address;
  int data_low = 0;
  int data_high = 0;
  int pec = 0;

  // Write
  i2c_start_wait(dev+I2C_WRITE);
  if (ToTa) i2c_write(0x06); else i2c_write(0x07); 
  //i2c_write(0x07);

  // Read
  i2c_rep_start(dev+I2C_READ);
  data_low = i2c_readAck();       // Read 1 byte and then send ack.
  data_high = i2c_readAck();
  pec = i2c_readNak();
  i2c_stop();

  // This converts high and low bytes together and processes temperature, 
  // MSB is a error bit and is ignored for temps.
  double tempFactor = 0.02;       // 0.02 degrees per LSB (measurement 
                                  // resolution of the MLX90614).
  double tempData = 0x0000;       // Zero out the data
  int frac;                       // Data past the decimal point

  // This masks off the error bit of the high byte, then moves it left 
  // 8 bits and adds the low byte.
  tempData = (double)(((data_high & 0x007F) << 8) + data_low);
  tempData = (tempData * tempFactor)-0.01;
  float celcius = tempData - 273.15;
  
  // Returns temperature in Celcius.
  return celcius;
}

void setLED(bool on)
{
  if (on)
    digitalWrite(LED_PIN, LOW);
  else
    digitalWrite(LED_PIN, HIGH);
}

Die Sensoren sind alle vorhanden

Das war nicht der Punkt. Wenn ein Sensor nicht vorhanden ist, was siehst du dann?

Oder:

Wie wäre es ausnahmsweise mit Fehlerüberwachung?

(Ein Steckbrett hat immer Wackelkontakte.)

Ouh, das habe ich falsch verstanden.
Ich werde es gleich einmal ausprobieren.

Ich hoffe mit Fehlerüberwachung ist der Logging Verlauf gemeint. ab 16.22 hatte ich nur noch 3 Sensoren angeschlossen.

Außerdem muss ich öfters ein 2. Mal den Haken neu setzen, da der beim ersten mal klicken /aktivieren auf " Open Format Zero Sensor" einen Fehler ausspukt. Leider ist der gesamte Code wieder zu lange um ihn zu posten, daher ist nur der Fehler mit 3 Sensoren (ab 16.22) hier. Den Verlauf Mit 4 Sensoren habe ich als Bild Dateien angehangen.

Ich habe also jeweils 2 mal den Haken gesetzt.

Do 16:15:41.714 : [31, DB        ] DB Update Data (Chn : 1) Time : 0,0006107 sec. for 11 items
Do 16:15:42.911 : [31, DB        ] DB Update Data (Chn : 1) Time : 0,0006162 sec. for 11 items
Do 16:15:43.164 : [ 1, Device    ] OFZ - Sending 'E' to Device for End
Do 16:15:43.164 : [ 1, Device    ] Stopping Source
Do 16:15:43.164 : [ 1, Serial    ] Stop IO Thread, Close Port
Do 16:15:43.164 : [ 1, Device    ] Stopping Calc Thread
Do 16:15:43.164 : [ 1, Device    ] Closing Database
Do 16:15:43.164 : [ 1, Project   ] HandleRawDatasets (setlast : True)
Do 16:15:43.211 : [ 1, DB        ] ..DB Update Last End Id : Proj ID 4     Start 1 End 540 [d3_ch1_20171116_161434]
Do 16:15:43.289 : [29, Serial    ] Serial IO Thread stopped.
Do 16:22:44.465 : [ 1, Device    ] Create new Device Instance
Do 16:22:44.465 : [ 1, Device    ]   Device : OpenFormat Zero Sensor - Vendor : LogView.info
Do 16:22:44.465 : [ 1, EnumSer   ]   UpdateDevices - Enumerate Serial devices
Do 16:22:44.481 : [ 1, EnumSer   ]     Com Port found : COM4 (Standardmäßgige Seriell-über-Bluetooth-Verbindung) - Microsoft
Do 16:22:44.481 : [ 1, EnumSer   ]     Com Port found : COM5 (Standardmäßgige Seriell-über-Bluetooth-Verbindung) - Microsoft
Do 16:22:44.481 : [ 1, EnumSer   ]     Com Port found : COM6 (USB Serial Port) - FTDI
Do 16:22:44.481 : [ 1, EnumSer   ]   UpdateDevices
Do 16:22:44.481 : [ 1, Serial    ]   Enum is not implemented for Linux
Do 16:22:44.481 : [ 1, File      ]   Enum not needed for File Class
Do 16:22:44.481 : [ 1, TcpClnt   ]   No need to enumerate Devices ... 
Do 16:22:44.481 : [ 1, TcpClnt   ]   No need to enumerate Devices ... 
Do 16:22:44.496 : [ 1, Device    ] Create new Device Instance
Do 16:22:52.983 : [ 1, Project   ] HandleRawDatasets (setlast : True)
Do 16:22:53.014 : [ 1, Serial    ] Open Port, Start IO Thread (Port : COM6)
Do 16:22:53.030 : [ 1, Device    ] OFZ - Sending 'S' to Device for Start
Do 16:22:53.045 : [ 1, Serial    ] GetSetting : COM6||\\?\ftdibus#vid_0403+pid_6015+dn01jjeca#0000#{4d36e978-e325-11ce-bfc1-08002be10318}||9600||8||One||None||False||False
Do 16:22:54.615 : [11, Device    ] OFZ - CheckValidData = false
Do 16:22:54.677 : [11, Device    ] OFZ - CheckValidData = false
Do 16:22:58.311 : [ 1, Device    ] OFZ - Sending 'E' to Device for End
Do 16:22:58.311 : [ 1, Device    ] Stopping Source
Do 16:22:58.311 : [ 1, Serial    ] Stop IO Thread, Close Port
Do 16:22:58.311 : [ 1, Device    ] Stopping Calc Thread
Do 16:22:58.311 : [ 1, Device    ] Closing Database
Do 16:22:58.311 : [ 1, Project   ] HandleRawDatasets (setlast : True)
Do 16:22:58.420 : [10, Serial    ] Serial IO Thread stopped.
Do 16:23:00.489 : [ 1, Project   ] HandleRawDatasets (setlast : True)
Do 16:23:00.520 : [ 1, Serial    ] Open Port, Start IO Thread (Port : COM6)
Do 16:23:00.551 : [ 1, Device    ] OFZ - Sending 'S' to Device for Start
Do 16:23:00.567 : [ 1, Serial    ] GetSetting : COM6||\\?\ftdibus#vid_0403+pid_6015+dn01jjeca#0000#{4d36e978-e325-11ce-bfc1-08002be10318}||9600||8||One||None||False||False
Do 16:23:00.980 : [ 8, Device    ] OFZ - CheckValidData = false
Do 16:23:02.128 : [ 8, Device    ] OFZ - CheckValidData = false
Do 16:23:02.128 : [ 8, Device    ] OFZ - CheckValidData = false
Do 16:23:02.190 : [ 8, Device    ] OFZ - CheckValidData = false
Do 16:23:02.190 : [ 8, Device    ] OFZ - CheckValidData = false
Do 16:23:11.674 : [ 1, Device    ] OFZ - Sending 'E' to Device for End
Do 16:23:11.674 : [ 1, Device    ] Stopping Source
Do 16:23:11.674 : [ 1, Serial    ] Stop IO Thread, Close Port
Do 16:23:11.674 : [ 1, Device    ] Stopping Calc Thread
Do 16:23:11.674 : [ 1, Device    ] Closing Database
Do 16:23:11.674 : [ 1, Project   ] HandleRawDatasets (setlast : True)
Do 16:23:11.784 : [27, Serial    ] Serial IO Thread stopped.