Sketch not processing all recieved serial data


hi guys/girls

i have sketch reads incoming serial data, displays on 5x led 7 segment displays via max7219 chip.

the serial data comes in identifier , value, separated colon - eg 9918:25000

the sketch assign value variable, , update displays
there little code split value digits each display , omit leading 0

one variable tells display show dashes if set 1, otherwise shows full value.

it works, , values change correctly of time, switching blanking variable 1 0, doesn't change display.  have 3-5 times change sometimes, other times if works fine.

to troubleshoot, have tried changing baud rate 9600 right 115200, have tried uno, mega , arm 32 board same results.

i have attached serial monitor serial source, , data coming in correctly, when displays dont change. rx light on board flickers every time well, not data coming in.

i have more complex sketch same thing, randomly doesn't update.
it seems more when value set or 0.

both sketches use same serial input processing, im thinking that.

anything standing out have missed? or there better way handle serial input?
 

sketch in question:
code: [select]

#include "ledcontrol.h"

ledcontrol lc=ledcontrol(5,6,7,1);  //data, clock, load, device

unsigned long delaytime=5;

const int devid = 99; 
const int flt1 = 18;    //flt alt
const int dash1 = 19;
int dash2;
int flt2;
int port;
int sts;
int stsold;
int dim;
int u1;
int t1;
int h1;
int th1;
int tth1;

void setup() {
  lc.shutdown(0,false);
  lc.setintensity(0,9);
  lc.cleardisplay(0);
  lc2.shutdown(0,false);
  lc2.setintensity(0,9);
  lc2.cleardisplay(0);
serial.begin(9600);

}



void loop() {

  if (serial.available()) {
    port = serial.parseint();   //get identifier
    sts = serial.parseint();    //get value
    delay(5);
   

  if ((port != 0) && (port - (devid * 100) == flt1))
  {
  flt2 = sts;
  }

  if ((port != 0) && (port - (devid * 100) == dash1))
  {
  dash2 = sts;
  }
   updatedisplay1();
  }
}


void updatedisplay1(){

  if (dash2 == 1) {

  lc.setchar(0,1,'-',false);
  delay(delaytime);
  lc.setchar(0,2,' ',false);
  delay(delaytime);
  lc.setchar(0,3,'-',false);
  delay(delaytime);
  lc.setchar(0,4,' ',false);
  delay(delaytime);
  lc.setchar(0,5,'-',false);
  delay(delaytime);
  }
 
  else
  {
  u1=flt2%10;
  t1=(flt2/10)%10;
  h1=(flt2/100)%10;
  th1=(flt2/1000)%10;
  tth1=(flt2/10000)%10;
  lc.cleardisplay(0);
 
  if (tth1 > 0)
  {
  lc.setchar(0,5,tth1,false);
  delay(delaytime);
  }
  else
  {
  lc.setchar(0,5,' ',false);
  delay(delaytime);
  }
 
  lc.setchar(0,4,th1,false);
  delay(delaytime);
 
  lc.setchar(0,3,h1,false);
  delay(delaytime);
   
  lc.setchar(0,2,t1,false);
  delay(delaytime);
     
  lc.setchar(0,1,u1,false);
  delay(delaytime);
     
    }
}



maybe add h (and cpp) files well? or link them if got them somewhere.

what format of data send?never mind.

and have @ serial input basics how reliably read serial data.



Arduino Forum > Using Arduino > Programming Questions > Sketch not processing all recieved serial data


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???