Unsure what happened : "Error inside Serial.serialEvent()"

Hello, i posted this in the Programming section and then found out it's not a software problem but (possibly) something to do with electrical interference ?

Here are the two threads which most resemble my situation;

Trouble with arduino nano serial resetting - Arduino Forum
forum.arduino.cc/index.php?topic=145981.0

Error inside Serial.serialEvent() - Arduino Forum
forum.arduino.cc/index.php?topic=49261.0

The difference is i don't use the 3V3 line, could anyone give some pointers on what next to troubleshoot ?

Below is the thread previously posted;
============================

Am learning to access an SD card and then displaying the contents to an LCD.
I have a Nano-compatible connected to the LCDisplay via I2C and SD card module via SPI.
Both modules work using them one at a time but now the difficulties start when i start combining them together.

The code actually works, but sometimes the LCDisplay doesn't lcd.clear() - i thought it was the code but discovered that it works after i closed and then opened the Serial Monitor (for debugging).

And now i encounter an error message which i have no idea about - is this hardware related ? (or bad setup??)

Here's the error message;

Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
	at gnu.io.RXTXPort.nativeavailable(Native Method)
	at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
	at processing.app.Serial.serialEvent(Serial.java:258)
	at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
	at gnu.io.RXTXPort.eventLoop(Native Method)
	at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)

<<...repeats again...>>

i also notice a red LED is lit up on the Nano (Iteaduino Nano) which is visible in the pic below.

this is the code itself;

/*
** Example Arduino sketch for SainSmart I2C LCD Screen 16x2
** by Edward Comer
** uses F Malpartida's NewLiquidCrystal library.

 */
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

#define I2C_ADDR    0x20 //
#define BACKLIGHT_PIN     7
// using MJKDZ board
#define En_pin  4    
#define Rw_pin  5   
#define Rs_pin  6   
#define D4_pin  0   
#define D5_pin  1   
#define D6_pin  2   
#define D7_pin  3   

LiquidCrystal_I2C	lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

/*
 SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 10
                           created  24 Nov 2010
                           modified 9 Apr 2012       by Tom Igoe
 
 This example code is in the public domain.
 */
#include <SD.h>
// Note that even if it's not used as the CS pin, the hardware CS pin
// must be left as an output or the SD library functions will not work.
const int chipSelect = 10;


void setup()
{
  lcd.begin (16,2);
  //Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  lcd.print("LCD connected");  

  Serial.begin(9600);

  Serial.print("Initializing SD card...");
  // make sure default chip select pin is set to output
  pinMode(10, OUTPUT);
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
} // end setup()

String readChar;
int posChar;

void loop()
{
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("what2prn.txt");  // default as FILE_READ
  lcd.clear();
  
//  lcd.autoscroll();
  
if (dataFile) {
    while(dataFile.available())  {
    // it's THIS SIMPLE - display byte-by-byte, NO need String var
    lcd.write(dataFile.read());
//    lcd.autoscroll();
    }
//
  posChar = 0;
  lcd.setCursor(posChar,1);
  lcd.write("End of file reached");
  Serial.println("End of file reached");
  delay(500);
  Serial.println("Clearing LCDisplay");
  lcd.clear();  
  delay(500);
 //
  }
}

i can also add some further observations, at times, it works for a few loops and then seizes up - that's when the red LED stays on.
(and related to some questions on the other threads on this error message, closing the Serial monitor and reopening it does "help" - the code runs again and then seizes up with the red LED once more.

is there some gradual build up of interference then ?

a closer look at the layout.

also, the code loops about 14 times before seizing up, sometimes the LCDisplay works, sometimes not.

EDIT:
here's the microcontroller being used;
http://imall.iteadstudio.com/im130615004.html
the datasheet;
ftp://imall.iteadstudio.com/Mainboard/IM130615004_ITeaduino_Nano/DS_IM130615004_Iteaduino_Nano.pdf

and a section from that manual that might be relevant;
(it uses a DP-2102 chip which i believe is different from the Arduino Nano)

Automatic (Software) Reset:
Rather than requiring a physical press of the reset button before an upload, the Iteaduino Nano is designed in a way that allows it to be reset by software running on a connected computer. One of the hardware flow control lines (CTS/RTS) of the DP2102 is connected to the reset line of the ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. This means that the bootloader can have a shorter timeout, as the lowering of CTS/RTS can be well-coordinated with the start of the upload. This setup has other implications. When the Nano is connected to either a computer running Mac OS X or Linux, it resets each time a connection is made to it from software (via USB). For the following half-second or so, the bootloader is running on the Nano. While it is programmed to ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first few bytes of data sent to the board after a connection is opened. If a sketch running on the board receives one-time configuration or other data when it first starts, make sure that the software with which it communicates waits a second after opening the connection and before sending this data.

but; i'm using WIndows XP SP3

does anybody have any idea ?

is this a "de-coupling" Issue ?

what is the Error message telling me exactly ?

The error message means that the file descriptor the Java code was using is no longer
valid to the operating system (the files closed). For historical reasons "file descriptor"
really means "stream descriptor", no actual file is required, here its the serial connection.

The USB serial connection closed for some reason. That's something to take up with
your operating system - one reason could be the USB plug's not secure, but there
are various possibilities.

The SerialEvent is likely the one saying that the stream closed unexpectedly I'd guess!

Is the problem you describe here the same problem you describe there...
http://forum.arduino.cc/index.php?topic=213167.0

not just the same problem but the exact same thread, that's why i indicated "there" that i'd post it "here".
i also modified the thread to [DUPLICATE] so a moderator could lock it or something, and just use the thread "here".
should i just give the link to this thread "here" and then that thread can be locked ?

if it is a decoupling issue, then one should put capacitors at these marked places, right ?

retronet_RIMBA1ZO:
should i just give the link to this thread "here" and then that thread can be locked ?

I'll deal with the mess later.

Next time ask a moderator to move the thread.