Pages: [1]   Go Down
Author Topic: Sketch only works when IDE monitor is active?  (Read 615 times)
0 Members and 1 Guest are viewing this topic.
Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33328
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ... ?
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33328
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

* CJ_SD_02.zip (6 KB - downloaded 1 times.)
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 138
Posts: 5851
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 04, 2012, 08:46:47 am by SurferTim » Logged

Adelaide, South Australia
Offline Offline
Full Member
***
Karma: 0
Posts: 143
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: