Arduino Pyserial communication problems

I'm basically sending an array of strings coming from a csv file to the arduino - using python 2.7 btw.

My problem is that the arduino stops receiving strings (at about 12 strings).

If anyone can see anything, that could be causing the problem I'd appreciate any help. I've attempted using various time.sleep(s) around the code as I've read many things - it takes awhile to initialize the port after serial.serial(). I've even tried waiting after all the data has been sent - before the comport must be read by the python code (that's my main method to check). I also have been using a software serial rx rx pins to a seperate usb to serial device (I don't rely on its output because it's cheap). I've also experimented with every Baud rate usable and no dice.

Here's the python code: `

import serial
import time
ser = serial.Serial('COM3', 9600, timeout=0)
file = open('C:\\samples.csv')
time.sleep(2)
while 1:
        line = file.readline()
        print line
        if not line:
                break
        ser.write(line)
        #time.sleep(4)
time.sleep(20)        
while 1:
        try:
                print ser.readline()
                time.sleep(1)
        except ser.SerialTimeoutException:
                print('Data could not be read')
                time.sleep(1)`

and here is the arduino code - the linkedlist library I have tested and it works (can be found on github from user ivanseidel:)

 #include <analogShield.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(18, 19); // RX, TX
#include <LinkedList.h>

unsigned int full = 65536;
unsigned int zero = 32767;

//SoftwareSerial mySerial(18, 19); // RX, TX
LinkedList<String> myLinkedList = LinkedList<String>();
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. 
  }


  //Serial.println("TESTING...");

  //
  delay(20000);
}

void loop() { // run over and over

  if (Serial.available()) {
    String s = Serial.readString();
    myLinkedList.add(s);
    mySerial.println(s);
    //delay(1);

  }
  else {
    Serial.println("THIS IS LIST "  );
    Serial.println(myLinkedList.size());
    for (int i = 0; i<myLinkedList.size();i++) {
      //unsigned int volt = myLinkedList.get(i);
      Serial.println(myLinkedList.get(i));
      //analog.write(0,volt);
      //delay(1);
      //delayMicroseconds(8);

      }

    while (true) {
      //analog.write(0,zero);  
    }
    }
}

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

My wild guess is that your memory is getting corrupted.

I suspect the LinkedList is also unsuitable for the small memory of an Arduino.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

This Python - Arduino demo may be of interest.

...R