Program only works when serial monitor is open

Hi,

I made a GPS system and want it to be able to work on a 9V battery.
Everything works perfectly fine in the IDE but when I switch to my battery or connect it to my pc without the serial monitor open it doesn’t work anymore.
I searched around and found it was most likely the serial connection auto-resetting. But even when i implemented the resistor as was said to do here: http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection
It still wouldn’t work!

Is this something in the code maybe? or something with the arduino itself?
BTW, using a mega AT2560 and followed those instructions.

GPS_logger.ino (5.97 KB)

If you disconnect your PC USB monitor connection, the standard serial is no longer available. Then you should have serial3 available, but it does not seem to be detected as available for some reason.

Could that be your problem area ?

That's probably it yeah, but aside from the resistor I have found no proper solution for it, which in my case didn't work

BTW : I only now noticed your using a Mega. (Yeah - where else would we have a Serial3 port, Anders) The Mega version have 3 serial ports, which are referred to as :

Serial1 Serial2 Serial3

If you use

Serial

You will only connect to the serial port via USB. This is available when connected.

The serial3 may not be available because the software initialisation has not been done. This could be caused by a defective cable, wrong comm port settings or coding errors.

best is to to try another cable or test the cable on another device. Then try look over the documentation for the GPS to ensure the port is set correctly. Finally look over your code to test if it is at all feasable what you try to do it, or you may have to use another method.

Whenever I use a different cable, the same problem occurs. It doesn't work until I either upload again or open the serial monitor. The COM port is set correctly. And the code should be just fine since I'm following a tutorial which uses the exact same code (except for the baudrate for Serial3) and I have a similar setup as the guy in the tutorial.

Everything works perfectly fine in the IDE but when I switch to my battery or connect it to my pc without the serial monitor open it doesn't work anymore.

What sort of 9V battery are you using ? Not what I know as a PP3 (small, rectangular, connections on the top) I hope as it cannot supply the required current for long.

When you are not using the Serial monitor how are you connecting the Arduino to the PC and what are you using to view the output ?

The Mega should have a power LED, like any other Arduino. Does it light up ?

If not, there is no power to the board, likely cause as explained by HeliBob.

I think I am using a PP3 but that should still be sufficient, even if it's not for long. When I connect the arduino otherwise is via the normal usb a to usb b cable as you would when you use the arduino IDE, and when I want to view what information I gathered I take out the sd-card and load it through an adapter.

The power led does light up

But, after some more testing I'm quite convinced it has got something to do with the serial port. When I power it through my battery I am getting information on the SD card, it's invalid because of the gps module not giving a fix but it does get info. So it's not auto resetting, but the Serial3 isn't functioning when there isnt a serial monitor.

Is there a fix in the code for this?

Try commenting out the serial monitor.

I have found, that in some code dependant cases, the serial locks the code, if it can not be read.

think I am using a PP3 but that should still be sufficient, even if it's not for long.

That depends on how much it has been used. What is the voltage across its terminals when it is powering the Arduino ?

Put some diagnostic code in setup() to flash the LED on pin 13 with a distinctive pattern so that you see when/if the Arduino is reset.

I'm not too sure on that,

but the arduino doesn't reset. I tested it with the LED and that still works. As I said, I think it has to do with the Serial3 port since even when it doesnt function correctly there is data sent to the sd-card

Eresis: I made a GPS system and want it to be able to work on a 9V battery. Everything works perfectly fine in the IDE but when I switch to my battery or connect it to my pc without the serial monitor open it doesn't work anymore.

9V blocks don't have much power. If your system works, then possibly not longer than one or two hours before the battery needs replacement.

If the battery powerd system does not work at all, the first thing I'd check would be the Arduino voltage.

Do you have a digital multimeter to measuere voltage? What's the voltage reading on the Arduino board between the GND and 5V pins while on battery power?

An SD card can most likely not be powered at all using a 9V block battery: The maximum current of SD cards during writing can easily be as high as 300 mA, and that might be something that your battery cannot provide while keeping the voltage at a stable regulated 5V. Not even for a few milliseconds during SD writes.

jurs: 9V blocks don't have much power. If your system works, then possibly not longer than one or two hours before the battery needs replacement.

If the battery powerd system does not work at all, the first thing I'd check would be the Arduino voltage.

Do you have a digital multimeter to measuere voltage? What's the voltage reading on the Arduino board between the GND and 5V pins while on battery power?

An SD card can most likely not be powered at all using a 9V block battery: The maximum current of SD cards during writing can easily be as high as 300 mA, and that might be something that your battery cannot provide while keeping the voltage at a stable regulated 5V. Not even for a few milliseconds during SD writes.

I don't have a multimeter, but as I said before, it does send info to the sd card, just not the info of the gps module. Same happens when I plug the arduino in my pc using the usb port but not turn on the arduino IDE with the serial monitor. It would seem that the Serial3 port is blocked. However, I don't know how to fix such an issue

I can't see anything in your code that would make a difference if it is or is not connected to a PC. Inadequate power seems the most likely problem.

Temporarily try another power source that is known to be better than a PP3 battery.

As someone else said, write some code to flash the on board LED as an inidicator that the program is running even when you can't see the output on the serial monitor.

Buy yourself a cheap digital multimeter.

...R

There is a LED already in the code which works when the gps module gets information, invalid or not. But that light doesn’t flicker

Eresis: But that light doesn't flicker

You cannot know whether it is failing to flicker because there is no data, or because the Arduino has crashed. Add some code to make another LED flash all the time. Then if it stops you will know the Arduino has stopped working properly.

...R