1

I need to parse a lot of data. When I mean a lot, I'm talking around 5,000 - 10,000 characters. Right now, my code works with 285ish pieces of data. I'm using the Arduino prototyping platform. Here's my loop() in my sketch:

void loop() {

    if (client.available()) {
        char inChar = client.read();
        currentLine += inChar;
        if (inChar == '\n') { currentLine = ""; }

        if (currentLine.endsWith("[start]")) {
            readingData = true;
            theData = "";
        }

        if (readingData) {
            if (inChar != '[') {
                 theData += inChar;
                 //Serial.println("something!");
            }
            else {
                readingData = false;
                int count = theData.length()-0;
                theData = theData.substring(1, count);
                Serial.println(theData);
                doAction(100,count,theData);
                client.stop();
            }
        }
    }

    if (!client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();
        for(;;)
            ;
    }
}

Should I split it up into 20+ strings and put them in an array? I'm not sure if my 2KB of RAM will be able to handle that.

4
  • Where do your 10000 characters come from? This is unlikely to even fit in the AVR's memory, IIRC. Commented Dec 20, 2011 at 17:41
  • @JamWaffles: From a remote URL that will turn on/off a sequence of LEDs on my breadboard. Commented Dec 20, 2011 at 17:44
  • 2
    I can't understand how you need 10k characters to control some LEDs. As Basile says, the AVR doesn't have enough RAM, so you'll need to split your string up into chunks and send them in, say, 1KB parts. Commented Dec 20, 2011 at 17:46
  • Eventually it's going to control christmas lights. If a song is 300 beats (around 2-3 mins), then using my code it would be around 5,000 characters... Commented Dec 20, 2011 at 17:50

1 Answer 1

4

With 2 kilobytes of RAM you can have no more than 2000 bytes of data (and in reality, significantly less, for example, perhaps only 1500 bytes, because of stack and global spaces).

If you need to process 20 kilobytes of data in memory, buy a bigger microcontroller.... (or program your Arduino to transmit the data to your PC which will process it).

Sign up to request clarification or add additional context in comments.

4 Comments

Sending it to my computer isn't an option. It's going to run remotely using a arduino uno & ethernet shield. Can I expand my memory?
@phpnerd211 This is a good candidate for an XY Problem; solve the root cause instead of hacking a solution to your problem. You should send your data in ~1KB packets over your network from the computer.
@phpnerd211: You will have to parse and interpret bytes as you get them and not keep them in memory unless you absolutely have to. As it is, your code appears to only keep one line at a time in memory (perfect!) so RAM shouldn't be an issue. Though you may want to put the lines containing currentLine into an if (!readingData) {, which will save you a bit more memory (and time).
@Mooing Duck: Wow, I can't believe I didn't think of that. It all works fine and dandy now! Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.