Go Down

Topic: How do I handle a large file with an arduino? (sufficient use of memory) (Read 592 times) previous topic - next topic

The_Leo

Hello:
     I am new to arduino and am trying to create a precise map with an arduino robot. The map needs to use cm as the base unite and needs to be able to map the floor of my classroom which is at least 250m^2. Because of the size of the room, and with my format of "(x,y)n" with n a number from 0 to 6 representing the chance of the area being blocked, the size of the file would be too big to be put into a string for the arduino to process. Also, many of the functions that I need only works for strings, such locating with the coordinates. I do not know how to avoid this problem. Please help me!! :o  :o 
Thanks

PaulS

Quote
Also, many of the functions that I need only works for strings, such locating with the coordinates.
That is nonsense. One can not measure the distance between two strings. The values in the strings need to be converted to numbers for processing.

So, write the functions properly so that they do not take strings.

Quote
I do not know how to avoid this problem.
Three ways.

1) Do not use strings in place of numeric values.
2) Use an Arduino with more memory.
3) Store the map in a file on an SD card, and access the required data from the file, instead of from SRAM.

More specific answers will require that you stop waving your arms around wildly, and give specific examples of what you are trying to do.
The art of getting good answers lies in asking good questions.

The_Leo

I am so sorry for not making this clear, but I am personally very new to arduino and only have touched upon it for 2 months.
Quote
So, write the functions properly so that they do not take strings.
Can you please further explain or give me some places where I can write my functions properly, because I am very new to this and do not know any mechanism or command that may be able to do the same job. I would like to learn some more knowledge about a way of locating the text without turning the entire text into a string but instead turning only the line I am looking for into a string.
Quote
More specific answers will require that you stop waving your arms around wildly, and give specific examples of what you are trying to do.
I am so sorry for that I am unable to provide any code. This is because I am still stuck on the theory part and haven't figured out a mechanism to make a properly functioning program. Please do ask if you need any specific detail about my mechanism, I will try my best to answer them all.
Respectfully

PaulS

Quote
Can you please further explain or give me some places where I can write my functions properly,
Not without seeing an example of a function that uses strings where it shouldn't.

Quote
I would like to learn some more knowledge about a way of locating the text without turning the entire text into a string but instead turning only the line I am looking for into a string.
Suppose that you read a character. It is not an end of record marker, so what do you need to do with it? Of course, you need to add it to a string that is the current record, and you need to move the NULL terminator.

Suppose that the character IS the end of record marker. What do you need to do? You need to determine if the current record IS the correct record. How you do that is entirely up to you, since you have provided no clue as to how to determine if a record IS the correct record.

Suppose that the current record IS the correct record. What do you need to do? Again, you have provided no clue, so you are on your own on this part.

Suppose that the current record is not the correct record. What do you need to do? Of course, you need to reset the array index back to 0, put a NULL at that position, and keep reading.

If you run out of records without finding the correct record, then you know that the correct record does not exist. You can then add a record, if appropriate, or show an error message, or do whatever seems appropriate.
The art of getting good answers lies in asking good questions.

The_Leo

Thank you very much for answering my question. Your answer brought a spark to my head and I a have figured out another way to search for the location of a key word. That is I would put many delimiters in the format and read it string by string. However this brings up another question though, and it may be irrelevant to my topic, but how do you rewrite data in the file while knowing it's exact location?

PaulS

Quote
but how do you rewrite data in the file while knowing it's exact location?
If you have the file open for read and write, and want to replace 20 characters starting at position 312 with 20 different characters, just seek() to the place to start writing (312), and print() the 20 characters.

If you want to replace 20 characters with 5 characters, or 5 characters with 20 characters, the process involves two files.
The art of getting good answers lies in asking good questions.

Go Up