PIN 13 Output HIGH

Hi ,

I'm trying to run a code which complies and uploads to the arduino, but the serial monitor (which should at least print the SD card being initialized) remains blank and the LED on Pin 13 turns on by itself. Is the program crashing ?

//using namespace std;
#include <SD.h>

#define SCALE_MAP 2
#define GRID_ROWS 96
#define GRID_COLS 50
//File myFile;
//
//char fileName[12] = "map.bmp";
#define SDchipSelect 10 //chip select for SD card --53 on mega, 10 on 328
#define WSchipSelect 4 //chip select for WS2801

// You can change this to use dynamic memory, if you like.
float gridMap[GRID_ROWS][GRID_COLS];

/*************************************************************************

  • Function inputMap converts the input map information into an *
  • initial occupancy grid, which is stored in gridMap. *
  • (Here, the "output" parameter says whether to print out the scaled *
  • map; output = 1 ==> yes, print; output = 0 ==> no, don't print.) *
    *************************************************************************/

void setup()
{
//randomSeed(analogRead(0));
// Serial.begin(9600);
Serial.begin(9600);
Serial.println();
Serial.println("Start");

Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
//pinMode(SDchipSelect, OUTPUT); //required for SPI to work
pinMode(WSchipSelect, OUTPUT); //required for WS2801 'spi' to work
if (!SD.begin(SDchipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
inputMap();

}

void loop() {}

//void inputMap(int output)
void inputMap()
{
int i, j, m, n;
char inputLine1[40], nextChar;
int width, height, maxVal;
#include <SD.h>
File myFile;
myFile = SD.open("map.bmp", FILE_READ);

/* Initialize map to 0's, meaning all free space */

for (m=0; m<GRID_ROWS; m++)
for (n=0; n<GRID_COLS; n++)
gridMap[m][n] = 0.0;

/* Read past first line /
//inFile.getline(inputLine1,80);
myFile.read(inputLine1,40);
/
Read in width, height, maxVal */
myFile >> width >> height >> maxVal;
Serial.print(width); //Width
Serial.print(height); //Height
Serial.print("\t"); //tab

/* Read in map; /
for (i=0; i<height; i++)
for (j=0; j<width; j++) {
myFile >> nextChar;
if (!nextChar)
gridMap[i/SCALE_MAP][j/SCALE_MAP] = 1.0;
}
Serial.print("Map input complete");
}
//
// if (output) {
// ofstream outFile("scaled_hospital_section.pnm");
// outFile << inputLine1 << endl;
// outFile << width/SCALE_MAP << " " << height/SCALE_MAP << endl
// << maxVal << endl;
//
// for (i=0; i<height/SCALE_MAP; i++)
// for (j=0; j<width/SCALE_MAP; j++) {
// if (gridMap
[j] == 1.0)*
// outFile << (char) 0;
// else
// outFile << (char) -1;
// }
// cout << "Scaled map output to file.\n";
// }
//}
//
//int main(int argc, char *argv[])
//{
// inputMap(1); // Here, '1' means to print out the scaled map to a file;
// // If you don't want the printout, pass a parameter of '0'.
//}
[/quote]

If you want it LOW then you need to set it so.

dannable:
If you want it LOW then you need to set it so.

I never did set it High it turns on by itself. But the bigger problem is the code doesn't seem to run since the serial monitor is blank.

The SD card uses SPI, which uses digital pins 11, 12, and 13 on most Arduinos. More specifically, pin 13 is used for the SPI Serial Clock so could well appear to be HIGH.

As to

#define GRID_ROWS 96 
#define GRID_COLS 50

float gridMap[GRID_ROWS][GRID_COLS];

That will take up 19,200 bytes of memory. Which Arduino board are you using ?

UKHeliBob:
The SD card uses SPI, which uses digital pins 11, 12, and 13 on most Arduinos. More specifically, pin 13 is used for the SPI Serial Clock so could well appear to be HIGH.

As to

#define GRID_ROWS 96 

#define GRID_COLS 50

float gridMap[GRID_ROWS][GRID_COLS];



That will take up 19,200 bytes of memory. Which Arduino board are you using ?

I did suspect the size to be a problem and also had set the Grid 20 by 20 but the problem still persists.
Right now am testing the code on a UNO

20 * 20 * 4 still uses 1600 bytes of RAM and the Uno only has 2000 bytes of SRAM so that size is still likely to be a problem.

UKHeliBob:
20 * 20 * 4 still uses 1600 bytes of RAM and the Uno only has 2000 bytes of SRAM so that size is still likely to be a problem.

You're right. I did a 5*5 grid and it worked. Looks like I'm going to have to use a Mega.

Thanks