Need some help with displaying serial data


i using softwareserial write serial lcd , communicate scale. message scale capital w. return message scale looks "02 000.00 /r 02 indicates start of message , carriage return indicates end of message. it's ascii data being received.

in code attempt trigger on 0x02 , put rest of data string called inputstring. when '/r' received want print out inputstring string. think i've made not store start character '02' , end character '/r' crazy characters printing.

in setup use statement- inputstring.reserve(16); define size of inputstring. i've tried making 6, 7, & 8 and16 bytes acts same. using logic analyzer going arduino pin data looks perfect everytime. seems i'm overflowing buffer or reading in data somehow don't want. doing wrong?

code: [select]

void loop() {
  delay(2000);                                         
  float = sonar[currentsensor].ping_median(20);    // send ping, ping time in microseconds (us).
  serial.print(us / us_roundtrip_in);
  lcdserial.write(0x8c);         // move line 0 position 12
  lcdserial.print("       ");    // clear data area
  lcdserial.write(0x8c);         // move line 0 position 12
  lcdserial.print(us / us_roundtrip_in);
  lcdserial.write(0x22);        // inches (")
  serial.println("in");

  scaleserial.write(0x57);       // send "w"
  scaleserial.listen();
  inchar = scaleserial.read();
  if (inchar = 0x02) {
    while (scaleserial.available() > 0) {
      inchar = scaleserial.read();
      if (inchar == '\r') {
        serial.println(inputstring);
        lcdserial.write(0xc8);         // move line 0 position 12
        lcdserial.print("       ");    // clear data area
        lcdserial.write(0xc8);         // move line 0 position 12
        lcdserial.print(inputstring);
        inputstring = "";       
      }
      else {
        inputstring += inchar;     
      }
    }
  }
}


i've attached screen shot of terminal monitor. should this:

0.00"
000.15
0.00"
000.15

but can see garbage in photo prints. 000.15 showing there .15 lbs of weight on scale @ present.

thanks.

code: [select]
if (inchar = 0x02)
oops


Arduino Forum > Using Arduino > Programming Questions > Need some help with displaying serial data


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'