Reading a CSV / txt file

Ok so kinda new to Arduino, been playing around with projects and some code, but by no means a master of it. What I need advice or help with is reading a CSV or txt file on a SD card or other portable storage. Right now I have a remote controller(for fireworks firing systems) that when in computer mode receives serial data from a program to set various pins high/low to activate the buttons on the remote controller, I did not write the entire script, it has been modified many times over and adapted to my use. The program that controls it uses a live serial communications it does not load anything into the Arduino it just sends out the serial commands.

What I would like to do is modify the sketch to "look for" a csv or txt file when powered up and read that file to create the firing commands for the controller, so the system can be used with a computer and the firing software OR the text file on a portable storage device. I am also figuring I would need a "trigger" of some sort to start the file program (ie press button to start, press again to pause/stop, press again to start from pause/stop point), when connected to a computer and with the software connected and running it would ignore csv commands, does that make any sense? I have searched and only found ways to write to CSV, or read a CSV on a computer but not what I need. I have posted the sketch as it sits now for you to see how it works, and also a copy of a typical CSV the program can export.

FJpyrosys_e_match_Johnny_Poole_V4.ino (22.3 KB)

altertatingcsv.xls (15 KB)

What I would like to do is modify the sketch to "look for" a csv or txt file when powered up and read that file to create the firing commands for the controller, so the system can be used with a computer and the firing software OR the text file on a portable storage device.

There are examples of reading text from a SD card in the SD library. You should be able to modify the example to deal with the fact that the file might not be present.

I am also figuring I would need a "trigger" of some sort to start the file program (ie press button to start, press again to pause/stop, press again to start from pause/stop point

OK.

when connected to a computer and with the software connected and running it would ignore csv commands, does that make any sense?

What software? Detecting that the Arduino is/is not connected to a PC is not a trivial task. Without the PCs knowledge/active support, it is, in fact, impossible.

The software is written like VB (or similar I did not write it) and it send the serial commands to the Arduino "real time" the sketch reads them and sets the aropriate pins high/low. I was looking for a way to take a text file (from the same program) and load it into a SD card or similar for the Sketch to "see it" and read it. However if the is not possible with the current sketch, can another Arduino be empolyed with a different sketch to take a CSV file from the computer, store it and send out serial commands to the first Arduino? Kinda like a small virtual computer? Or am I just going in circles?

You could have the sketch look for a specifically named csv file on your SD card and, if it finds it, get your firing commands by reading the file. If the file is missing, have it read from the serial port instead.

Alternatively (and perhaps a little safer) add a switch that you use to tell the arduino which option to use.

wildbill:
You could have the sketch look for a specifically named csv file on your SD card and, if it finds it, get your firing commands by reading the file. If the file is missing, have it read from the serial port instead.

Alternatively (and perhaps a little safer) add a switch that you use to tell the arduino which option to use.

Is there anyway you can look at the above file and maybe give me some pointers on at least some of what needs to change? or point me to the right tutorials I tried searching the playground and googled it but really didn't find what I was looking for(or maybe did not fully understand what it was I needed to do) So I can start playing with it, I am still really green at this, but with some guidance I think I can handle it, or at least get close. Also I know you can power the UNO board through the power plug, would a memory stick (USB drive)work for this better than a shield on the UNO board itself?

Can you post the csv file in text format? I can't read xls.

This should open in Notepad the current firing software imports in this format. The first lines on top (header) are
Nr,(order of fire command)
slave,(which slave is chosen-encoding section of Arduino sketch)
output, (this is the bank/cue section of the Arduino code)
Ignition time, (time the cue is fired)
breaktime(time effect is in the sky, not important for the sketch)
duration(effect duration not important for sketch)
delay( this is the prefire of ignition time, relected in the ignition time, not important)

the other headers are none relevant as well. Time is entered as 00:00:000 (minutes:seconds:tenths,hundreths, etc) I really hope you understood that just in case it does not open here is copy in quotes.

Nr.,Slave ID:,Output:,Ignition time:,Breaktime:,Duration:,Delay:,Description:,Position:,Angle:
1,3,1,00:01.000,00:01.000,00:00.000,0,,,
2,1,1,00:01.500,00:01.500,00:00.000,0,,,
3,3,9,00:02.000,00:02.000,00:00.000,0,,,
4,1,9,00:02.500,00:02.500,00:00.000,0,,,
5,3,17,00:03.000,00:03.000,00:00.000,0,,,
6,1,17,00:03.500,00:03.500,00:00.000,0,,,
7,3,25,00:04.000,00:04.000,00:00.000,0,,,
8,1,25,00:04.500,00:04.500,00:00.000,0,,,
9,3,2,00:05.000,00:05.000,00:00.000,0,,,
10,1,2,00:05.500,00:05.500,00:00.000,0,,,
11,3,10,00:06.000,00:06.000,00:00.000,0,,,
12,1,10,00:06.500,00:06.500,00:00.000,0,,,
13,3,18,00:07.000,00:07.000,00:00.000,0,,,
14,1,18,00:07.500,00:07.500,00:00.000,0,,,
15,3,26,00:08.000,00:08.000,00:00.000,0,,,
16,1,26,00:08.500,00:08.500,00:00.000,0,,,
17,3,3,00:09.000,00:09.000,00:00.000,0,,,
18,1,3,00:09.500,00:09.500,00:00.000,0,,,
19,3,11,00:10.000,00:10.000,00:00.000,0,,,
20,1,11,00:10.500,00:10.500,00:00.000,0,,,
21,3,19,00:11.000,00:11.000,00:00.000,0,,,
22,1,19,00:11.500,00:11.500,00:00.000,0,,,
23,3,27,00:12.000,00:12.000,00:00.000,0,,,
24,1,27,00:12.500,00:12.500,00:00.000,0,,,
25,3,4,00:13.000,00:13.000,00:00.000,0,,,
26,1,4,00:13.500,00:13.500,00:00.000,0,,,
27,3,12,00:14.000,00:14.000,00:00.000,0,,,
28,1,12,00:14.500,00:14.500,00:00.000,0,,,
29,3,20,00:15.000,00:15.000,00:00.000,0,,,
30,1,20,00:15.500,00:15.500,00:00.000,0,,,
31,3,28,00:16.000,00:16.000,00:00.000,0,,,
32,1,28,00:16.500,00:16.500,00:00.000,0,,,
33,3,5,00:17.000,00:17.000,00:00.000,0,,,
34,1,5,00:17.500,00:17.500,00:00.000,0,,,
35,3,13,00:18.000,00:18.000,00:00.000,0,,,
36,1,13,00:18.500,00:18.500,00:00.000,0,,,
37,3,21,00:19.000,00:19.000,00:00.000,0,,,
38,1,21,00:19.500,00:19.500,00:00.000,0,,,
39,3,29,00:20.000,00:20.000,00:00.000,0,,,
40,1,29,00:20.500,00:20.500,00:00.000,0,,,
41,3,6,00:21.000,00:21.000,00:00.000,0,,,
42,1,6,00:21.500,00:21.500,00:00.000,0,,,
43,3,14,00:22.000,00:22.000,00:00.000,0,,,
44,1,14,00:22.500,00:22.500,00:00.000,0,,,
45,3,22,00:23.000,00:23.000,00:00.000,0,,,
46,1,22,00:23.500,00:23.500,00:00.000,0,,,
47,3,30,00:24.000,00:24.000,00:00.000,0,,,
48,1,30,00:24.500,00:24.500,00:00.000,0,,,
49,3,7,00:25.000,00:25.000,00:00.000,0,,,
50,1,7,00:25.500,00:25.500,00:00.000,0,,,
51,3,15,00:26.000,00:26.000,00:00.000,0,,,
52,1,15,00:26.500,00:26.500,00:00.000,0,,,
53,3,23,00:27.000,00:27.000,00:00.000,0,,,
54,1,23,00:27.500,00:27.500,00:00.000,0,,,
55,3,31,00:28.000,00:28.000,00:00.000,0,,,
56,1,31,00:28.500,00:28.500,00:00.000,0,,,
57,3,8,00:29.000,00:29.000,00:00.000,0,,,
58,1,8,00:29.500,00:29.500,00:00.000,0,,,
59,3,16,00:30.000,00:30.000,00:00.000,0,,,
60,1,16,00:30.500,00:30.500,00:00.000,0,,,
61,3,24,00:31.000,00:31.000,00:00.000,0,,,
62,1,24,00:31.500,00:31.500,00:00.000,0,,,
63,3,32,00:32.000,00:32.000,00:00.000,0,,,
64,1,32,00:32.500,00:32.500,00:00.000,0,,,

alternatating.zpl.csv (2.82 KB)

Now I'd suggest that you write a new sketch that uses the SD library to read the file. Use read to accumulate the data a line at a time into a char array, then use atoi to parse out the data items you need from each line. Once this is working, combine it with your original sketch.

firejunkie:
Time is entered as 00:00:000 (minutes:seconds:tenths,hundreths, etc)

You aren't using a comma in your time format are you? That wouldn't work well with a CSV format.

PeterH:

firejunkie:
Time is entered as 00:00:000 (minutes:seconds:tenths,hundreths, etc)

You aren't using a comma in your time format are you? That wouldn't work well with a CSV format.

No, each time entry (ignition time, breaktime,delay etc) is comma seperated the time itself is 00:00:000 (Minutes:seconds:hundredths)

wildbill:
Now I'd suggest that you write a new sketch that uses the SD library to read the file. Use read to accumulate the data a line at a time into a char array, then use atoi to parse out the data items you need from each line. Once this is working, combine it with your original sketch.

OK bare with me, I am very new and just trying to get the jist of it to be able to modify this sketch, is there a tutorial in the playgrpound to help me along, and are there any "libraries" I need to install before hand? might take a few weeks to get this done, but I will try to what I can.

No additional libraries required - just take a look at the documentation for the SD library. See if you can read the file line by line and serial print it. Once you're there, parsing it will not be too much more work.