Reading Inputs reliability

userHead Lemminger65 2019-05-17 02:55:12 2442 Views0 Replies
Hi

I have my third LattePanda.

Some Problems with input reading.
I could not read proper all inputs.


First off all, an Input that is declared as digital and is already on if LattePanda starts is not detected.
If there is a input change high, low, high, then high will be detected. Is there a possibility to detect also inputs they are static high at LP Start?
Anybody else some experience.

Second issue is that not all analog inputs could be read as analog. It just work A0-A5

I have doubt if the LattePanda is reliability enough to us it in industrial solutions!?!
Please see below my code. Does anybody find a mistake in defining Inputs?

For help many thanks

Regards, Klaus

Code: Select all

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.IO; using LattePanda.Firmata; namespace Telemetrie01 { class Program { //Version 23.04.2019 //Aufgaben: //Eingänge zuweisen prüfen, speziell Feuchte static Arduino arduino = new Arduino();//create an instance and initialize with the default parameters static void Main(string[] args) { int Digiwert9 = 0; int Digiwert0 = 0; float V0 = 1100; float V10 = 1010; float V30 = 973; float V65 = 833; float V95 = 623; float V115 = 100; float y1 = 0; float y2 = 20; float x1 = 1100; float x2 = 980; int Wartezeit = 120; //120 final Sekunden int gelaufeneZeit = 0; // bis shutdown float maxtemp1 = 0; float maxtemp2 = 0; float maxtemp3 = 0; float maxtemp4 = 0; float maxtemp5 = 0; float mintemp1 = 0; float mintemp2 = 0; float mintemp3 = 0; float mintemp4 = 0; float mintemp5 = 0; int start = 1; //NEUNEUNEUNEU-------------------------------------------------------------------------- float Temp101 = 0; float Temp102 = 0; float Temp103 = 0; float Temp104 = 0; float Temp105 = 0; float Temp106 = 0; float Temp107 = 0; float Temp108 = 0; float Temp109 = 0; float Temp110 = 0; float Temp201 = 0; float Temp202 = 0; float Temp203 = 0; float Temp204 = 0; float Temp205 = 0; float Temp206 = 0; float Temp207 = 0; float Temp208 = 0; float Temp209 = 0; float Temp210 = 0; float Temp301 = 0; float Temp302 = 0; float Temp303 = 0; float Temp304 = 0; float Temp305 = 0; float Temp306 = 0; float Temp307 = 0; float Temp308 = 0; float Temp309 = 0; float Temp310 = 0; float Temp401 = 0; float Temp402 = 0; float Temp403 = 0; float Temp404 = 0; float Temp405 = 0; float Temp406 = 0; float Temp407 = 0; float Temp408 = 0; float Temp409 = 0; float Temp410 = 0; float Temp501 = 0; float Temp502 = 0; float Temp503 = 0; float Temp504 = 0; float Temp505 = 0; float Temp506 = 0; float Temp507 = 0; float Temp508 = 0; float Temp509 = 0; float Temp510 = 0; //Log.WriteLog(" ", " ", " ", " ", " "); // Trennzeile schreiben Log.WriteLog(" Neustart " , " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart ", " Neustart "); // Trennzeile schreiben //Log.WriteLog(" ", " ", " ", " ", " "); // Trennzeile schreiben // arduino.pinMode(10, Arduino.OUTPUT); // arduino.digitalWrite(10, Arduino.HIGH); //for ( I = 0; I <= 23; I=I+1); arduino.pinMode(7, Arduino.INPUT); // X5-1 Drivemode arduino.pinMode(0, Arduino.INPUT); // X5-2 Zündung Duplex arduino.pinMode(8, Arduino.INPUT); // X5-3 Tankreserve arduino.pinMode(1, Arduino.INPUT); // X5-4 Tempobegrenzung arduino.pinMode(9, Arduino.INPUT); // X5-5 Warnmeldungen arduino.pinMode(2, Arduino.INPUT); // X5-6 Zündung als Überwachung für Shut down arduino.pinMode(10, Arduino.INPUT); // X5-7 Freigabe BMS arduino.pinMode(3, Arduino.INPUT); // X5-8 Brake auf Schaltplatte arduino.pinMode(6, Arduino.ANALOG); // Feuchte unten arduino.pinMode(18, Arduino.ANALOG); arduino.pinMode(19, Arduino.ANALOG); arduino.pinMode(20, Arduino.ANALOG); arduino.pinMode(21, Arduino.ANALOG); arduino.pinMode(22, Arduino.ANALOG); arduino.pinMode(23, Arduino.ANALOG); arduino.pinMode(6, Arduino.ANALOG); // arduino.pinMode(23, Arduino.INPUT); // X2-11 Feuchte oben // arduino.pinMode(6, Arduino.INPUT); // X4-2 Feuchte unten arduino.pinMode(11, Arduino.OUTPUT); // Relais Warn arduino.pinMode(5, Arduino.OUTPUT); // Relais Zündung Reset für Start // Test für Relais 11 // arduino.digitalWrite(11, Arduino.HIGH); // Relais um den Zündungseingang einmal bim Start ztu triggern 23 //Thread.Sleep(1000); // arduino.digitalWrite(11, Arduino.LOW); // 23 //Thread.Sleep(1000); arduino.digitalWrite(5, Arduino.HIGH); // Relais um den Zündungseingang einmal bim Start ztu triggern Thread.Sleep(1000); arduino.digitalWrite(5, Arduino.LOW); // while (true) { //Temperaturen auslesen folgend int Value1 = arduino.analogRead(0);//Kabel 1 Hauptmotor Einlass if ((Value1 >= V10) & (Value1 <= V0))// Wertepaare setzen { x2 = V10; x1 = V0; y1 = 0; y2 = 12; } if ((Value1 >= V30) & (Value1 <=V10)) { x2 = V30; x1 = V10; y1 = 12; y2 = 40; } if ((Value1 >= V65) & (Value1 <=V30)) { x2 = V65; x1 = V30; y1 = 40; y2 = 65; } if ((Value1 >= V95) & ( Value1 <= V65)) { x2 = V95; x1 = V65; y1 = 65; y2 = 95; } if ((Value1 >= V115) & (Value1 <= V95)) { x2 = V115; x1 = V95; y1 = 95; y2 = 115; } float Temp1 = y1 + ((y2 - y1) / (x2 - x1)) * (Value1 - x1); //Berechnen Motortemp int Value2 = arduino.analogRead(1);//Kabel 2 Hauptmotor Auslass if ((Value2 >= V10) & (Value2 <= V0))// Wertepaare setzen { x2 = V10; x1 = V0; y1 = 0; y2 = 12; } if ((Value2 >= V30) & (Value2 <= V10)) { x2 = V30; x1 = V10; y1 = 12; y2 = 40; } if ((Value2 >= V65) & (Value2 <= V30)) { x2 = V65; x1 = V30; y1 = 40; y2 = 65; } if ((Value2 >= V95) & (Value2 <= V65)) { x2 = V95; x1 = V65; y1 = 65; y2 = 95; } if ((Value2 >= V115) & (Value2 <= V95)) { x2 = V115; x1 = V95; y1 = 95; y2 = 115; } float Temp2 = y1 + ((y2 - y1) / (x2 - x1)) * (Value2 - x1); //Berechnen int Value3 = arduino.analogRead(2);//Kabel 3 Nach Wärmetauscher / Vor Batterie if ((Value3 >= V10) & (Value3 <= V0))// Wertepaare setzen { x2 = V10; x1 = V0; y1 = 0; y2 = 12; } if ((Value3 >= V0) & (Value3 <= V10)) { x2 = V30; x1 = V10; y1 = 12; y2 = 40; } if ((Value3 >= V65) & (Value3 <= V30)) { x2 = V65; x1 = V30; y1 = 40; y2 = 65; } if ((Value3 >= V95) & (Value3 <= V65)) { x2 = V95; x1 = V65; y1 = 65; y2 = 95; } if ((Value3 >= V115) & (Value3 <= V95)) { x2 = V115; x1 = V95; y1 = 95; y2 = 115; } float Temp3 = y1 + ((y2 - y1) / (x2 - x1)) * (Value3 - x1); //Berechnen Motortemp int Value4 = arduino.analogRead(3);//Kabel 4 Nach Batterie / vor Controller if ((Value4 >= V10) & (Value4 <= V0))// Wertepaare setzen { x2 = V10; x1 = V0; y1 = 0; y2 = 12; } if ((Value4 >= V30) & (Value4 <= V10)) { x2 = V30; x1 = V10; y1 = 12; y2 = 40; } if ((Value4 >= V65) & (Value4 <= V30)) { x2 = V65; x1 = V30; y1 = 40; y2 = 65; } if ((Value4 >= V95) & (Value4 <= V65)) { x2 = V95; x1 = V65; y1 = 65; y2 = 95; } if ((Value4 >= V115) & (Value4 <= V95)) { x2 = V115; x1 = V95; y1 = 95; y2 = 115; } float Temp4 = y1 + ((y2 - y1) / (x2 - x1)) * (Value4 - x1); //Berechnen int Value5 = arduino.analogRead(4);//Kabel 5 Nach Controller / Vor Wärmetauscher if ((Value5 >= V10) & (Value5 <= V0))// Wertepaare setzen { x2 = V10; x1 = V0; y1 = 0; y2 = 12; } if ((Value5 >= V30) & (Value5 <= V10)) { x2 = V30; x1 = V10; y1 = 12; y2 = 40; } if ((Value5 >= V65) & (Value5 <= V30)) { x2 = V65; x1 = V30; y1 = 40; y2 = 65; } if ((Value5 >= V95) & (Value5 <= V65)) { x2 = V95; x1 = V65; y1 = 65; y2 = 95; } if ((Value5 >= V115) & (Value5 <= V95)) { x2 = V115; x1 = V95; y1 = 95; y2 = 115; } float Temp5 = y1 + ((y2 - y1) / (x2 - x1)) * (Value5 - x1); //Berechnen Motortemp //float Temp0 = y1 + ((y2-y1) / (x2 - x1)) * (Value1 - x1); int Drivemode = arduino.digitalRead(7); // Drivemode lesen int noch_nix = arduino.digitalRead(0); // noch nix int Tankreserve = arduino.digitalRead(8); // Tankreserve lesen int Tempobegrenzung = arduino.digitalRead(1); // Tempobegrenzung lesen int Warnmeldung = arduino.digitalRead(9); // Warnmeldung lesen // int Freigabe_BMS = arduino.digitalRead(2); // Zündung lesen int Freigabe_BMS = arduino.digitalRead(10); // Freigabe_BMS lesen int Brake = arduino.digitalRead(3); // Brake lesen int Feuchte_oben = arduino.analogRead(5); // Feuchte lesen D23/A5 int Feuchte_unten = arduino.analogRead(7); // Feuchte lesen D6/A7 if (start == 1) { start = 0; maxtemp1 = Temp1; // Grenzwerte auf ersten Lesewert setzen maxtemp2 = Temp2; maxtemp3 = Temp3; maxtemp4 = Temp4; maxtemp5 = Temp5; mintemp1 = Temp1; mintemp2 = Temp2; mintemp3 = Temp3; mintemp4 = Temp4; mintemp5 = Temp5; //NEUNEUNEUNEU-------------------------------------------------------------------------- // Alle Temperaturen auf ersten Wert setzen Temp101 = Temp1; Temp102 = Temp1; Temp103 = Temp1; Temp104 = Temp1; Temp105 = Temp1; Temp106 = Temp1; Temp107 = Temp1; Temp108 = Temp1; Temp109 = Temp1; Temp110 = Temp1; Temp201 = Temp2; Temp202 = Temp2; Temp203 = Temp2; Temp204 = Temp2; Temp205 = Temp2; Temp206 = Temp2; Temp207 = Temp2; Temp208 = Temp2; Temp209 = Temp2; Temp210 = Temp2; Temp301 = Temp3; Temp302 = Temp3; Temp303 = Temp3; Temp304 = Temp3; Temp305 = Temp3; Temp306 = Temp3; Temp307 = Temp3; Temp308 = Temp3; Temp309 = Temp3; Temp310 = Temp3; Temp401 = Temp4; Temp402 = Temp4; Temp403 = Temp4; Temp404 = Temp4; Temp405 = Temp4; Temp406 = Temp4; Temp407 = Temp4; Temp408 = Temp4; Temp409 = Temp4; Temp410 = Temp4; Temp501 = Temp5; Temp502 = Temp5; Temp503 = Temp5; Temp504 = Temp5; Temp505 = Temp5; Temp506 = Temp5; Temp507 = Temp5; Temp508 = Temp5; Temp509 = Temp5; Temp510 = Temp5; } //Mittlwertbildung Temp110 = Temp109; Temp109 = Temp108; Temp108 = Temp107; Temp107 = Temp106; Temp106 = Temp105; Temp105 = Temp104; Temp104 = Temp103; Temp103 = Temp102; Temp102 = Temp101; Temp101 = Temp1; Temp1 = ((Temp101 + Temp102 + Temp103 + Temp104 + Temp105 + Temp106 + Temp107 + Temp108 + Temp109 + Temp110) / 10); Temp210 = Temp209; Temp209 = Temp208; Temp208 = Temp207; Temp207 = Temp206; Temp206 = Temp205; Temp205 = Temp204; Temp204 = Temp203; Temp203 = Temp202; Temp202 = Temp201; Temp201 = Temp2; Temp2 = ((Temp201 + Temp202 + Temp203 + Temp204 + Temp205 + Temp206 + Temp207 + Temp208 + Temp209 + Temp210) / 10); Temp310 = Temp309; Temp309 = Temp308; Temp308 = Temp307; Temp307 = Temp306; Temp306 = Temp305; Temp305 = Temp304; Temp304 = Temp303; Temp303 = Temp302; Temp302 = Temp301; Temp301 = Temp3; Temp3 = ((Temp301 + Temp302 + Temp303 + Temp304 + Temp305 + Temp306 + Temp307 + Temp308 + Temp309 + Temp310) / 10); Temp410 = Temp409; Temp409 = Temp408; Temp408 = Temp407; Temp407 = Temp406; Temp406 = Temp405; Temp405 = Temp404; Temp404 = Temp403; Temp403 = Temp402; Temp402 = Temp401; Temp401 = Temp4; Temp4 = ((Temp401 + Temp402 + Temp403 + Temp404 + Temp405 + Temp406 + Temp407 + Temp408 + Temp409 + Temp410) / 10); Temp510 = Temp509; Temp509 = Temp508; Temp508 = Temp507; Temp507 = Temp506; Temp506 = Temp505; Temp505 = Temp504; Temp504 = Temp503; Temp503 = Temp502; Temp502 = Temp501; Temp501 = Temp5; Temp5 = ((Temp501 + Temp502 + Temp503 + Temp504 + Temp505 + Temp506 + Temp507 + Temp508 + Temp509 + Temp510) / 10); // MAx und Miin werte setzen if (Temp1 > maxtemp1) { maxtemp1 = Temp1; } if (Temp2 > maxtemp2) { maxtemp2 = Temp2; } if (Temp3 > maxtemp3) { maxtemp3 = Temp3; } if (Temp4 > maxtemp4) { maxtemp4 = Temp4; } if (Temp5 > maxtemp5) { maxtemp5 = Temp5; } if (Temp1 < mintemp1) { mintemp1 = Temp1; } if (Temp2 < mintemp2) { mintemp2 = Temp2; } if (Temp3 < mintemp3) { mintemp3 = Temp3; } if (Temp4 < mintemp4) { mintemp4 = Temp4; } if (Temp5 < mintemp5) { mintemp5 = Temp5; } string t1 = Convert.ToString(Math.Round(Temp1, 0)); string t2 = Convert.ToString(Math.Round(Temp2, 0)); string t3 = Convert.ToString(Math.Round(Temp3, 0)); string t4 = Convert.ToString(Math.Round(Temp4, 0)); string t5 = Convert.ToString(Math.Round(Temp5, 0)); string mt1 = Convert.ToString(Math.Round(maxtemp1, 0)); string mt2 = Convert.ToString(Math.Round(maxtemp2, 0)); string mt3 = Convert.ToString(Math.Round(maxtemp3, 0)); string mt4 = Convert.ToString(Math.Round(maxtemp4, 0)); string mt5 = Convert.ToString(Math.Round(maxtemp5, 0)); string mut1 = Convert.ToString(Math.Round(mintemp1, 0)); string mut2 = Convert.ToString(Math.Round(mintemp2, 0)); string mut3 = Convert.ToString(Math.Round(mintemp3, 0)); string mut4 = Convert.ToString(Math.Round(mintemp4, 0)); string mut5 = Convert.ToString(Math.Round(mintemp5, 0)); string DM = Convert.ToString(Drivemode); string TR = Convert.ToString(Tankreserve); string TB = Convert.ToString(Tempobegrenzung); string WM = Convert.ToString(Warnmeldung); string BMS = Convert.ToString(Freigabe_BMS); string Br = Convert.ToString(Brake); Log.WriteLog(t1, t2, t3, t4, t5, mt1, mt2, mt3, mt4, mt5, mut1, mut2, mut3, mut4, mut5, DM, TR, TB, WM, BMS, Br); Console.SetCursorPosition(0,0); //Console.Clear(); Console.WriteLine(" Seewasser vor Fahrmotor (A0) " + t1 + " Max: " +mt1 + " Min: " + mut1); Console.WriteLine(" Abwasser nach Fahrmotor (A1) " + t2 + " Max: " + mt2 + " Min: " + mut2); Console.WriteLine(" Vor Batterie / nach Wärmetauscher (A2) " + t3 + " Max: " + mt3 + " Min: " + mut3); Console.WriteLine(" Nach Batterie / vor Controller (A3) " + t4 + " Max: " + mt4 + " Min: " + mut4); Console.WriteLine(" Nach Controller / vor Wärmetauscher (A4) " + t5 + " Max: " + mt5 + " Min: " + mut5); Console.WriteLine(); Console.WriteLine(" Temperaturerhöhung durch Motor " + Math.Round((Temp2-Temp1)),0+" "); Console.WriteLine(" Temperaturerhöhung durch Batterie " + Math.Round((Temp4 - Temp3)),0); Console.WriteLine(" Temperaturerhöhung durch Controller " + Math.Round((Temp5 - Temp4)),0); Console.WriteLine(" Temperatursenkung durch Wärmetauscher " + Math.Round((Temp5 - Temp2)),0); Console.WriteLine(" "); Console.WriteLine(" Drivemode " + Convert.ToString(Drivemode)); Console.WriteLine("noch_nix " + Convert.ToString(noch_nix)); Console.WriteLine(" Tankreserve " + Convert.ToString(Tankreserve)); Console.WriteLine(" Tempobegrenzung " + Convert.ToString(Tempobegrenzung)); Console.WriteLine(" Warnmeldung " + Convert.ToString(Warnmeldung)); Console.WriteLine(" Freigabe_BMS " + Convert.ToString(Freigabe_BMS)); Console.WriteLine(" Brake " + Convert.ToString(Brake)); // Console.WriteLine(" Feuchte_oben " + Convert.ToString(Feuchte_oben)); // Console.WriteLine(" Feuchte_unten " + Convert.ToString(Feuchte_unten)); Console.WriteLine(" "); //arduino.pinMode(23, Arduino.INPUT);// Set the digital pin 9 as input Digiwert9 = arduino.digitalRead(2);//Zündung einlesen Digiwert0 = arduino.digitalRead(0);//Zündung Duplex einlesen // Console.WriteLine(Digiwert9); if ((Digiwert9 == 1) | (Digiwert0 == 1)) { Console.WriteLine(" Zündung an "); Console.WriteLine(" "); gelaufeneZeit = 0; } if ((Digiwert9 ==0) & (Digiwert0 == 0)) { Console.WriteLine(" Shut down in " + (Wartezeit-gelaufeneZeit)+" "); gelaufeneZeit = gelaufeneZeit + 1; //Thread.Sleep(500); if (gelaufeneZeit > Wartezeit) { Console.WriteLine(" System wird heruntergefahren! ");// Hier muss noch ein exit rein"); System.Diagnostics.Process.Start(System.Environment.SystemDirectory + "\\shutdown.exe", "-s"); break; } } Thread.Sleep(1000); } } } }