Can't user Serial1 and Serial when cable is not connected

Hello,

Let me to explain the subject:

I am in development of a software who communicates over GPRS with a GSM module I can use perfectly thanks to arduino and so many work.

The problem, if it can be called "problem", is that everything went OK while developing. I mean, if I connect the usb cable of the arduino Leonardo into the PC, and use Serial for that communication (just debugging routines), and Serial1 to communicate with the module, it works perfect. I can see debug info I've coded, and the communication over network with GPRS technology is great.

The problem comes when I don't connect the USB cable to the PC and then I power it on with battery. Everything switches ON, and I can see the lights working Okay. But, I've no response of the board on my internet service... So, I guess the problem is the Serial1 communication with the mobile board, as I am sure Serial1 becomes Serial when USB cable is not connected...

So, how can I use the correct Serial in the code when USB cable is not connected, without making 2 releases of the same program? Debug and Production, for example.

Thanks in advance,

hope you have a nice day.

Abel.

p.s. sorry my bad english, really.

as I am sure Serial1 becomes Serial

You are almost surely mistaken about that.

"being sure" about something, is almost always a bad idea. It tends to blind you from seeing the real problem.

The first two things I would do :

Check that your system is indeed properly powered and grounded when it is battery powered.

Check that there is no place in your code, where the program waits for an input or output on the Serial ( the connection to your computer ), and waits and waits and waits, because it is not connected.

Id guess that it is probably waiting on serial connection on pc. you may have to write a time out in there so it quits waiting after a sec or two

abeltomillo:
The problem comes when I don't connect the USB cable to the PC and then I power it on with battery. Everything switches ON, and I can see the lights working Okay. But, I've no response of the board on my internet service... So, I guess the problem is the Serial1 communication with the mobile board

There is a common convention of putting code in setup() which waits until the Serial port has initialised. On some boards, this will block the sketch until a PC application opens the serial port:

  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

If you have this code in your setup() function, I suggest you take it out.

abeltomillo:
I am sure Serial1 becomes Serial when USB cable is not connected...

I am sure it does not.

thanks a lot for the answers,

i remember i deleted this post as i solved the problem, it was a reading problem of the gsm module. sometimes working, sometimes not working. but the leonardo's hw serial1 worked like a charm!

sorry to be late.

i'll try to dont be sure of everything, i'll try to see the real problem :wink:

thanks!!!