arduino serial erratic behaviour missing characters

I have a problem with the hardware serial on the UNO, in many occasions it seems to drop a character (usually the first character being received) and in some cases it misses a whole transmission. this only occurs when the Arduino is receiving data from the computer typed by me in the serial monitor. I can see the RX light flashing when I send the string but the arduino just completely ignores it.

The data I am sending is three comma separated 8 bit unsigned integers

#include <Adafruit_NeoPixel.h>
    //#include <OneSheeld.h>
    
    #define PIN 6
    #define LEDS 5
    
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN, NEO_GRB + NEO_KHZ800);
    int leds = LEDS-1;
    byte red;
    byte green;
    byte blue;
    int i;
    // pins for the LEDs:
    //const int red = 3;
    //const int green = 5;
    //const int blue = 6;
    
    void setup() {
      // initialize serial:
      Serial.begin(9600);
      strip.begin();
      strip.setPixelColor(0,12,12,12);
         strip.show(); // Initialize all pixels to 'off'
         Serial.print("number of LEDS in strip:");
         Serial.println(LEDS);
         i=0;
      // make the pins outputs:
    //  pinMode(redPin, OUTPUT); 
    //  pinMode(greenPin, OUTPUT); 
    //  pinMode(bluePin, OUTPUT); 
    
    }
    
    void loop() {
      red = 0;
      green=0;
      blue= 0;
      
     // i=0;
      // if there's any serial available, read it:
      while (Serial.available() > 0) {
    
        // look for the next valid integer in the incoming serial stream:
          red = Serial.parseInt(); 
        // do it again:
          green = Serial.parseInt(); 
        // do it again:
           blue = Serial.parseInt();
           delay(1);
    
        // look for the newline. That's the end of your
        // sentence:
        if (Serial.read() == '\n') {
          // constrain the values to 0 - 255 and invert
          // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
    //      red = constrain(red, 0, 255);
    //      green = constrain(green, 0, 255);
    //      blue = constrain(blue, 0, 255);     
             Serial.print("LED being served = ");
             Serial.println(i);
           
    
          // fade the red, green, and blue legs of the LED: 
          
    //      analogWrite(redPin, red);
    //      analogWrite(greenPin, green);
    //      analogWrite(bluePin, blue);
          strip.setPixelColor(i,red,green,blue);
          strip.show();
    
          // print the three numbers in one string as hexadecimal:
          Serial.print("R=");
          Serial.println(red);
          Serial.print("G=");
          Serial.println(green);
          Serial.print("B=");
          Serial.println(blue);
         
         if(i==leds)
         i=0;
         else
         i=i+1;
        }
      }
    }

and here is some example output from the serial monitor when entering the following string
string: <25,25,25>

output:

number of LEDS in strip:5
    LED being served = 0
    R=25
    G=25
    B=25
    LED being served = 1   <<< this transmission got lost the first time it was sent
    R=25
    G=25
    B=25
    LED being served = 2
    R=25
    G=25
    B=25
    LED being served = 3
    R=5
    G=25
    B=25
    LED being served = 4 <<< This transmission got lost the first 4 times it was sent
    R=5
    G=25
    B=25
    LED being served = 0
    R=25
    G=25
    B=25
    LED being served = 1
    R=25
    G=25
    B=25
    LED being served = 2
    R=25
    G=25
    B=25
    LED being served = 3
    R=25
    G=25
    B=25
    LED being served = 4
    R=5
    G=25
    B=25
    LED being served = 0
    R=25
    G=25
    B=25
    LED being served = 1
    R=5
    G=25
    B=25
    LED being served = 2
    R=25
    G=25
    B=25
    LED being served = 3
    R=25
    G=25
    B=25
    LED being served = 4
    R=25
    G=25
    B=25

Thanks!

There is nothing wrong with Serial. The problem is in your code and the way you are trying to read the data. Get rid of the use of ParseInt() and do the job properly.

Mark

I commented out the calls to the Adafruit library and ran the code just fine. However, if I included the angle brackets ("<", “>”) as part of the string, the parseint method fails. I don’t know if you’re doing that or not, but your post says you are. Remove the brackets and see what happens.

Does parseInt() eat the delimiter after the digits? If so then that's where your '\n' may have gone.

Hi, thanks for all the replies, I am fairly new to arduino and the code that does the reading was taken directly from the ReadASCIIString example found under >file>examples>ReadASCIIString I am not really sure how to fix my code or do it properly, an example would be greatly appreciated!

thank you

More than an example. http://gammon.com.au/serial