Show Posts
Pages: 1 ... 68 69 [70] 71 72 ... 109
1036  Using Arduino / Storage / Re: SdFat update on: July 21, 2012, 09:13:11 am
SdFat has a function, rmRfStar(), that will clean an SD.  Here is the documentation:
bool SdBaseFile::rmRfStar()    

Recursively delete a directory and all contained files.

This is like the Unix/Linux 'rm -rf *' if called with the root directory hence the name.

Warning - This will remove all contents of the directory including subdirectories. The directory will then be removed if it is not root. The read-only attribute for files will be ignored.

    This function should not be used to delete the 8.3 version of a directory that has a long name.

    The value one, true, is returned for success and the value zero, false, is returned for failure.

Here is an example sketch that will delete all except the root directory:
#include <SdFat.h>
SdFat sd;

void setup() {
  Serial.println("Type any character to delete all files");
  while ( <= 0) {}
  if (!sd.begin()) sd.initErrorHalt();
  // list all files;
  // sd.vwd() is root, working directory for volume
  // remove all files and directories in root
  Serial.println("---------- rmRfStar()");;
void loop() {}
Here is output from the sketch using an SD with two directories and a file.
Type any character to delete all files
---------- rmRfStar()

1037  Using Arduino / Storage / Re: SdFat.h incompatible with SD.h? on: July 20, 2012, 09:26:01 am
If you mean file.available(), SdFat does not provide available() since this function does not always provide the correct result in SD.h. The problem is available() is declared as an int in the Stream class.  Type int is limited to 32767 bytes but files can be much larger, up to 4294967295 bytes.

You can use the following expression in SdFat:
 uint32_t bytesLeft;
  bytesLeft = file.fileSize() - file.curPosition();

Too get the correct result with SD.h use this expression instead of available():
 uint32_t bytesLeft;
  bytesLeft = file.size() - file.position();

1038  Using Arduino / Storage / Re: SD card file write is skipping data on: July 20, 2012, 09:12:14 am
SD.begin() initializes the SD card, mounts the FAT volume, and clears any unwritten data in internal buffers.

Calling it in loop discards a lot of data and may cause file system corruption.  SD.h was not designed to call SD.begin() multiple times.  SD.h is a wrapper for an old version of SdFat.  The wrapper has bugs that prevent multiple calls from always working.

SdFat allows multiple calls to begin/init if all files are closed first.  This allows one SD card to be removed and another SD card to be inserted.
1039  Using Arduino / Storage / SdFat update on: July 19, 2012, 04:23:35 pm
A new version of SdFat,, is available here

This version requires Arduino version 1.0 or greater since implementing and testing new features in older versions is time consuming and messy.

Here are some of the additions/changes:
Added support for SDXC cards formatted as FAT32.  Modified the SdFormatter
example to format SDXC cards as FAT32.  This is not the SDXC standard which
is exFAT.

Added Arduino style SdFat::begin(chipSelect, spiSpeed);

Added options for SD crc checking.  Enabling crc checking increases reliability
at the cost of speed.  Edit SdFatConfig.h to select CRC options.

Added << operator for Arduino flash string macro F().

New RawWrite example for fast write of contiguous files.

New faster software SPI

Software SPI for Leonardo boards

Changes to allow use of the SerialPort library.

Error messages and output from programs are now sent to a stdOut Print

The default stdOut is a small non-interrupt driven class that outputs messages
to serial port zero.  This allows an alternate Serial library like SerialPort
to be used with SdFat.

You can redirect stdOut with SdFat::setStdOut(Print* stream) and
get the current stdOut stream with SdFat::stdOut().

Change file type for all examples to *.ino.

Removed __cxa_pure_virtual to avoid conflicts with other libraries.
1040  Using Arduino / Storage / Re: Need help connecting CH375B USB module to Arduino Mega 2560 on: July 19, 2012, 06:45:11 am
You can't connect the module until you know what hardware configuration the software expects. 
1041  Using Arduino / Storage / Re: Need help connecting CH375B USB module to Arduino Mega 2560 on: July 18, 2012, 01:34:06 pm
This is not an easy device to write software for.  Is there any software available for the Arduino?   How do you plan to use it?

The connection will depend on what is required by the software.

This module need to have it's data pins D0-D7 connected to a 8-bit port.  pins on Port A or C on the Mega might work.

INT, CS, A0, RD, and WR need to be connected to other pins.

1042  Using Arduino / Programming Questions / Re: Adding leading zeros to HEX on: July 16, 2012, 08:19:57 pm
I second TCWORLD's opinion that sprintf is almost always a better solution to formatting than the String class.  I like snprintf a little better since it is safer but in this case you will never overflow the character array.

In addition to being simpler the sprintf solution takes less memory.  This sketch takes 4070 bytes and has no zero fill.
uint8_t mac[] = {110, 5, 30, 0, 50, 12};
void setup() {
  String dataString = "";
  dataString += String(mac[0], HEX);
  dataString += ":";
  dataString += String(mac[1], HEX);
  dataString += ":";
  dataString += String(mac[2], HEX);
  dataString += ":";
  dataString += String(mac[3], HEX);
  dataString += ":";
  dataString += String(mac[4], HEX);
  dataString += ":";
  dataString += String(mac[5], HEX);
void loop() {
This sketch takes 3528 bytes and is very simple.
uint8_t mac[] = {110, 5, 30, 0, 50, 12};
void setup() {
  char dataString[50] = {0};
  sprintf(dataString, "%02X:%02X:%02X:%02X:%02X:%02X",mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
void loop() {
If memory is a problem you can do something like this which takes 2220 bytes but is not a general solution.
uint8_t mac[] = {110, 5, 30, 0, 50, 12};
void setup() {
  for (uint8_t i = 0; i < 6; i++) {
    if (i) Serial.write(':');
    if (mac[i] < 16) Serial.write('0');
    Serial.print(mac[i], HEX);
void loop() {
1043  Using Arduino / Storage / Re: Windows Errors on opening SD card file on: July 16, 2012, 03:08:01 pm
Wow!  Looks like you are hitting every pothole.  The SYLK trap is a good one.
1044  Using Arduino / Storage / Re: Windows Errors on opening SD card file on: July 16, 2012, 01:20:28 pm
If you remove the SD without closing the file you will most likely have a corrupt file.  Closing the file updates the directory entry for the file and insures the SD file structures are consistent.

If you check the SD for errors with the windows, the volume will probably have problems.

In Windows right click on the SD and select properties then click on the tools tab then click "Check now..."  under Error-checking.

If closing the file before removing the SD doesn't fix the problem post the exact Windows message and describe the app that was used to open the file
1045  Using Arduino / Storage / Re: Logging 100 ksps with the Arduino internal ADC on: July 16, 2012, 12:46:35 pm
I did some tests but mostly looked at other people's work.

This is a good article on the AVR ADC and agrees with other tests

Here are the results of the SNR tests expressed as ENOB.

ENOB = (SNR – 1.76dB)/6.02dB

At 100 ksps I must clock the ADC at 2 MHz so the above test says I get an ENOB of a little under 7.5.  Not too bad since I am recording 8-bit data.

At rates lower than about 70 ksps I can use 1 MHz for the ADC clock for better SNR/ENOB.

The ATmega datasheet makes it sound like an ADC clock above 200 kHz will kill accuracy but all test I find give results like the above for the 328p.

1046  Using Arduino / Storage / Re: SD Card Initialization Fail 70% Of the time..... on: July 16, 2012, 12:00:03 pm
You could have used almost any pin for chip select and got the same result.

When a pin is uninitialized it may float low.  To enable a SPI device you pull chip select low.  So your uninitialized pin 4 was mostly enabling the SD.

You are not the first have this happen and you won't be the last.
1047  Using Arduino / Storage / Re: SD Card Initialization Fail 70% Of the time..... on: July 16, 2012, 11:34:12 am
The wireless shield uses pin 4 for SD chip select if you are using this shield

See the SDCS at pin 4 on the shield.

Edit SdFormatter  to use pin 4 as above and try it.

You must use pin 4 as SD chip select in all sketches.

The shield works some times because pin 4 is not initialize and floats low.  The shield will fail if pin 4 floats high.
1048  Using Arduino / Storage / Re: SD Card Initialization Fail 70% Of the time..... on: July 16, 2012, 11:11:36 am
It appears that your shield uses pin 4 as SD chip select.

Are you always using pin 4 as SD chip select in begin() and init() calls?

Some SD modules/shields almost work when the wrong chip select pin is used since pin 4 may float low most of the time.

Your errors are occurring at random times, not just at initialization time.  This indicates use of the wrong CS pin, noise or bad SPI bus signals or a second SPI device interfering with the SD.

It does not appear that you have any other SPI devices.

Do you have anything connected to the SPI pins 10, 11, 12, 13?

Did you edit SdFormatter and define chipselect like this?
const uint8_t chipSelect = 4;
1049  Using Arduino / Storage / Re: SD Card Initialization Fail 70% Of the time..... on: July 15, 2012, 09:10:54 pm
You need to run the QuickStart or SdInfo examples in the SdFat/examples folder.  The Arduino group didn't include these examples so you need to download SdFat here

QuickStart's output looks like this with the errorCode at the end:
SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Is there a wiring/soldering problem?
errorCode: 0x2, errorData: 0xff

SdInfo's output looks like this:
card.init failed
SD errorCode: 0X2
SD errorData: 0X20

1050  Using Arduino / Storage / Re: DfFat for dataflash and others on: July 15, 2012, 02:48:18 pm

You need to read the datasheet.  Many people have been tricked by the "ping-pong" thing.

Here are some times (typical and max)
Page erase and programming time (512-/528-bytes) 17 40 ms
Page programming time (512/528 bytes) 3 6 ms
Page erase time (512/528 bytes) 15 35 ms
Block erase time (4,096/4,224 bytes) 45 100 ms
Sector erase time (131,072/135,168 bytes) 1.6 5 s

So you can ping-pong write a block at typical 17 ms for a block or about 30 KB/sec.  Programing time is horrible.  3 ms typical 6 ms max.

If you are streaming to the part you face this:
The erase and the programming of the page are internally self-timed, and should take place in a maximum time of tEP. During this time, the status register and the RDY/BUSY pin will indicate that the part is busy.

So the ping-pong thing does little good.  Or as some people say Dataflash is slow as molasses.

Most MTD flash memory devices have a real downside when used for file systems.  That's why all popular flash devices for file systems, like SD cards and SSDs, have a block erase/wear controller.

I have not pursued F-RAM since the parts are low density so a file system makes less sense.  Dataflash at 32 Mbit is about the minimum density suitable for a file system.

Pages: 1 ... 68 69 [70] 71 72 ... 109