Serial.read() will not recieve repeating characters.


hi, i'm working on sketch read serial data. works when send duplicate characters funny data returning.
ex
if send:
123456789012345678901234567890
i get:
123456789012345678901234567890

however if send:
111111111222222222333333333333344444444444
i get:
11±1±1±1±22²2²2²2²233³3³3³3³344´4´4´4´4´

i have tried several things adding time delays, removing libraries may have conflicted different serial data sources. no improvement. can 63 characters despite changing buffer size command

#define _newss_max_rx_buff 128

any appreciated

code: [select]
#include <newsoftserial.h>
newsoftserial myserial(4, 5);
//#include <serialglcd.h>
#define _newss_max_rx_buff 128 // rx buffer size

char string[128];
int count2 = 0;
int availablebytes;
void setup(){

  // initialize serial communications:
  serial.begin(9600);
  myserial.begin(9600);
 
  pinmode(8,output); //max 485 power
  pinmode(13,output); //system latch
  pinmode(10,output); // 485 write enable
 
  delay(1000);
  digitalwrite(8, 1); 
  digitalwrite(13, 1); 
  digitalwrite(10, 0);
  delay(1000);
}

// serialglcd lcd; // initialisation
void loop()
{
  serial.flush(); // clear buffer
  while(myserial.available() == 0) // wait new data
  {
  }
  delay(500); // wait data
  availablebytes = myserial.available();

  for(int i=0; i<availablebytes; i++)
  {
    delay(2);
    string[i] = myserial.read();  //read array later processing
  }

  while(count2 < availablebytes)
  {
    delay(5);
    serial.print(string[count2]); // display testing
    count2 = count2+1;
  }
  count2 = 0;   
}



i don't delays, nor flush. read hints:

http://www.gammon.com.au/serial


Arduino Forum > Using Arduino > Programming Questions > Serial.read() will not recieve repeating characters.


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial