Start a new topic

Slow to update display Nextion with RedBear DUO ?

My display will only update the one text box named t0 every 2 to 3 seconds. I have the code used listed. If I comment out my procedure my serial prints every second as expected. If I include the call to nexWrite function the print on the display updates every 2 to 3 seconds. My DUO appears to be working ok, until I uncomment the nexWrite funtion. I can not determine why it is so slow ?


/*
 * RedBear Duo
 * 9:57 AM 8/7/2016 added Nextion lib.
 * Serial1 Pins: D17, D16
*/
int DUO = 88;
#if PLATFORM_NAME == DUO
#include "application.h"
#endif
//
#include <Nextion.h>
#include <NextionVariableString.h>
#define SKETCHNAME "nextionBasic.ino"
#define nexSerial Serial1
#define NEXTION_BAUD 9600
#define bufSize 255
#define ONESEC 1000UL
//
char buf[bufSize];
unsigned long nexMillis = 0;
//
/** Functions start here **/
void clearBuf(){ memset (buf, 0, bufSize); }
//
Nextion nex(nexSerial);
NextionVariableString t0(nex, 0, 2, "t0");
//
#if defined(ARDUINO)
SYSTEM_MODE(MANUAL);//do not connect to cloud
#else
SYSTEM_MODE(AUTOMATIC);//connect to cloud
#endif
/******* Procedures *******/
//
String runTime(){
  String Time="";
  unsigned long ss;
  byte mm,hh;
  ss=millis()/ONESEC;
  hh=ss/3600;
  mm=(ss-hh*3600)/60;
  ss=(ss-hh*3600)-mm*60;
  //if(hh<10)Time+="0";
  Time+=(String)hh+":";
  //if(mm<10)Time+="0";
  Time+=(String)mm+":";
  //if(ss<10)Time+="0";
  Time+=(String)ss;
  return Time;
}/******* END runTime *******/
//
void readNex(){
 // determine active page
 switch( nex.getCurrentPage() ){
  case 0: {
   break;
  }
  default:{
   break;
  }
 }
}/******* END readNex *******/
//
void writeNex(){
 // determine active page
 switch( nex.getCurrentPage() ){
  case 0: { // first page
     //
     clearBuf();
     runTime().toCharArray(buf,sizeof(buf));
     t0.setText( buf ); 
     break;
    }
  case 1: { // second page
     //
     break;
    }
  default: {
     //
     break;
    }
 }
}/******* END writeNex *******/
//
void setupNextion(){
 //
 nexSerial.begin(NEXTION_BAUD);
 nex.init();
}/******* END setupNextion *******/
//
void setup() {
 //Initialize serial and wait for port to open:
 Serial.begin(115200);
 while (!Serial) {delay(ONESEC/3);}
 delay(ONESEC*5);
 Serial.println("SketchName: nextionBasic.ino");
 //
 setupNextion();
}/******* END setup *******/
//
void loop() {
 if ( nexMillis > millis() ) {
  return;
 }
 Serial.print(runTime());
 Serial.println(" writeNex");
 // writeNex();
 nexMillis = millis() + ONESEC;
}/******* END loop *******/


What is you ultimate goal here?


I could not determine the slow updating, after replacing the breadboard connecting wire  from TX to mcu pin, problem is gone, now updating fine.

Login or Signup to post a comment