Go Down

Topic: Sketch only works when IDE monitor is active? (Read 689 times) previous topic - next topic

ninja2

I have a sketch that works fine when connected to IDE, but if I shut down the IDE (or even just the monitor window) it soon fails (LED stops blinking). If I hit reset without IDE monitor connected it doesn't startup and run properly (LED never blinks).

This program does report to monitor quite a bit, but my understanding was the serial comms simply goes to the "bit bucket" if monitor not connected.

What am I missing?

Grumpy_Mike

The TX and RX LEDs are controlled by the drivers in the PC not by the data lines on the arduino. Your sketch is still running.

ninja2

I know what you mean by the TX/RX leds, but when my sketch runs it executes the code I added to change the state of the LED on D13 every loop. So the LED blinking confirms sketch running.

But that LED doesn't flash, or soon stops, unless the serial monitor is connected/active, & even if I reset

my question remains, how / why ... ?

MikMo

I think posting your code and maybee a schematic of your project would make it a lot easier to help.

Grumpy_Mike

Yes post the sketch.
Quote
But that LED doesn't flash, or soon stops, unless the serial monitor is connected/active, & even if I reset

When the serial monitor is connected and disconnected it automatically resets the arduino, so is there something in the sketch that needs the serial port before you get to flash the LED?

Basically what you suggest does not happen so we need to find out where you are misunderstanding things.

ninja2

After some testing it's nothing to do with Serial monitor being connected. Disabling sections of code until the LED worked normally, the problem seems to be due to a conflict between the SD library and the D13 LED. When I comment the 3rd line out (SD.begin) from this section it works, when I reinstate that line only the LED doesn't work again: (bizarre!)  

     displayText(1);                                  // "Initializing SD card..."
     pinMode(SS_pin, OUTPUT);                // must be set as an output or the SD library won't work.
     if (!SD.begin(SS_pin)) {displayText(2); return;} // "[SD init FAILED]"
     displayText(3);                                  // "[SD OK]"
     MONITOR.println("");
     root = SD.open("/");
     printDirectory(root, 0);

(BTW displayText only prints text stored using PROGMEM)

I've attached a ZIP of the full sketch (6 tabs, compiles to approx. 26,000 bytes). I'm running this in a Freetronics USBdroid (a Uno compatible).

Meanwhile I'll try a stripped down program with just SD aspects and D13 LED to see if this still happens.

SurferTim

#6
Feb 04, 2012, 12:20 pm Last Edit: Feb 04, 2012, 02:46 pm by SurferTim Reason: 1
If that device is an Uno-type (not Mega), then that is normal. Pins 11-13 are used for the SPI interface. That is what the SD interface uses for communication.

edit: That should have been digital pins 10-13. Pin 10 is the default slave select, so you can't use it either.

ninja2

thanks SurferTim, that explains it.
I may have to dump the blinking LED, runnig out of pins!

Go Up