Portenta H7 with Nextion Serial Strings Read

Hello everyone, I need some help.

I have a Portenta H7 and a Nextion display and would like to read serial strings and also output texts on the display.

The strange thing is when I connect it to an Arduino Mega via interface 0.1 then it works.

I would like to use UART 1 or UART 2 with the Portenta.

Can someone maybe show me a code how to read continuously without errors? I've never seen that before.

So i will paid via Paypal if you help me

Thank you


// +++++++++++++  INPUTS FROM DISPLAY TO MEGA ++++++++++++
// SERIELLE BUTTON/TEXT KOMMUNIKATION INFO
// Interlock EXT1 = "BT98ON" "BT98OFF"
// Interlock EXT2 = "BT99ON" "BT99OFF"
// Interlock RESET = "ERESET"
// Interlock 1-8 Select = "IL18ON" "IL18OFF"
// Interlock 9-16 Select = "IL916ON" "IL916OFF"
// Interlock 16-24 Select = "IL1724ON" "IL1724OFF"
// Interlock 24-32 Select = "IL2532ON" "IL2532OFF"
// Interlock ALL ON/OFF "ALLON" "ALLOFF"
// SYSTEM RESTART = "SReset"
// LED SYSTEMTEST = "TLEDON" "TLEDOFF"

// +++++++++++++  OUTPUT FROM ARDUINO TO MEGA ++++++++++++
// PAGE 2 t1.txt HAUPTSTATUS ANZEIGE
// PAGE 2 t4.txt KEYSWITCH ON/OFF

//#####################################################################################################
//SETUP CONTROLLER
//#####################################################################################################
// GENERAL INPUTS 
int ESTOPIN= 4;       // EINGANG ESTOP IN FÜR MELDUNG
int KEYSWITCH=5;      // EINGANG KEYSWITCH IN FÜR MELDUNG
int RESETEXT=6;    // EINGANG RESET TASTE INTERN

// GENERAL OUTPUTS

int OUT1= 14;        // AUSGANG RELAIS 1 SEKTION 1-8
int OUT2= 15;        // AUSGANG RELAIS 2 SEKTION 9-16
int OUT3= 16;        // AUSGANG RELAIS 3 SEKTION 17-24
int OUT4= 17;        // AUSGANG RELAIS 4 SEKTION 25-32
int OUT5= 18;        // AUSGANG RELAIS 5 RESET
int OUT6= 19;        // AUSGANG 
int OUT7= 20;        // AUSGANG 
int OUT8= 21;        // AUSGANG 






void setup() {
  // STARTE COMMUNICATION
  Serial.begin(9600);
  Serial.println("SERIAL 1 BEGINN");

  // DEFINIERTE E/As
  pinMode(ESTOPIN, INPUT_PULLUP); 
  pinMode(KEYSWITCH, INPUT_PULLUP); 
  pinMode(RESETEXT, INPUT_PULLUP); 
  pinMode(OUT1, OUTPUT); 
  pinMode(OUT2, OUTPUT); 
  pinMode(OUT3, OUTPUT); 
  pinMode(OUT4, OUTPUT); 
  pinMode(OUT5, OUTPUT); 
  pinMode(OUT6, OUTPUT); 
  pinMode(OUT7, OUTPUT); 
  pinMode(OUT8, OUTPUT); 

}
  


//#####################################################################################################
//AUFRUF PROGRAMM
//#####################################################################################################

void loop() {

  if(Serial.available()){                                   //++++++++++++++++++++++++++++++++++++++++++
  String data_from_display="";                              // LADE SCHNITSTELLE UND SCHREIBE STRING
  delay(50);                                                //++++++++++++++++++++++++++++++++++++++++++                             
    data_from_display += char(Serial.read());
  }

  ESTOPIN =     digitalRead(4);                             //+++++++++++++++++++++++++++++++++++++++++++
  KEYSWITCH =   digitalRead(5);                             // EINLESEN VON EINGÄNGEN
  RESETEXT=  digitalRead(6);                                //+++++++++++++++++++++++++++++++++++++++++++
 






  {                                                         //+++++++++++++++++++++++++++++++++++++++++++
  if(KEYSWITCH == LOW){                                     // FUNKTION MELDUNG KEYSWITCH OFF/ON                         
  Serial.print("t1.pco=65504");                             //+++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"OFF\"");                          // SENDE TEXT AN DISPLAY KEYSWITCH OFF
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}
  else if(KEYSWITCH == HIGH){                             // FUNKTION KEYSWITCH ON 
  Serial.print("t1.pco=1024");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"ON\"");                          // SENDE TEXT AN DISPLAY KEYSWITCH ON
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}                                                         //++++++++++++++++++++++++++++++++++++++++++++++
 else if(ESTOPIN == LOW){                                 // FUNKTION MELDUNG NOTAUS
                                                          //++++++++++++++++++++++++++++++++++++++++++++++
  delay(30);
  digitalWrite(OUT5, LOW);
  delay(30);
  Serial.print("b1.bco=65504");                           
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("b1.pco=63488");                           // SENDE TEXT AN DISPLAY EMERGENCY STOP // TASTER NEGATION
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.pco=63488");                           
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"EMERGENCY STOP!\"");             // SENDE TEXT AN DISPLAY EMERGENCY STOP // TASTER NEGATION
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff); 
}
 else if(ESTOPIN == LOW && KEYSWITCH == HIGH){               
  delay(30);
  digitalWrite(OUT5, LOW);
  delay(30);
  Serial.print("b1.bco=65504");                           
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("b1.pco=63488");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);         
  Serial.print("t1.pco=63488");                         
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"EMERGENCY STOP!\"");             // SENDE TEXT AN DISPLAY EMERGENCY STOP // TASTER NEGATION
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff); 
}

else if(ESTOPIN == HIGH){
  Serial.print("SYSSTATE.pco=63488"); 
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("SYSSTATE.txt=\"\"");                            // LEERE TEXT WENN KEIN NOTAUS // TASTER NEGATION
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff); 
}                                                         //++++++++++++++++++++++++++++++++++++++++++++++
else if(ESTOPIN == HIGH && KEYSWITCH == LOW){             // FUNKTION MELDUNG SYSTEM STARTBEREIT        
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"SYSTEM READY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"WAIT FOR KEY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"SYSTEM READY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"WAIT FOR KEY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"SYSTEM READY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  delay(500);
  Serial.print("t1.pco=1024");                            //++++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"WAIT FOR KEY!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}                                                          //+++++++++++++++++++++++++++++++++++++++++++++
  else if(ESTOPIN == HIGH && KEYSWITCH == HIGH){           // FUNKTION MELDUNG LASER EMISSION OFF/ON        
  Serial.print("t1.pco=65504");                            //++++++++++++++++++++++++++++++++++++++++++++
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.print("t1.txt=\"LASER EMISSION ON!\"");
  Serial.write(0xff);
  Serial.write(0xff);
  Serial.write(0xff);
}
}
}  



                                                          //+++++++++++++++++++++++++++++++++++++++++++++
void sendData(String data_from_display){                  //EMFANGENE DATEN VON DISPLAY STRING                                                         
                                                          //+++++++++++++++++++++++++++++++++++++++++++++
  
  
  if(data_from_display =="IL18ON"){                       // SEKTION ANWAHL BUTTON INTERLOCK 1-8 ON
  delay(30);
  digitalWrite(OUT1, HIGH);
  delay(30);                    
}
  else if (data_from_display =="IL18OFF"){                // SEKTION ANWAHL BUTTON INTERLOCK 1-8 OFF
  delay(30);
  digitalWrite(OUT1, LOW);
  delay(30);   
}
 else if (data_from_display =="IL916ON"){                // SEKTION ANWAHL BUTTON INTERLOCK 9-16 ON
  delay(30);
  digitalWrite(OUT2, HIGH);
  delay(30);   
}
 else if (data_from_display =="IL916OFF"){                // SEKTION ANWAHL BUTTON INTERLOCK 9-8 OFF
  delay(30);
  digitalWrite(OUT2, LOW);
  delay(30);   
}
 else if (data_from_display =="IL1724ON"){                // SEKTION ANWAHL BUTTON INTERLOCK 17-24 ON
  delay(30);
  digitalWrite(OUT3, HIGH);
  delay(30);   
}
 else if (data_from_display =="IL1724OFF"){                // SEKTION ANWAHL BUTTON INTERLOCK 17-24 OFF
  delay(30);
  digitalWrite(OUT3, LOW);
  delay(30);   
}
 else if (data_from_display =="IL2532ON"){                // SEKTION ANWAHL BUTTON INTERLOCK 25-32 ON
  delay(30);
  digitalWrite(OUT4, HIGH);
  delay(30);   
}
 else if (data_from_display =="IL2532OFF"){                // SEKTION ANWAHL BUTTON INTERLOCK 25-32 OFF
  delay(30);
  digitalWrite(OUT4, LOW);
  delay(30);   
}
 else if (data_from_display =="ALLON"){                   // SEKTION ANWAHL INTERLOCK ALLE ON
  delay(30);
  digitalWrite(OUT1, HIGH);
  digitalWrite(OUT2, HIGH);
  digitalWrite(OUT3, HIGH);
  digitalWrite(OUT4, HIGH);
  delay(30);   
}
else if (data_from_display =="ALLOFF"){                   // SEKTION ANWAHL INTERLOCK ALLE OFF
  delay(30);
  digitalWrite(OUT1, LOW);
  digitalWrite(OUT2, LOW);
  digitalWrite(OUT3, LOW);
  digitalWrite(OUT4, LOW);
  delay(30);
}    






}

may be this can help

I see you double posted

I'm closing this thread

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum. It will help you get the best out of the forum in the future.

Thank you.