Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« on: November 25, 2012, 07:04:35 am » |
I'm working with the Card info sketch in the sd examples, and my 16gb sd card reports as 3gb. It's my understanding that this is a result of Serial.print only understanding uint32_t. I've tried editing print.h to understand long long int, but it's not taking. What am I not understanding? size_t print(const __FlashStringHelper *); size_t print(const String &); size_t print(const char[]); size_t print(char); size_t print(unsigned char, int = DEC); size_t print(int, int = DEC); size_t print(unsigned int, int = DEC); size_t print(long, int = DEC); //size_t print(long long, int = DEC); size_t print(unsigned long, int = DEC); //size_t print(unsigned long long, int = DEC); size_t print(double, int = 2); size_t print(const Printable&);
size_t println(const __FlashStringHelper *); size_t println(const String &s); size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); size_t println(int, int = DEC); size_t println(unsigned int, int = DEC); size_t println(long, int = DEC); //size_t println(long long, int = DEC); size_t println(unsigned long, int = DEC); //size_t println(unsigned long long, int = DEC); size_t println(double, int = 2); size_t println(const Printable&); size_t println(void);
|
|
|
|
« Last Edit: November 25, 2012, 01:36:16 pm by Steve Spence - KK4HFJ »
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #1 on: November 25, 2012, 07:23:33 am » |
add this to print.cpp and the signatures to print.h - be aware long long is slow slow  void Print::println(long long n, int base) { print(n, base); println(); }
void Print::print(long long n, int base) { if (n < 0) write('-'); if (base == 0) write(n); else printLLNumber(n, base); }
void Print::println(unsigned long long n, int base) { print(n, base); println(); }
void Print::print(unsigned long long n, int base) { if (base == 0) write(n); else printLLNumber(n, base); }
void Print::printLLNumber(unsigned long long n, uint8_t base) { unsigned char buf[16 * sizeof(long)]; // Assumes 8-bit chars. unsigned long long i = 0;
if (n == 0) { print('0'); return; }
while (n > 0) { buf[i++] = n % base; n /= base; }
for (; i > 0; i--) print((char) (buf[i - 1] < 10 ? '0' + buf[i - 1] : 'A' + buf[i - 1] - 10)); }
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #2 on: November 25, 2012, 08:46:04 am » |
I get C:\Users\Steve\Programs\arduino-1.0.2\hardware\arduino\cores\arduino\nPrint.cpp:230: error: prototype for 'size_t Print::printNumber(long long unsigned int, uint8_t)' does not match any in class 'Print' C:\Users\Steve\Programs\arduino-1.0.2\hardware\arduino\cores\arduino\/Print.h:38: error: candidate is: size_t Print::printNumber(long unsigned int, uint8_t) When I run /* SD card test This example shows how use the utility libraries on which the' SD library is based in order to get info about your SD card. Very useful for testing a card when you're not sure whether its working or not. The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila ** CS - depends on your SD card shield or module. Pin 4 used here for consistency with other Arduino examples
created 28 Mar 2011 by Limor Fried modified 9 Apr 2012 by Tom Igoe */ // include the SD library: #include <SD.h>
// set up variables using the SD utility library functions: Sd2Card card; SdVolume volume; SdFile root;
// change this to match your SD shield or module; // Arduino Ethernet shield: pin 4 // Adafruit SD shields and modules: pin 10 // Sparkfun SD shield: pin 8 const int chipSelect = 4;
void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }
Serial.print("\nInitializing 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); // change this to 53 on a mega
// we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card is inserted?"); Serial.println("* Is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { Serial.println("Wiring is correct and a card is present."); }
// print the type of card Serial.print("\nCard type: "); switch(card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break; default: Serial.println("Unknown"); }
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; }
// print the type and size of the first FAT-type volume uint64_t volumesize; Serial.print("\nVolume type is FAT"); Serial.println(volume.fatType(), DEC); Serial.println(); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters // volumesize *= 512; // SD card blocks are always 512 bytes // Serial.print("Volume size (bytes): "); // Serial.println(volumesize); Serial.print("Volume size (Kbytes): "); // volumesize /= 1024; volumesize /= 2; Serial.println(volumesize); Serial.print("Volume size (Mbytes): "); volumesize /= 1024; Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); }
void loop(void) { }
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Offline
Edison Member
Karma: 16
Posts: 1036
Arduino rocks
|
 |
« Reply #3 on: November 25, 2012, 10:57:18 am » |
and the signatures to print.h
Did you do that?
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #4 on: November 25, 2012, 11:47:37 am » |
I attached print.h
Does it look correct?
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #5 on: November 25, 2012, 12:19:59 pm » |
I'll will try the code myself, be back asap [update] unexpected conflicts - pity ...
|
|
|
|
« Last Edit: November 25, 2012, 01:09:15 pm by robtillaart »
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #6 on: November 25, 2012, 01:24:51 pm » |
a workaround: print it in 2 steps void setup() { Serial.begin(9600); Serial.println("start..."); uint64_t ll = 123456789012345678ULL; uint64_t xx = ll/1000000000ULL;
if (xx >0) Serial.print((long)xx); Serial.print((long)(ll-xx*1000000000)); }
void loop(){}
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #7 on: November 25, 2012, 01:35:33 pm » |
ok. I get
start... 12345678912345678
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #8 on: November 25, 2012, 02:06:30 pm » |
does this 'trick' solve your problem enough? An "integrated solution" is more difficult than I expected. I also had a quick look at - http://www.nongnu.org/avr-libc/user-manual/modules.html - but found no solutions there either.
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #9 on: November 25, 2012, 02:19:13 pm » |
Not sure how to merge that into the sd cardinfo sketch .....
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #10 on: November 25, 2012, 03:50:04 pm » |
// Serial.print("Volume size (bytes): "); // Serial.println(volumesize);
becomes Serial.print("Volume size (bytes): "); uint64_t xx = volumesize/1000000000ULL;
if (xx >0) Serial.print((long)xx); Serial.print((long)(volumesize - xx*1000000000));
give it a try
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #11 on: November 25, 2012, 05:24:40 pm » |
I get:
Initializing SD card...Wiring is correct and a card is present.
Card type: SDHC
Volume type is FAT32
Volume size (bytes): 31099904 Files found on the card (name, date and size in bytes): DCIM/ 2011-06-20 14:58:52 100_PANA/ 2011-06-20 19:07:48 P1000812.JPG 2011-09-08 09:19:54 4158647 P1000781.JPG 2011-08-20 21:02:02 4309863 P1000813.JPG 2011-09-08 09:20:00 4258311
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #12 on: November 26, 2012, 02:51:26 pm » |
Is this what you expected? if not what did you expect?
|
|
|
|
|
Logged
|
|
|
|
|
Andrews SC
Offline
Full Member
Karma: 0
Posts: 184
If Arduino is not the answer, you are asking the wrong question!
|
 |
« Reply #13 on: November 26, 2012, 07:31:21 pm » |
I was expecting somewhere around 16,000,000,000 bytes .....
|
|
|
|
|
Logged
|
Steve Spence - ET/AT/R&D KK4HFJ
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 101
Posts: 9553
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #14 on: November 27, 2012, 02:08:38 pm » |
can you post your complete code again?
|
|
|
|
|
Logged
|
|
|
|
|
|