Page 4 of 7 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 62

Thread: Sequence file decoding on Arduino

  1. #31
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Hows this for using an array to search the file?

    boolean flag;
    char searchArray[4];
    while (flag == 0)
    {
    searchArray[1] = searchArray[2];
    searchArray[2] = searchArray[3];
    searchArray[3] = searchArray[4];
    searchArray[4] = vixen1.read();

    if (searchArray[1] == 'u' && searchArray[2] == 'e' && searchArray[3] == 's' && searchArray[4] == '>')
    flag = 1;
    }

    Is that what you had in mind?



    EDIT:
    This did it!

    char searchArray[4];
    while(flag == 0 && vixen1.available())
    {
    searchArray[0] = searchArray[1];
    searchArray[1] = searchArray[2];
    searchArray[2] = searchArray[3];
    searchArray[3] = vixen1.read();
    vixlog.print(searchArray[3]);

    if (searchArray[0] == 'u' && searchArray[1] == 'e' && searchArray[2] == 's' && searchArray[3] == '>')
    {
    flag = 1;

    }

    }
    Last edited by Jonpro03; 04-07-2012 at 06:35 PM.
    - Jon Proietti

  2. #32
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Well, i hit the limit already. I am running out of ram on the arduino and some very interesting things are happening.

    It wasn't a problem until I tried to decode base64.

    With the base64 decode code commented out, I was able to run normally again. When I threw an 87kB file on the SD card to be read, the arduino would crash as soon as I try to access the file.


    I'll have to put PROGMEM to work tomorrow to free up some ram.

    Debug output to serial:

    Code:
    Initializing SD card... card initialized.
    Deleting old vixenlog.txt file...  finished.
    Creating new vixenlog.txt file...  finished. ˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙˙
    Last edited by Jonpro03; 04-08-2012 at 12:11 AM.
    - Jon Proietti

  3. #33
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    With all of this work spent on decoding .vix files into something useful, I realize that the other half of the equation is to have the arduino playback audio off of the SD card. I spent some time researching mp3 playback today. I don't like any of the current shields (not saying we can't use them) because they require too much work to be done by the arduino. I would like to keep the arduino free to do other things and hand the audio decoding and playback off to another micro.

    I am proposing a daughter board based on the VLSI VS10xx MP3 decoder. http://www.vlsi.fi/en/products/vs1011.html
    The only input it needs from the Arduino is a play command with a filename.
    It will sit on the SPI bus along with an SD cardslot and a 32K SRAM module.

    Please give me feedback. Is it worth it to design a playback shield, or should we stick to existing shields.
    - Jon Proietti

  4. #34
    Join Date
    Dec 2011
    Location
    Northern California
    Posts
    649

    Default Re: Sequence file decoding on Arduino

    Jon,

    Glad you found the 0 based array stuff yourself. dimensionsing an array[4] mean indexing by 0..3

    How were you planning to handle the decode? Were you reading a .pix file and writing another file?

    (Obviously 87 KB decoded to about 3/4 of that size is not going to fit in 2 KB of RAM)

    Or were you only decoding a few bytes at a time, to use those values, and then the next few?
    Zeph

  5. #35
    Join Date
    Dec 2011
    Location
    Northern California
    Posts
    649

    Default Re: Sequence file decoding on Arduino

    Jon,

    Which audio shields have you investigated? Let's post the URLs so we can avoid duplication of effort - or having a good option fall through the cracks.

    Are you saying the VL10xx acts as both an SPI bus slave (to receive commands from the Arduino) and as an SPI bus master (to fetch data from the SD card)?

    One thing to keep in mind is time synchronization. We don't want to drift out of sync, between the music and the blinky.

    By the way, with the Mega the RAM can increase quite a bit, tho not enough to hold large sequencing files. Not only is there 8 KBytes of RAM (vs 2 KB), but for $20-25 you can get an add-on for the Mega (not for the Uno, which doesn't have the needed extra pins) which expands that to 56K, with bank switching access to even more. I mean program RAM, where you can store variables and arrays and access them freely, not SPI based RAM which can more slowly be fetched or stored byte by byte. Just something to keep in mind - meanwhile, let's try to make things fit into standard Uno's if possible.

  6. #36
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Quote Originally Posted by Zeph View Post
    Jon,

    Glad you found the 0 based array stuff yourself. dimensionsing an array[4] mean indexing by 0..3

    How were you planning to handle the decode? Were you reading a .pix file and writing another file?

    (Obviously 87 KB decoded to about 3/4 of that size is not going to fit in 2 KB of RAM)

    Or were you only decoding a few bytes at a time, to use those values, and then the next few?
    Zeph
    The plan currently is to decode the base64 ahead of time (on the arduino), reorganize the data, and save it to a file on the SD card. Then reboot the arduino (watchdog), check for the reorganized data file, and load data from the SD.

    If the reads from the SD are too slow, I may implement a buffer using the SPI SRAM.
    - Jon Proietti

  7. #37
    Join Date
    Dec 2011
    Location
    Northern California
    Posts
    649

    Default Re: Sequence file decoding on Arduino

    So, given 87 KB of file on the SC card, how much were you thinking to buffer in 2K of RAM before writing it out to another file?

  8. #38
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Honestly, I haven't gotten that far. I'm not sure how the base64 decoding will go.

    I think that if I try to decode 3 or 4 characters at a time, it will not decode correctly. At the end of the first track, I would end up with a little bit of data for the 2nd track. But I think this will be the only way to do it because I cannot decode an entire track at once (unless it's really short). I'll just have to remember to calculate and drop the un-needed bits at the end of the first track, then drop the un-needed bits at the beginning of the second and so on...
    - Jon Proietti

  9. #39
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Here's the code as of now. It's successfully getting the length of the track, length of each event, and the number of channels from a .vix file.

    Lots of code has been commented out because I've been battling with running out of ram. :-/

    Code:
    //#include <EEPROM.h>
    //#include <avr/wdt.h>
    #include <SD.h>
    //#include <Base64.h>
    //#include <avr/pgmspace.h>
    
    #define filename "32ch" //leave out the .vix
    #define chipSelect 10
    
    //File periodFile, vixen1, lengthFile, channelFile;
    File vixen1;
    
    void setup()
    {
      Serial.begin(115200);
      Serial.print("Initializing SD card...");
      pinMode(10, OUTPUT); //card select pin
    
      if (!SD.begin(chipSelect)) 
      {
        //If card failed to initialize, exit.
        Serial.println(" Card failed, or not present. ");
        Serial.println("Try rebooting your Arduino and ensuring your card is properly formatted.");
        return;
      }
      Serial.println(" card initialized.");
      //Look for first sequence named 1.vix
      if (SD.exists(filename".vix"))
      {
        Serial.print(filename);
        Serial.println(".vix found. ");
        Serial.println();
      }
      //If not found, error and exit
      else
      {
        Serial.println("ERROR - File not found. ");
        Serial.println("Ensure that you've entered the correct filename and try again.");
        Serial.println("Exiting...");
        //vixenlog.flush();
        //vixenlog.close();
        return;
      }
    
      if (!SD.exists(filename".lng"))
      {
    
        uint32_t trackLength = 0, eventPeriod = 0, numChannels = 0;
        boolean flag = 0;
        char searchArray[9], Read;
        uint16_t Cursor = 0;
    
    
    
        Serial.println("Looks like a new sequence. Entering configuration mode.");
        //Open 1.vix and find the track length in milliseconds
        vixen1 = SD.open(filename".vix", FILE_READ);
        // Cursor = 60;
        // vixen1.seek(Cursor);
        Serial.print(filename);
        Serial.print(".vix opened. Searching for configuration data...");
        vixen1.seek(1);
    
        // while (vixen1.available()) 
        // Serial.write(vixenlog.read());
    
    
    
        //Code to find TIME
        while(flag == 0 && vixen1.available())
        {
          searchArray[0] = searchArray[1];
          searchArray[1] = searchArray[2];
          searchArray[2] = searchArray[3];
          searchArray[3] = vixen1.read();
          
    
          if (searchArray[0] == 'i' && searchArray[1] == 'm' && searchArray[2] == 'e' && searchArray[3] == '>')
          {
            flag = 1;
            Serial.print(".");
          }
    
        }
    
        if (flag == 0)
        {
          Serial.println(" ERROR - Unable to determine TRACK LENGTH. Please ensure the correct file name was declared and it is a *.vix file.");
          return;
        }
    
        flag = 0;
    
        while (Read != '<')
        { 
          Read = vixen1.read();
          if (Read != '<')
          {
            trackLength += Read - 48;
            trackLength *= 10;
            Serial.print(".");
          }
          else
            trackLength /= 10;
        }
    
        Cursor = vixen1.position();
    Serial.print(".");
    
    
        //Find the event period in milliseconds
        Cursor += 37;
        vixen1.seek(Cursor);
    
        Read = 0;
        while (Read != '<')
        { 
          Read = vixen1.read();
    
          if (Read != '<')
          {
            eventPeriod += Read - 48;
            eventPeriod *= 10;
            Serial.print(".");
          }
    
          else
            eventPeriod /= 10;
        }
    
    
        //Code to find NUMBER OF CHANNELS
    
    
        while(vixen1.available())
        {
          searchArray[0] = searchArray[1];
          searchArray[1] = searchArray[2];
          searchArray[2] = searchArray[3];
          searchArray[3] = searchArray[4];
          searchArray[4] = searchArray[5];
          searchArray[5] = searchArray[6];
          searchArray[6] = searchArray[7];
          searchArray[7] = searchArray[8];
          searchArray[8] = vixen1.read();
          
    
          if (searchArray[0] == '/' && searchArray[1] == 'C' && searchArray[2] == 'h' && searchArray[3] == 'a' && searchArray[4] == 'n' && searchArray[5] == 'n' && searchArray[6] == 'e' && searchArray[7] == 'l' && searchArray[8] == '>')
           {
            numChannels += 1;
            Serial.print(".");
           }
        }
    
    Serial.println(" Finsihed.");
      vixen1.close();
      
        /*     
         //Save TRACK LENGTH, EVENT PERIOD, CHANNELS files.
         Serial.print("Saving length file... ");
         lengthFile = SD.open(filename".lng", FILE_WRITE);
         lengthFile.write(trackLength);
         lengthFile.close();
         Serial.println(" finished.");
         
         Serial.print("Saving period file... ");
         periodFile = SD.open(filename".per", FILE_WRITE);
         periodFile.write(eventPeriod);
         periodFile.close();
         Serial.println(" finished.");
         Serial.println();
         
         Serial.print("Saving Channels file... ");
         channelFile = SD.open(filename".chl", FILE_WRITE);
         channelFile.write(numChannels);
         channelFile.close();
         Serial.println(" finished.");
         Serial.println();
         
         */
        //Print out discovered TRACK LENGTH, EVENT PERIOD, CHANNELS.
        Serial.println();
        Serial.print("Track length is ");
        Serial.print(trackLength);
        Serial.println("ms. ");
        Serial.println();
        Serial.print("Event period is ");
        Serial.print(eventPeriod);
        Serial.println("ms.");
        Serial.println();
        Serial.print("Number of Channels is ");
        Serial.print(numChannels);
        Serial.println(".");
    
        Serial.println("Sequence configuration successful.");
        // cli();			// Clear interrupts
        //wdt_enable(WDTO_15MS);	// Set the Watchdog to 15ms
        //while(1);		// Enter an infinite loop 
        //Serial.print(".");
    
    
      }
    /*
      Serial.println("Looks like this sequence is configured, time to decode.");
      char searchArray[4], Read;
      boolean flag = 0;
      //  lengthFile = SD.open(filename".lng", FILE_READ);
    
      //Find the event values
       Serial.println("");
       Serial.println("Prepare for some gibberish while I look for the event values...  ");
       while(flag == 0 && vixen1.available())
       {
       searchArray[0] = searchArray[1];
       searchArray[1] = searchArray[2];
       searchArray[2] = searchArray[3];
       searchArray[3] = vixen1.read();
       Serial.print(searchArray[3]);
       
       if (searchArray[0] == 'u' && searchArray[1] == 'e' && searchArray[2] == 's' && searchArray[3] == '>')
       {
       flag = 1;
       Serial.println(" They're here!");
       Serial.println("found data");
       }
       
       }
       if (flag == 0)
       {
       Serial.println("ERROR - Unable to find data to decode. Please say 3 hail mary's and try again");
       return;
       }
       
      /*
       Cursor = vixen1.position();
       Read = 0;
       while (Read != '<' && vixen1.available())
       { 
       Read = vixen1.read();
       }
       
       Cursor = vixen1.position() - Cursor;
       Serial.println(" HEY JON LOOK HERE!!! ");
       Serial.print(Cursor);
       
       
       // vixdat = SD.open("1.avx", FILE_WRITE);
       
       Serial.println();
       Serial.print("Track length is ");
       Serial.print(trackLength);
       Serial.println("ms. You must have worked hard on that.");
       Serial.println();
       Serial.print("Event period is ");
       Serial.print(eventPeriod);
       Serial.println("ms. Should make for a good show.");
       */
    
    
      //Dump vixenlog to serial
      //vixenlog.seek(1);
      // while (vixenlog.available()) 
      //   Serial.write(vixenlog.read());
    
    
    
      //Save and close files for now
     
      vixen1.close();
      //vixenlog.flush();
      //vixenlog.close();
    
    
    }
    
    void loop()
    {
    }
    /*
    //this is the code is to reboot the arduino
     cli();			// Clear interrupts
     wdt_enable(WDTO_15MS);	// Set the Watchdog to 15ms
     while(1);		// Enter an infinite loop 
     */
    and here is the serial output:

    Code:
    
    Initializing SD card... card initialized.
    32ch.vix found. 
    
    Looks like a new sequence. Entering configuration mode.
    32ch.vix opened. Searching for configuration data............................................. Finsihed.
    
    Track length is 253204ms. 
    
    Event period is 50ms.
    
    Number of Channels is 32.
    Sequence configuration successful.

    I had initially planned on creating separate files for track length, event period, and number of channels... but now I think that might be a bad idea. In the best interests of RAM, i think it may be best to use the SD card library as little as possible.

    Opinions on using EEPROM to store those values through a reboot?

    Also, anyone with a SD card on their Arduino want to give this code a shot and see if it works with their .vix files?
    The vixen file needs to be in the root directory of the SD card and the filename needs to be declared in the code.
    Last edited by Jonpro03; 04-15-2012 at 09:26 PM.
    - Jon Proietti

  10. #40
    Join Date
    Dec 2011
    Location
    Illinois
    Posts
    180

    Default Re: Sequence file decoding on Arduino

    Put in another couple of hours yesterday. Everything is going well.
    There are now two functions, a config() function and a decode() function. Both get the filename as a variable so that we can use multiple sequences. Each function also checks to see if the file has already been config'd/decoded and if so, returns.

    The config function is complete and in need of testing. It finds 3 variables, trackLength, eventPeriod, numChannels. These are saved in EEPROM at locations 0, 4, and 8 respectively. For the second track, it will be 10, 14, 18, and so on.

    I've only got a little of the decode function written. Before I went to bed last night, it decoded 4 characters of base64 :D. I could use some help if anyone wants to join the effort.

    Here is the code so far:

    Code:
    void decode()
    {
      //Base64 decode
    
        Serial.println("Starting to decode... ");
    
      char searchArray[4]; 
      uint8_t dataArray[3];
      boolean flag = 0;
    
      File vixen1, dataFile;
      vixen1 = SD.open (filename".vix", FILE_READ);
      dataFile = SD.open (filename".dat", FILE_WRITE);
      
      //Find the event values
      Serial.println();
      Serial.println("Searching for event values...");
      while(flag == 0 && vixen1.available())
      {
        searchArray[0] = searchArray[1];
        searchArray[1] = searchArray[2];
        searchArray[2] = searchArray[3];
        searchArray[3] = vixen1.read();
        Serial.print(searchArray[3]);
        
        if (searchArray[0] == 'u' && searchArray[1] == 'e' && searchArray[2] == 's' && searchArray[3] == '>')
          flag = 1;  
      }
      if (flag == 0)
      {
        Serial.println("ERROR - Unable to find data to decode.");
        return;
      }
    
      for (int i = 0; i < 4; i++)
      {
        searchArray[i] = vixen1.read();
        Serial.print(searchArray[i]);
      }
      Serial.println(base64_dec_len(searchArray, 4));
      
      
      Serial.println(base64_decode(dataArray, searchArray, 4));
      
      for (int i = 0; i < 3; i++)
      {
        Serial.print(searchArray[i]);
        //dataFile.write(dataArray[i]);
      }
    
    }
    Not much yet...
    Last edited by Jonpro03; 04-18-2012 at 09:01 AM.
    - Jon Proietti

Page 4 of 7 FirstFirst ... 23456 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •