Shop OBEX P1 Docs P2 Docs Learn Events
Example of reading data from a microSD with FSRW 2.6 PLEASE — Parallax Forums

Example of reading data from a microSD with FSRW 2.6 PLEASE

kotsoskotsos Posts: 12
edited 2011-04-12 09:24 in Propeller 1
Hello,

I've been searching for documentation over the internet, but I found nothing on "how to read data from a microSD with the propeller". I know how to write data with the FSRW object, but I can only read one character at a time.
Is there anyone who can enlight me on how to read entire strings of numbers (separated by space)?

Thanks in advance!

Comments

  • groggorygroggory Posts: 205
    edited 2011-04-03 17:29
    Go look up kye's most recent SD FAT32 driver and see how far that takes you
  • kotsoskotsos Posts: 12
    edited 2011-04-03 19:18
    I got nowhere...

    I would like to actually see an example (like a couple lines of code) on how this is done with the FSRW 2.6
    I know that the following code would get you a character, but how can you extract strings of that?
    OBJ                             
    sdfat : "fsrw"
    pst : "FullDuplexSerial"
    
    sdfat.popen(string("text.txt"),"r")    
    temp := sdfat.pgetc
    pst.tx(temp)
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-04-03 19:38
    This is a link to Kye's driver http://forums.parallax.com/showthread.php?122991-SD2.0-Full-FAT32-16-File-Sytem-Driver-You-there!-Yes-you-viewing-this-forum.&highlight=kyedos

    There is enough to read files, but if you need to do more, eg string manipulaton, then Kye's code also has this as well, in a separate string object.

    For reading strings of numbers with a space, it will help to know the data format. What does your data stream look like (including spaces, CR, LF etc)?

    If spaces only are between the characters, we can use some extra string functions I added to Kye's code, eg "instr" to find the next space.
  • KyeKye Posts: 2,200
    edited 2011-04-03 20:09
    Kotsos - Send me an email and I'll provide you with what todo. Thanks, if you can't find my email PM me.
  • kotsoskotsos Posts: 12
    edited 2011-04-03 21:25
    Thanks a lot Kye!, I've sent you an e-mail!
  • ElkinElkin Posts: 58
    edited 2011-04-04 01:42
    Can you post this when you get it back? I would like to have a look at this also as I am having some issues with the same thing.

    Thanks
  • JonnyMacJonnyMac Posts: 9,376
    edited 2011-04-04 11:07
    The process is not difficult if you take it step-by-step. In my case, I'm working on an animation controller that will read a CSV file of servo and lighting values (each line is a frame) and the Propeller will parse and use that data.

    I wrote the attached program to get a little experience reading lines of text from a file on the SD card (using FSRW). Note that I created a custom method called readln() as this is not part of the FSRW object.
  • ElkinElkin Posts: 58
    edited 2011-04-04 23:41
    Jon,

    I ran your MCP 3202 program and it works great! I was wondering if you have ever wrote anything that will take those values and write them to an SD card like the one that is used in the code above. All of the objects in the exchange use the PST as an output for either the SD card system or for the ADC, but none of them have any different programs for sending files to other slaves.

    Once they are on the card it doesnt seem to be a problem dumping them.

    Thanks,
    Kyle
  • HollyMinkowskiHollyMinkowski Posts: 1,398
    edited 2011-04-05 00:20
    Kye wrote: »
    Kotsos - Send me an email and I'll provide you with what todo. Thanks, if you can't find my email PM me.

    Kye, you are almost too good to be true!
    Always so willing to help someone out.
    And your coding skills are first class. :-)
  • JonnyMacJonnyMac Posts: 9,376
    edited 2011-04-05 10:16
    Elkin wrote: »
    Jon,

    I ran your MCP 3202 program and it works great! I was wondering if you have ever wrote anything that will take those values and write them to an SD card like the one that is used in the code above. All of the objects in the exchange use the PST as an output for either the SD card system or for the ADC, but none of them have any different programs for sending files to other slaves.

    Once they are on the card it doesnt seem to be a problem dumping them.

    Thanks,
    Kyle

    No... but that doesn't stop me from putting on a pot of coffee and giving it a try. It turns out to be pretty easy: I simply copied the .dec() method from FDS and modified it to "print" to a string (passed by pointer) instead of to a serial stream.

    I didn't want to be bothered connecting an MCP3202 so I wrote a method that provides two, randomized 12-bit values -- replace this with calls to the MCP3202. The output is to a CSV file and as you can see I was able to open it as desired in my spreadsheet, including text headers for each column.
    526 x 418 - 144K
    800 x 600 - 309K
  • ElkinElkin Posts: 58
    edited 2011-04-05 13:34
    Jon,

    This looks fantastic! I was thinking that using some king of shiftout or printout function was what I needed to do, but I just was not sure how to do it. I really appreciate the help, it is working great!

    Cheers,
    Kyle
  • ElkinElkin Posts: 58
    edited 2011-04-11 02:12
    Jon,

    I have connected everything and and I still seem to be having trouble. The PUB that I am calling in place of the lottery variable is read from your jm_MCP3202_ez program. In the beginning of the program I am also calling the jm_MCP3202_ez.init PUB block as is done your demo. The problem seems to be that the first value out is a good 12 bit number but the following values are much smaller. I am not sure if I am loosing bits during the transfer or what is happening. I am now wondering if I need to have a "0" terminator in this call for the pputs function or dec2str call to know where to terminate the number.

    here is what I have so far:

    PUB read_adc (pntr0) | ch0

    'long [pntr0] := ?lottery & $FFF

    long [pntr0] := ADC.read (ch0, ADC#SE)
  • JonnyMacJonnyMac Posts: 9,376
    edited 2011-04-11 18:34
    Do you have the latest version of my MCP3202 code? I made a change about a month ago that fixed an error. I don't know if that's the source of what you're seeing but, as ever, I suggest you test all the pieces individually. My MCP3202 code (jm_mcp3202_ez.spin) comes with a test program. Run that first to check your connections. Once you're satisfied that's working you can fold the read into your datalogging program.

    My MCP320x code: http://obex.parallax.com/objects/625/

    On another note, I've been using that readln() method in other programs and have modified it based on C source I found for a generic SD card driver. This is the new version (which terminates on LF instead of CR):
    pub readln(pntr, n) | c, len
    
    '' reads line of text from open file
    '' -- terminated by LF or EOF
    '' -- pntr is address of string buffer
    '' -- n is maximum number of characters to read from line
    
      len  := 0                                                     ' index into string
    
      repeat
        c := \sdcard.pgetc                                          ' get a character
        if (c < 0)                                                  ' end of file or error
          if (len == 0)                                             ' if nothing
            len := -1                                               ' return empty
          quit
        if (c == LF)                                                ' if LF we're done with line
          quit
        else
          if (c <> CR)                                              ' if not a CR
            byte[pntr++] := c                                       '   move c to buffer
            len++                                                   '   update character count
    
      byte[pntr] := 0                                               ' terminate end of line
    
      return len
    
  • ElkinElkin Posts: 58
    edited 2011-04-12 09:24
    Jon,

    The issue was with the mux bit configuration as I am only using channel 0 on the ADC. I have looked at this readln method a bit and I think it could be useful for retrieving data from the SD card without having to remove it. As always, I appreciate the help!
Sign In or Register to comment.