So im building a system wich recieves 10 bytes of data from a robotic cameraplatform every 33 milliseconds. The data is read from a serial port and then processed and sent as String via another serial port to a nextion display.
The problem is as soon as i try to send more than 2 Strings in a single loop, the data recieved by the display is screwed up and wrong. Anyone knows why this is?
I use the following code, and yes i know the variable calculations are uggly as shit...
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin (2400);
Serial1.flush();
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial1.available()>10)
{
int inData[10];
int i=0;
for (i=0; i<=9; i++)
{
inData*=Serial1.read();*
-
}*
-
int azLSB = inData[0];*
-
int azMSB = inData[1];*
-
int elLSB = inData[2];*
-
int elMSB = inData[3];*
-
int styrning =inData[8];*
-
String styr;*
-
unsigned int azTemp = (azMSB<<8) | azLSB;*
-
unsigned int elTemp = (elMSB<<8) | elLSB;*
-
long azTemp2 = azTemp-32768;*
-
long elTemp2 = elTemp-32768;*
-
float faktor = (360.000/65536.000);*
_ float azTemp3 = (azTemp2 * faktor);_
_ float elTemp3 = (elTemp2 * faktor);_ -
float azNextion = -azTemp3;*
-
float elNextion = elTemp3;*
-
String stringAz =String(azNextion,3);*
-
String stringEl = String(elNextion,3);*
-
if (styrning == 1)*
-
{*
-
styr = ("Joystick");*
-
}*
-
if (styrning == 2)*
-
{*
-
styr = ("Radar");*
-
}*
-
if (styrning == 3)*
-
{*
-
styr = ("UNIPOS");*
-
}*
-
if (styrning == 4)*
-
{*
-
styr = ("Prediktor");*
-
}*
-
Serial.print("t2.txt=");*
-
Serial.print(""");*
-
Serial.print(stringAz);*
-
Serial.print(""");*
-
Serial.write(0xFF);*
-
Serial.write(0xFF);*
-
Serial.write(0xFF);*
-
Serial.print("t3.txt=");*
-
Serial.print(""");*
-
Serial.print(stringEl);*
-
Serial.print(""");*
-
Serial.write(0xFF);*
-
Serial.write(0xFF);*
-
Serial.write(0xFF);*
-
Serial.print("t4.txt=");*
-
Serial.print(""");*
-
Serial.print(styr);*
-
Serial.print(""");*
-
Serial.write(0xFF);*
-
Serial.write(0xFF);*
-
Serial.write(0xFF); *
}
}