Show Posts
Pages: [1]
1  Using Arduino / Storage / Re: SD CARD Create File and then Read Directory Problem on: November 11, 2012, 05:25:56 pm
Thanks I'll give that a shot
2  Using Arduino / Storage / SD CARD Create File and then Read Directory Problem on: November 11, 2012, 04:35:00 pm
Hello All,

I have stumbled upon a problem that I can't get past and need you assistance. I have been reading everything I could search for and have not found a solution although I am fairly certain it is something trivial.

On setup I am creating a file on the SD card if it doesn't exist which is working fine. Later on I want to get a list of file in the main directory. The issue is that when I create a file in setup and then later try to get a list of the files the files will not list. However, if I comment out the portion in Setup that creates the file I can get a list of files without a problem.

I have modified the listfiles example below to illustrate my point. What am I doing wrong. It's almost like even though I am closing the SD open file it is still open.

#include <SD.h>

File root;
File dataFile;

void setup()
  // Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");
  dataFile ="TEST.CSV", O_CREAT | O_APPEND | O_WRITE | O_READ); //if I comment this out then the list files works
   Serial.println("Created File: TEST.CSV");


void loop()
  dataFile ="/");
  printDirectory(dataFile, 0);

void printDirectory(File dir, int numTabs) {
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
     for (uint8_t i=0; i<numTabs; i++) {
     if (entry.isDirectory()) {
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.println(entry.size(), DEC);

Any help would be very appreciated.

3  Using Arduino / Programming Questions / Re: "Filtering" Char Array on: June 10, 2012, 10:14:08 pm
Thanks I'll give that a shot. But can you use atoi() to convert a string to an integer?
4  Using Arduino / Programming Questions / "Filtering" Char Array on: June 10, 2012, 09:51:09 pm
Hello All,
I would assume that is has been covered several times before but I have been searching the forum and can't find what I'm looking for. I assume I'm just not searching for the right terminology. By the way I have been programming Arduino all of 2 weeks now so thank you for all your help thus far.

I have a command set that I am sending via UDP to the arduino from a program I created. Everything is working fin on that front. Now I am trying to split a character array into multiple char arrays based on a prefix. For example the command may be L500R500 . I can identify the prefix characters from the using the code below but then I get stuck. How do I get the next 3 characters after "L" and set them to a new array?

// packetSize is the size of the UDP char array and packetBuffer is the UDP char array

for(int x =0; x < packetSize +1; x ++){
 if(packetBuffer[x] == 'L') {

//get the next 3 characters and set them to Lspeed[4] char array

Lmotor = atoi(Lspeed); //convert to Lspeed array to integer for use in motor speed set command

Pages: [1]