SD Card Data Tutorial. formating data
sir_hacksalot
Posts: 15
Hello again,
Im grinding my way through the tutorials. All has gone well until this little issue.
Docs:
Learn GCC tutorials / Simple Devices / SD Card Data:
Hardware:
Brand new Professional Development Board:
40004 Propeller memory Card.
SanDisc 1 GB SD
Issue:
The code provided in the Learn Library works as expected. After running in terminal I powered down, extracted the SD card, mounted it in my PC and Shazamm! There it is! The test.txt file shows up with perfect text data in NotePad.
Here is that code:
I felt like I was king of the world when this worked! The possibilities are endless!!! That being discovered, I decided to tackle the "Try this" challenge.
I wrote the code as shown in the tutorial. (I hope) and fired it off.
The "run in terminal" ran as expected. I thought I was a few comma separated values from DAQ bliss until I attempted to read the file on my pc. Horrible Sadness followed. My will to live slowly wept away as I stared at the gibberish in notepad.
So began the Hacking.! About 14 hours at it now. I have caused carpal tunnel finger while navigating the Winchester Mystery House of "Library Reference".
I have so little knowledge about C that, though my efforts were quite valiant, I have to admit defeat.
Please tell me why the first code writes beautiful TEXT to the SD card and the Second code Example writes garbage. Though the Terminal reads it just fine.
I even wrote the code for the next step. I hope its not to dorky. It works in terminal but isn't decipherable as viable data on the PC. Im using rc_time with a simple variable resistor Automotive Tempe Sending unit. on Pin 5
220 Ohm to Pin5
Cap 10uf series 220 Ohm and VSS
Sensor is parallel to the cap. I don't know if that made any sense. It works....5 Digit resolution but it Goes the wrong direction for Temp up / Temp down. Really hot is small numbers and Cold is really big numbers. Ill figure that out later. I just want to see data from the SD on my PC.
Thank you for your help on this. I am actually working on a real world product that needs a lot more than my BS2p can handle.
Im grinding my way through the tutorials. All has gone well until this little issue.
Docs:
Learn GCC tutorials / Simple Devices / SD Card Data:
Hardware:
Brand new Professional Development Board:
40004 Propeller memory Card.
SanDisc 1 GB SD
Issue:
The code provided in the Learn Library works as expected. After running in terminal I powered down, extracted the SD card, mounted it in my PC and Shazamm! There it is! The test.txt file shows up with perfect text data in NotePad.
Here is that code:
/* SD Minimal.side Create test.txt, write characters in, read back out, display. http://learn.parallax.com/propeller-c-simple-devices/sd-card-data */ #include "simpletools.h" // Include simpletools header int DO = 22, CLK = 23, DI = 24, CS = 25; // SD card pins on Propeller BOE int main(void) // main function { sd_mount(DO, CLK, DI, CS); // Mount SD card FILE* fp = fopen("test.txt", "w"); // Open a file for writing fwrite(" 'Stab self in neck..'\n", 1, 25, fp); // Add contents to the file fclose(fp); // Close the file char s[15]; // Buffer for characters fp = fopen("test.txt", "r"); // Reopen file for reading fread(s, 1, 25, fp); // Read 15 characters fclose(fp); // Close the file print("First 25 chars in test.txt that\n"); // Display heading print("appear just fine on my pc are:..\n\n"); print("%s", s); // Display characters print("\n"); // With a newline at the end }
I felt like I was king of the world when this worked! The possibilities are endless!!! That being discovered, I decided to tackle the "Try this" challenge.
I wrote the code as shown in the tutorial. (I hope) and fired it off.
/* This is exactly copied (i hope) from the SD Minimal.side GCC Learn tutorial http://learn.parallax.com/propeller-c-tutorials */ #include "simpletools.h" // Include simple tools int main(void) { int DO = 22, CLK = 23, DI = 24, CS = 25; sd_mount(DO, CLK, DI, CS); // Mount SD card FILE* fp = fopen("data.txt", "w"); int val = 500; fwrite(&val, sizeof(val), 1, fp); val = -10000; fwrite(&val, sizeof(val), 1,fp); // Add contents to the file fclose(fp); // Close the file fp = fopen("data.txt", "r"); // Reopen file for reading fread(&val,4,1,fp); print("val = %d\n",val); fread(&val,4,1,fp); print("val = %d\n",val); fclose(fp); }
The "run in terminal" ran as expected. I thought I was a few comma separated values from DAQ bliss until I attempted to read the file on my pc. Horrible Sadness followed. My will to live slowly wept away as I stared at the gibberish in notepad.
So began the Hacking.! About 14 hours at it now. I have caused carpal tunnel finger while navigating the Winchester Mystery House of "Library Reference".
I have so little knowledge about C that, though my efforts were quite valiant, I have to admit defeat.
Please tell me why the first code writes beautiful TEXT to the SD card and the Second code Example writes garbage. Though the Terminal reads it just fine.
I even wrote the code for the next step. I hope its not to dorky. It works in terminal but isn't decipherable as viable data on the PC. Im using rc_time with a simple variable resistor Automotive Tempe Sending unit. on Pin 5
220 Ohm to Pin5
Cap 10uf series 220 Ohm and VSS
Sensor is parallel to the cap. I don't know if that made any sense. It works....5 Digit resolution but it Goes the wrong direction for Temp up / Temp down. Really hot is small numbers and Cold is really big numbers. Ill figure that out later. I just want to see data from the SD on my PC.
/* Blank Simple Project.c http://learn.parallax.com/propeller-c-tutorials */ #include "simpletools.h" // Include simple tools void SDread(int q); int DO = 22, CLK = 23, DI = 24, CS = 25; int val,temp,fp; //-----------------[Main]------------------------------------------ int main() { SDread(24); void SDread(); print("function call success!! \n"); //ignor this. Just hacking my way around the tutorials pause(200); sd_mount(DO, CLK, DI, CS); int n = 0; while(n < 20) // Will this cause "sequential" writing to the SD Card? // I think its working but Im not sure about whats on // the SD Card.. { n = n + 1; FILE* fp = fopen("data2.txt", "w"); high(5); // Set P5 high pause(10); // Using QT or RC time with Varible Resistance sensor int dec,val = rc_time(5, 1); pause(15); fwrite(&val,sizeof(val),sizeof(int),fp); // Add contents to the file fclose(fp); pause(100); fp = fopen("data2.txt", "r"); fread(&val,sizeof(val),sizeof(int),fp); print("SD write : %d\n",val); } print("end\n"); } void SDread(int a) // Ignor this Function. More Hack learning. { print("Made it to the Function call!\n"); print("Variable is:...%d\n"); pause(400); }
Thank you for your help on this. I am actually working on a real world product that needs a lot more than my BS2p can handle.
Comments
Thanks for sharing
What I really want to do I store int data samples on the SD card using CSV for later analysis in Excel. I mean 10s of thousands of samples from multiple sensors that are all time coded to ach other. Probably and I2c array of sensors an clock. I am developing a product that will be shipped all over world and is to be in constant mobile deployment. I want to be able to provide technical assistance my customers. The only way I can begin to do that is to have the machine control software run a DAQ routine while the unit is operating. That way Im only a simple CSV file from knowing everything about the machine's performance, environmental and support system vectors and can thereby easily identify issues and provide solutions.
The equipment is being field tested now without the DAQ. Im working a BS2p really hard just running primary system operations as well as three independent third party subsystems that monitor conditions live.
Im really focused on this project. Your assistance with filling an SD card with INT data would be most helpful.
Thanks.
Parallax Forever!!