Shop OBEX P1 Docs P2 Docs Learn Events
Can files written by the SD card object be read directly to a PC? — Parallax Forums

Can files written by the SD card object be read directly to a PC?

ElectricAyeElectricAye Posts: 4,561
edited 2008-10-17 05:19 in Propeller 1
Hi all,
just another pestering about SD cards: can anybody please tell me if the files written by the SD card object(s) in the Object Exchange can be read directly by a PC? Ideally I want to be able to unplug my SD card from my data acquisition unit, plug it into my computer and transfer the files into an Excel spreadsheet. Am I dreaming or is this a possibility without building all sorts of interface circuits, performing rain dances, etc.?

thank you,
Mark

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-08-27 17:21
    If you use the included fat16 file system, then yes it can be read by a PC. I frequently use a SD card reader to load files onto the SD card, because it's easier. It works the other way too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-27 17:23
    Yes

    Files written by the SD card object can be read directly by a PC. There's a caveat here though. A file is just a sequence of bytes. The content of the file and its format may be crucial to the PC program trying to read it. Text files are the common denominator. Most PC programs can read some kind of text file. Excel, for example, can read CSV or Comma Separated Values files. It can also read tab separated values files. Google "wiki CSV" for a description of this. Propeller code can easily produce this.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-08-27 17:32
    Okay,
    Let's see if I understand this right:
    Paul is saying that a PC can understand FAT16. And FAT16 is what the SD card object will provide for you.
    But Excel needs, let's say, CSV. But to get CSV files you have to rewrite the SD card object code so it writes the data from the Prop to the SD card in a CSV kinda way. Otherwise Excel might be blind to the generic kind of FAT16 file.

    Am I close?

    cool.gif
    Mark
  • LeonLeon Posts: 7,620
    edited 2008-08-27 17:46
    Writing CSV files is very easy.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • jazzedjazzed Posts: 11,803
    edited 2008-08-27 17:46
    FAT16 or whatever should be tranparent to you. Think of it as a frame and your file as a picture. You make the picture and FAT16 makes the frame. CSV is the form of ASCII text that excel needs to read; the O/S handles the way it is stored ... FAT16 or otherwise. Added: Actually, FAT16 is created when you format the SD card, so you're specifying the "frames" (or clusters)·with that format. CSV stands for Comma Separated Values ....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve

    Post Edited (jazzed) : 8/27/2008 6:34:21 PM GMT
  • simonlsimonl Posts: 866
    edited 2008-08-27 20:28
    Hi Mark,

    Yup, quite simple to write CSV to SD really. Here's a snippet (that comes after mounting the card):

    OBJ
        sdfat       : "fsrw"
        Num         : "Numbers"
    
    PUB main
    
        ' Mount the SD card
        sdfat.mount(0)
    
        ' Open a file called 'data.csv' for writing
        status := sdfat.popen(string("data.csv"), "w")
        
        sta   := cnt
        bytes := 0
        lcnt  := 1
        Temp  := 1
        
        ' Write 60 lines of data in CSV format (e.g. 1,2732,AAC), 
        ' each followed by a carriage return (Chr 13)
        repeat 60
          sdfat.pwrite(Num.ToStr(lcnt, Num#DEC5), 5)
          sdfat.pputc(",")
    
          sdfat.pwrite(Num.ToStr(Temp, Num#HEX5), 5)
          sdfat.pputc(",")
    
          sdfat.pwrite(Num.ToStr(Temp, Num#DEC5), 5)
          
          sdfat.pputc(13)
          
          Temp := Temp + 2
          lcnt++
    
        ' Close the file
        sdfat.pclose
    
    



    Hope that helps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheers,

    Simon
    www.norfolkhelicopterclub.co.uk
    You'll always have as many take-offs as landings, the trick is to be sure you can take-off again ;-)
    BTW: I type as I'm thinking, so please don't take any offense at my writing style smile.gif
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-08-27 20:43
    Hey Simon,

    thanks very much for posting some code containing human language as well as Spin.· One look at this, and I'm gaining inspiration.· Seeing how the method call is actually set up helps a lot.· It's refreshing.· Ahhh...

    much appreciated,
    Mark

    ·
  • MovieMakerMovieMaker Posts: 502
    edited 2008-08-27 20:44
    Electric Avenue,

    I am such a noobie to the propeller that I don't know a lot yet. But, here is what happened to me.

    I bought a card from SparkFun for about $15. I had a 4 Gig SD ready, but I was told it is too big and may not work. So, I purchased a 2 gig SD card. I put a right angle curve in a male connector and cut off the extra pins. I soldered it right onto the protoboard. First, I hooked up the main pins to p0,p1,p3,p4. But, this conflicted with other setting. So , I hooked it up to 8,9,10 and 11. The documentation that came with the sparkFun will show you what goes to what pin. I don't think that it is important WHERE you hook them as much as you have to change the software to match the I/O pins. I complete rewired and resoldered the whole system 3 times. So it looks like a mess. But, it is working.

    Next, I loaded up Boebot BasicPP.Bin into the propeller.

    I had a lot of problems getting the Propeller to see my PC on the USB connector. It all boiled down to the stupid baud rate was too high. Once I gave it the 9600 baud that it worked, it came back with an "OK". This meant that the BASIC Language was loaded into the Propeller and was ready to accept commands.

    I had previously loaded onto the SD card a program to test it with. I wasn't able to run the program because it was not a BASIC program. But, when I said "FILES", it gave me a list of files on the SD card. I rubbed my eyes and did a double take. Could this be this simple, I asked myself?? So, I erased the files on the SD and put more with a specific name that I did not have on another drive. BINGO! When I said "FILES" it listed this special program on the SD card. I am soooooo happy!

    Make sure that you have a good ground and a good positive voltage on the card as well as data lines.

    Hope that this flimsy attempt to help you does you some good. IF Even ONE item that I mentioned helps you, I will be glad. These are a GREAT group of guys. Bar NONE.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-08-27 21:00
    MovieMaker,

    Hey, thanks for sharing your experiences with this SD thing.· I'm totally new to this Spin business, too.· I made excellent progress learning how to use the Prop and got some fundamental things started with it and I've been thrilled with my progress.· But lately I've been hitting a wall.· Much of the advanced aspects of the Prop require useage of what's in the Object Exchange (the Obex).· Problem is, much of the material there is scantily documented, if documented at all.· It's frustrating because the concept of Object-oriented programming is to have Objects that you don't have to crawl inside of and do a mind-meld with.· But that's not how the Obex is working out for me.· Instead, I'm feeling like I'm making a nuisance of myself asking for help on every little thing.· So far people have been gracious enough to try to help out, but in some cases I'm so hopelessly new at this that I don't even know the first thing of what they're talking about.· Example: two weeks ago I didn't even know what an SD card was!

    Ain't that pathetic!

    eyes.gif·
  • HarleyHarley Posts: 997
    edited 2008-08-27 21:11
    ElectricAye

    "Life!", as a friend used to say with a sigh.

    But we all have had to start at the beginning. Just wish I could of had an earlier start; say, like 'twp_man' before teens. Sigh. LIFE!


    yeah.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • jazzedjazzed Posts: 11,803
    edited 2008-08-27 21:19
    Not pathetic at all. Actually, the new spin (or whatever) folks have an opportunity to make things better for all of us. All of the experiences you have that can be captured in the written word can be molded into a beginner's text ... with knowledge corrections if necessary by the more experienced. Of course Mark's observation of the "black-box" nature of the way things should be regarding object APIs and other docs should be carefully considered by all. We can all learn a lot from the discussions here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --Steve
  • Sabre00Sabre00 Posts: 30
    edited 2008-10-17 01:55
    Having SD card woes. so I am tagging for future reference.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-10-17 04:16
    Sabre00,

    If you're having trouble with SD cards, why not post your particular problem to the forum? The people on here held my hand almost the entire way until I got my system up and running, and I knew NOTHING about SD cards when I started out. In fact, if you use the search button in the upper right hand corner of the screen and search for... Posted By... ElectricAye, you are destined to find dozens of questions about SD cards answered for me by forum gurus like Mike Green, rokicki, Rayman, OBC, StephanL, simonL, jazzed, Micah Dowty, AndreM.... in fact, it would be easier to name who DIDN'T help me get my SD card up and running.

    See for example....
    http://forums.parallax.com/forums/default.aspx?f=25&m=295496&g=295702#m295702

    Good luck,
    Mark
  • evanhevanh Posts: 15,545
    edited 2008-10-17 05:19
    I've always called it Character Separated Values. Any character can be specified and Tabs are a favourite choice, especially when comma is the Euro's decimal point. Not to mention there is often more than one separation character to represent multi-dimensional arrays.
Sign In or Register to comment.