Show Posts
Pages: [1] 2 3 ... 6
1  Using Arduino / Storage / Re: SD card variable file name on: September 30, 2011, 10:13:29 am
GTech13,

here is a snippet that might help:
Code:
      char file_name[] = "xxxxxxxx.CSV";    // prototype file name
      char extension[] = "CSV";  // sometimes the extension gets modified

      sprintf(file_name,"%c%c%cCALIB.%s",EEPROM.read(fpf0),EEPROM.read(fpf1),
      EEPROM.read(fpf2),extension);

      /*  open the CAL file on the SD.  New file each time
       The serial number, customer number, file number are on the processor EEPROM
       */

      if (file.open(&root, file_name, O_CREAT | O_APPEND | O_WRITE))
      {
        PgmPrintln("calibration file opened");
        Serial.println(file_name);
      }

 Use your date strings instead of the EE reads in sprintf().  I increment the EE bytes and save them again so each file name is a sequential number.  Should work with date strings.  Are you setting the file creation dates and the file modification dates? They are useful and facilitate sorting file names when looking at the directory.

JC
2  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 28, 2011, 04:35:34 pm
fat16lib

Well, that is straightforward, and it works perfectly.

I tried a lot of combinations, but I think I was stuck on Root, not root.

Thanks

Until the last version of SdFat I used either the Arduino published version of the interface or the MC version with perfect results while programming either UNOs or Duemilanoves.  Since the last version of SdFat the MC version has been unusable, this is typical output:


Code:
C \__arduino-0022MCa\hardware\tools\avr\bin\avr-g++    -c  -g  -Os  -w  -fno-exceptions  -ffunction-sections  -fdata-sections  -mmcu=atmega328p  -DF_CPU=16000000L  -DARDUINO=22  -DARDUINO=     -IC \___a_projects\Pump Controller\A9   -IC \__arduino-0022MCa\hardware\arduino\cores\arduino   -IC \___a_projects\libraries\SdFat   -IC \__arduino-0022MCa\.\libraries\Wire   -IC \___a_projects\libraries\RTClib   -IC \__arduino-0022MCa\.\libraries\EEPROM    c \___a_output\A9.cpp  -o  c \___a_output\A9.cpp.o
In file included from C:\___a_projects\libraries\SdFat/SdFile.h:24,
                 from C:\___a_projects\libraries\SdFat/SdFat.h:26,
                 from A9.cpp:30:
C:\___a_projects\libraries\SdFat/SdBaseFile.h:27:13: error: operator '<' has no left operand
C:\___a_projects\libraries\SdFat/SdBaseFile.h:30:21: error: Arduino.h: No such file or directory
In file included from A9.cpp:31:
C:\___a_projects\libraries\SdFat/SdFatUtil.h:27:13: error: operator '<' has no left operand
In file included from C:\___a_projects\libraries\SdFat/SdFile.h:24,
                 from C:\___a_projects\libraries\SdFat/SdFat.h:26,
                 from A9.cpp:30:
C:\___a_projects\libraries\SdFat/SdBaseFile.h:271: error: 'Print' has not been declared
C:\___a_projects\libraries\SdFat/SdBaseFile.h:285: error: 'Print' has not been declared
C:\___a_projects\libraries\SdFat/SdBaseFile.h:287: error: 'Print' has not been declared
C:\___a_projects\libraries\SdFat/SdBaseFile.h:360: error: 'Print' has not been declared
C:\___a_projects\libraries\SdFat/SdBaseFile.h:370: error: 'Print' has not been declared
In file included from C:\___a_projects\libraries\SdFat/SdFat.h:26,
                 from A9.cpp:30:
C:\___a_projects\libraries\SdFat/SdFile.h:32: error: expected class-name before '{' token
In file included from C:\___a_projects\libraries\SdFat/ArduinoStream.h:26,
                 from C:\___a_projects\libraries\SdFat/SdFat.h:28,
                 from A9.cpp:30:
C:\___a_projects\libraries\SdFat/bufstream.h: In member function 'void ibufstream::init(const char*)':
C:\___a_projects\libraries\SdFat/bufstream.h:49: error: 'strlen' was not declared in this scope
In file included from C:\___a_projects\libraries\SdFat/SdFat.h:28,
                 from A9.cpp:30:
C:\___a_projects\libraries\SdFat/ArduinoStream.h: At global scope:
C:\___a_projects\libraries\SdFat/ArduinoStream.h:40: error: expected `)' before '&' token
C:\___a_projects\libraries\SdFat/ArduinoStream.h:82: error: ISO C++ forbids declaration of 'Stream' with no type
C:\___a_projects\libraries\SdFat/ArduinoStream.h:82: error: expected ';' before '*' token
C:\___a_projects\libraries\SdFat/ArduinoStream.h: In member function 'void ArduinoInStream::readline()':
C:\___a_projects\libraries\SdFat/ArduinoStream.h:50: error: 'hw_' was not declared in this scope
C:\___a_projects\libraries\SdFat/ArduinoStream.h:53: error: 'millis' was not declared in this scope
C:\___a_projects\libraries\SdFat/ArduinoStream.h:54: error: 'hw_' was not declared in this scope
C:\___a_projects\libraries\SdFat/ArduinoStream.h:61: error: 'hw_' was not declared in this scope
C:\___a_projects\libraries\SdFat/ArduinoStream.h: At global scope:
C:\___a_projects\libraries\SdFat/ArduinoStream.h:95: error: expected `)' before '&' token
C:\___a_projects\libraries\SdFat/ArduinoStream.h:113: error: ISO C++ forbids declaration of 'Print' with no type
C:\___a_projects\libraries\SdFat/ArduinoStream.h:113: error: expected ';' before '*' token
C:\___a_projects\libraries\SdFat/ArduinoStream.h: In member function 'virtual void ArduinoOutStream::putch(char)':
C:\___a_projects\libraries\SdFat/ArduinoStream.h:103: error: 'pr_' was not declared in this scope
C:\___a_projects\libraries\SdFat/ArduinoStream.h:104: error: 'pr_' was not declared in this scope
In file included from A9.cpp:30:
C:\___a_projects\libraries\SdFat/SdFat.h: At global scope:
C:\___a_projects\libraries\SdFat/SdFat.h:61: error: 'Print' has not been declared
In file included from A9.cpp:31:
C:\___a_projects\libraries\SdFat/SdFatUtil.h:39: error: variable or field 'print_P' declared void
C:\___a_projects\libraries\SdFat/SdFatUtil.h:39: error: 'Print' was not declared in this scope
C:\___a_projects\libraries\SdFat/SdFatUtil.h:39: error: 'pr' was not declared in this scope
C:\___a_projects\libraries\SdFat/SdFatUtil.h:39: error: expected primary-expression before 'const'
C:\___a_projects\libraries\SdFat/SdFatUtil.h:40: error: variable or field 'println_P' declared void
C:\___a_projects\libraries\SdFat/SdFatUtil.h:40: error: 'Print' was not declared in this scope
C:\___a_projects\libraries\SdFat/SdFatUtil.h:40: error: 'pr' was not declared in this scope
C:\___a_projects\libraries\SdFat/SdFatUtil.h:40: error: expected primary-expression before 'const'
A9.cpp: In function 'void loop()':
A9:148: error: 'class SdFile' has no member named 'print'
A9.cpp: In function 'void file_head_stamp()':
file_functions:91: error: 'class SdFile' has no member named 'println'
A9.cpp: In function 'void file_setup_stamp()':
file_functions:100: error: 'class SdFile' has no member named 'print'
file_functions:104: error: 'class SdFile' has no member named 'print'
file_functions:107: error: 'class SdFile' has no member named 'print'
file_functions:110: error: 'class SdFile' has no member named 'println'
file_functions:113: error: 'class SdFile' has no member named 'print'
file_functions:118: error: 'class SdFile' has no member named 'println'
file_functions:123: error: 'class SdFile' has no member named 'println'

 cannot find a general discussion of the problem.  Is it just my installation or is this a problem for others?


Thanks for the help. The cards can now be pulled and inserted at any time.

John C
3  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 27, 2011, 07:49:50 pm
fat16lib

how does one close Root?

JC
4  Community / Website and Forum / Re: how to insert a code panel into a forum posting on: September 27, 2011, 06:13:22 pm
Thanks,

It should be simple but I did it wrong the first try.  If I survive the criticism I will do it properly next time

JC
5  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 27, 2011, 06:10:16 pm
fat16lib

I kludged up a test to try re-initializing the board.  The functions in the code initialize the card nicely with a fresh reset but the code emits

Quote
Program Starting
card initialized
volume initialized
error: openRoot failed
Root directory opened

During the second attempt after reinserting the card. Clearly "Root directory opened " is an artifact of my sloth, the error handling routine has been short circuited to keep going with out logging,  Start_up_SD() and fopen() are the same code called at startup.

Interestingly, if the card is not in place for the boot up, the controller notes this and continues with the controlling functions.  If the card is inserted after the initial bootup failure to initialize, it will connect just fine.  Not the next time though.  I think we are close

Quote
void Start_up_SD()
{
  file.close(); // just in case it is a re-open
  file.writeError = false;
  PgmPrintln("Program Starting");// not really
  if (!card.init(SPI_FULL_SPEED)) error("card.init failed");
  PgmPrint("card initialized \n");
  if (!volume.init(&card)) error("volume.init failed");
  PgmPrint("volume initialized \n");
  if (!root.openRoot(&volume)) error("openRoot failed");
  PgmPrint("Root directory opened \n");// maybe not
  card_yanked = false;
  return;
}

boolean fopen()
{
  if (file.open(&root, file_name, O_CREAT | O_APPEND | O_WRITE))
  {
    PgmPrintln("data file opened");
    Serial.println(file_name);
    return true;
  }
  else return false;
}


Thanks again for the thoughtful consideration of my problem

JC
6  Community / Website and Forum / how to insert a code panel into a forum posting on: September 27, 2011, 09:42:53 am
Where ar the instructions for inserting a quote or code panel in to a forum posting?
7  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 26, 2011, 02:33:14 pm
fat16lib

If we loose a little data it makes no difference.  The trends and shape of the curves after the data is subject to some noise removal is the real information.  The cards have been pulled hundreds or thousands of times in use and during development.

I thought that the detecting-card-absent problem was a new problem for which we once had a solution.

After digging through old code for a different controller I found:

if (file.writeError) error("write fail");

pulling the card results in:

error: write fail
SD error: F,0

echoed to the serial monitor

Is this something of yours or some one else's that I shamelessly plagiarized?

Assuming the missing card is noted, how does one get rid of program links and knowledge of the original SD and files so a replaced SD can be tested for and utilized?  It seems like there is opportunity for a lot of memory consumption if it is not released.

Thanks

JC





8  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 25, 2011, 01:40:54 pm
fat16lib

I wish I had your knowledge and abilities.  I am grateful that you share.  I cannot tell an oil well pumper that he must close all the files before changing cards and expect that it will have any effect on the way he does his work.  I am just pleased that they sometimes bring me a card with data on it.  They dislike resetting the controller because it shuts the pump down and The controller goes through the whole range of experiments to determine the correct pumping rate again.  It is disruptive.  Some of the parameters are stored in EEPROM but they change often and the controller must do little experiments all the time to keep operation optimized.  It is best to not start over.  The power company does that for us often enough.

What can be damaged by just pulling the card?  We have done it hundreds of times and to the best of my knowledge nothing irreversible has occured.

What is the proper way to shut down a card?  Just close()?  What are the challenges to opening a file after the card that was pulled out is replaced?

Thanks

jc
9  Using Arduino / Storage / Re: Good way to detect that a SD card has been removed on: September 24, 2011, 07:55:23 pm
All the pins have been consumed or are planned for other functions.  It would be really nice to have a software fix. 

I just discovered a new release of SdFat and will explore it this evening to see if there are new options.

Hurray for rename!
10  Using Arduino / Storage / Good way to detect that a SD card has been removed on: September 24, 2011, 07:29:40 pm
I generally get along pretty well with SDFat.  An Arduino based controller needs to know that the SD card that it has been writing to has been removed so that it can then attempt to reconnect when one is replaced.

The cards need to be changed out occasionally to harvest the data.  No problem of course, if the controller is re-set, but unnecessary starts and stops of the pump it controls are to be avoided.

It seems like the return value of sync() would work but in my tests it always returns a 1, card in or card out.  Perhaps from sync()'s point of reference, the buffer of characters went somewhere.  Write puts it in the buffer and does not seem like a reliable source of information either.

Any thoughts for detecting the failed writes that do not involve a bunch of unnecessary writing and reading?

Thanks in advance
11  Using Arduino / Programming Questions / Re: Read a pin as a boolean value on: September 12, 2011, 03:06:40 pm
I tried both.  The results seem to be the same.  The underlying problem proved to be a misplaced  } that caused some code to be included in an   else .
Thanks again
12  Using Arduino / Programming Questions / Re: Read a pin as a boolean value on: September 12, 2011, 12:30:06 pm
Thanks, the byte variable sounds like a good solution.  I think it was salvation once before when things seemed to become flaky, but I cannot find the code
13  Using Arduino / Programming Questions / Read a pin as a boolean value on: September 12, 2011, 12:00:02 pm
It seems like this has worked before but now I am uncertain about the current results:

boolean variable = digitalRead(pin);

as in:

 IsWater = digitalRead(ReadFloatPin);

Thanks
14  Using Arduino / Project Guidance / Re: communicartion with a digital scale on: August 16, 2011, 03:04:55 pm
mjbmikeb thanks for the sanity check.

You are correct, there must be some common denominator.  Guess I will just buy a pretty one and live with it.  I will know a lot more in a week or so.

Nothing inspired is necessary, just slave labor to create the command strings and to dig the needed values out of the ascii response strings,  make it work and keep the execution from overwhelming really tight ram.  The needs are pretty minimal, so really specific code will probably come from this, not a general solution.  Thanks again

jac
15  Using Arduino / Project Guidance / communicartion with a digital scale on: August 15, 2011, 06:24:42 pm
I need to serial communicate with a digital weighing scale or balance, RS232 or USB.  The two manuals I have read describe communication exchanges with ascii  strings that are kind of the same but enough different to be a pain. 

No doubt I can make it work but I hate to work toward a dead end with regard to the application or extension of the code I develop.  Does any one have some practical advice about the way scales communicate and which ones to seek out or avoid?  Does anyone have some existing code to share?  I would be pleased to contribute to something that already exists rather than reinvent a wheel.
Pages: [1] 2 3 ... 6