Hi and first of all thank you for the great help in the past
in the last months i was more an reader or using the search engine but now i have a question and couldn´t find the answer myself so i need some help.
I want to read commands (txt file) form an SD Card to control the arduino.
For example i write an txt file with rows like this ( 1 125 250 250 300)
the first number is a time stamp the next number should be used to set the pwm for an led so here for 4 leds.
the txt has many many rows so i can store a program on the sd and the arduino will use the txt to control the leds so it can be used without a direct connection to a pc.
A time stamp generally indicates when an event occurred. Presumably this is not what you mean by a time stamp. You should explain what you do mean by timestamp.
It's not clear what help you need. Do you have an SD card shield now? Do you know how to read from it? Do you know how to parse the text you read from the card, to extract one record? Do you know how to parse that record to extract the 5 values as integers? Do you know how to set the PWM value for a pin? Do you know how to do stuff for a specified amount of time?
If you answered yes to all the questions, it's just a matter of doing those steps in the right order.
the "time stamp" on my txt is the time when i want to change the led setting.
for example in the first row there is 1 (maybe for in second 1)
in the second row the 2 or an other number.
with help of the millis() command is should be able to start the action i want in the time i wish.
to the questions i know how to control leds with pwm and set these
and the time factor is an easy thing with millis() ( i think so)
Do you have an SD card shield now? Do you know how to read from it? Do you know how to parse the text you read from the card, to extract one record? Do you know how to parse that record to extract the 5 values as integers?
the answer for this questions is no
i want to clear the details so i can find the best shield for my problem
and the special problem is to get the data out of the sd and to integers for the Controlling.
i want to clear the details so i can find the best shield for my problem
and the special problem is to get the data out of the sd
Sparkfun has one:
On that site, if nothing else, is a quick-start guide that has links to libraries and stuff that will make reading from the SD card easy.
If you use the library that they link to, the file.read() function returns one character at a time from the file. Using that function in a loop, terminating when the character read is a carriage return or line feed ('\r' or '\n') will allow you to read one record at a time, into a char array.
The strtok() function can then be used to parse the record, extracting each token ("1", "125", "250", "250", and "300" in your example).
Each token can be passed to atoi() which returns an int that the string represents. (300 is not a valid PWM value...)
i have no experience of recording in chars and especially with the strtok() function. (is there an example in such an direction)
How "fast" can arduino handle this hole process ( i know it depends on the hole syntax and all)? i hope to get it fast enough for a quick changing light effect.
P.S i know that 300 is no PWM level i was just in the example typing but non then less thank you.
The limiting factor will be the speed with which data can be read from the SD card. Since the records are fairly small, as long as you don't have a million records in one file, you should be able to read an process several records per second.
There have been some posts recently about ways to speed up the access of data from SD cards. Might be worth investigating.