Sketch starts only after opening the serial monitor

Hello everyone,

I have a problem with my Ardunio Uno, I ve connected an RFID reader an the LCD display of seeedstudios. The arduino sketch starts only after opening the serial monitor. When connected to only to the power supply or the usb port the programm doesnt start.

#include <SerialLCD.h>
#include <SoftwareSerial.h>
#include <WiFly.h>	
#include <SoftwareSerial.h>   // for xbee shield v1.1
#ifndef __CREDENTIALS_H__
#define __CREDENTIALS_H__
SoftwareSerial serial2 (3, 4); // for xbee shield v1.1
char passphrase[] = "";
char ssid[] = "camo";
char ntp_server[] = "nist1-la.ustiming.org"; // or your favorite ntp server.
#endif
byte server[] = { xxx, xxx, xxx, xxx}; // 
WiFlyClient client("xxx.xxx.xx.xxx", yy);
#define DEVICE_NAME "Alpha"

//RFID
SoftwareSerial RFID (10, 11);
int val = 0;
char code[10];
int bytesread = 0;

//Display
SerialLCD slcd(12,13);


void setup(void)
{
 slcd.begin();
 Serial.begin(9600);
 Serial.println("Setup started");
 serial2.begin (9600);  // for xbee shield v1.1
 delay(1000);
 WiFly.setUart(&serial2);
 WiFly.begin();
 while (!WiFly.join(ssid)){Serial.println("Association failed.");delay(1000);}
 // RFID
 RFID.begin (9600);
 Serial.println("Setup finished");
}

void loop(void)
{  
Serial.println("Loop started");

if(RFID.available() > 0) { // if data available from reader
if((val = RFID.read()) == 2) { // check for header
bytesread = 0;
while(bytesread<10) { // read 10 digit code

if( RFID.available() > 0) {

val = RFID.read();

if((val == 2)||(val == 3)) { // if header or stop bytes before the 10 digit reading

break; // stop reading

}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread == 10) { // if 10 digit read is complete
 	Serial.print("TAG code is: "); // possibly a good TAG
 	Serial.println(code); // print the TAG code
 	if (client.connect ())
 	{
     	slcd.clear();
     	client.print ("get http://xxx.xxx.xxx.xxx/sensor/3c1fd199800e47b2fb2735f95ed2af3dcd6e8ceb/device/");
     	client.print (DEVICE_NAME);
     	client.print ("/RackNr/");
     	client.print (code);
     	slcd.print (code);
     	Serial.println("RackNr on Display!");
     	Serial.println("Message sent!");
 	 
 	}
     	client.stop ();
     	delay (2000);
}
   bytesread = 0;
}

//end
}
}

Would be great to find a solution for this. Thanks!

The arduino sketch starts only after opening the serial monitor.

Is that still the case if you comment out all the Serial method calls?

Including SoftwareSerial.h once is usually sufficient.

The #define/#endif guard to prevent multiple inclusions is hardly needed in the sketch.

The SerialLCD class is using SoftwareSerial, too. Multiple instances of SoftwareSerial need to be used with care. Only one instance at a time can listen. You need to be sure to make the RFID-reader active again after EVERY call to write to the LCD.

Having three instances of SoftwareSerial as well as an instance of HardwareSerial is a sure sign that you are using the wrong hardware.

Hi Pauls,

I disabled the LCD display. This is not really necessary for the application. Now the RFID reader works fine.

I will try to include the LCD again later.

Thank you for the help!