Reading and Parsing CSV file

I often get mobile contacts in a CSV file and I need to send SMS to them. I’m intending to save some time on this repetitive task. I decided to try a solution combining Arduino and SIM900 (GPRS Shield) there are quite few projects and tutorials available over the internet regarding this matter (AT comands, wiring, etc…)

It would be great if I could generate an arrayList or any other data structure containing just two parameters of the CSV file : Contact Name and Contact Number.

But first i need to read the file, get what i need and format what is not in the desired pattern(This applies to contact number only).

I started researching for some solution to this and I found this interesting:

Processing with Arduino

Reading Files from SD Card

So if you compare both solutions you can see that the first link reads a file from your PC but uses a Processing environment (I tried that code changing the file path and couldnt see anything, no results.) The second solution is less dinamic than the first one and read the file within a SD Card.

Is it possible to read the file from the PC without using Processing? What about the ArrayList structure do you know any similar lib for arduino as an alternative for this one presented for Processing?

EDIT – Attached an example of the csv file with really few contacs, in a real situation this would be huge, note that as default it comes with some “headers” which are the column names

contacts.txt (1.25 KB)

I often get mobile contacts in a CSV file and I need to send SMS to them

you could have a SD card reader on your arduino
write a small program parsing the file to extract the relevant fields
do what you need to do with that info...

but seems like SMS harassment to me...

J-M-L:
you could have a SD card reader on your arduino
write a small program parsing the file to extract the relevant fields
do what you need to do with that info...

but seems like SMS harassment to me...

I've made more research and figured out that arduino can't read files from PC, then we have two options : Use the SD approach as you mentioned (Which I will consider) and use Processing to read the file and send the data through serial, Do you know a good tutorial to follow this approach?

Really? A PC program can't read a file and send the contents to a serial port? Since what time?

aarg:
Really? A PC program can't read a file and send the contents to a serial port? Since what time?

@aarg - read again that’s not what OP said

He meant the Arduino does not have direct access to the PC file system hence two options

1/ Use an SD card and parse on Arduino

2/ Write a parser on the PC and send the relevant infos to the Arduino using some communication layer (USB, WiFi, Ethernet, Bluetooth ,...)

@rezik - can you describe the use case? I’m not interested at helping out on a SMS spamming project.

many terminal emulators enable a file to be opened, read and transmitted to a COM: port
e.g. TeraTerm's File > Send file command

J-M-L:
@rezik - can you describe the use case? I’m not interested at helping out on a SMS spamming project.

Yes sure... I have a base of customers which I need to SMS, the matter of the message will vary but I will mostly use it for payment reminder, offerts...My interest on this approach is due its cost (i do not know how this will operate considering big scales) At the moment I am using a SMS Service, so I pay a Pack of SMS credits. With a solution like this I could just get a Sim Card and a mobile line that will provide me unlimited SMS credits. So basically the goal of this solution is to achieve what I have with the SMS Service but with lower cost.

I figured this idea as two parts and the "Part I" is what I consider a bit "tricky". Part I is Read the csv File, extract two parameters in a desired Format. Part II will be a lot easier.

Regards,

Rezik

how to you receive the CSV files? if it is on a PC why not write a program on a PC in C++, C#, Java, Python, etc to process the CSV file and extract the information you require. You would then have ArrayList type functionality in the language.

for example, using Java String.split and looking for none empty strings

// split string on ; and look for fields
public class StringSplit2 { 
  public static void main(String[] args) { 
    String data[]={"Andrew;A1;;Soluções;;;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Disp. móvel;8006009510;;;;;;;;;;;;;;;;;;;;;;;",
                   "Adelson;Adelson;;;;Adelson;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Disp. móvel;027 99978-1045;;;;;;;;;;;;;;;Aluguel da Casa;;;;;;;;",
                   "Admilson;Admilson;;;;;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Mobile;033 98888-1078;;;;;;;;;;;;;;;Paroquia;Bingo;;;;;;;"};
    for(int i=0;i<data.length;i++) {                      // iterate thru array of string
      System.out.println("\nsplitting " + data[i]);
      String array1[]= data[i].split(";");                // split string on ;
      System.out.println("number of array elements " + array1.length);
      for(int j=0;j<array1.length;j++)                    // display the fields
        if(array1[j].length() > 0)                        // if not empty
          System.out.println("field " + j + " string '" + array1[j] + "'");
    }
  }
}

gives

splitting Andrew;A1;;Soluções;;;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Disp. móvel;8006009510;;;;;;;;;;;;;;;;;;;;;;;
number of array elements 35
field 0 string 'Andrew'
field 1 string 'A1'
field 3 string 'Soluções'
field 28 string '* myContacts'
field 33 string 'Disp. móvel'
field 34 string '8006009510'

splitting Adelson;Adelson;;;;Adelson;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Disp. móvel;027 99978-1045;;;;;;;;;;;;;;;Aluguel da Casa;;;;;;;;
number of array elements 50
field 0 string 'Adelson'
field 1 string 'Adelson'
field 5 string 'Adelson'
field 28 string '* myContacts'
field 33 string 'Disp. móvel'
field 34 string '027 99978-1045'
field 49 string 'Aluguel da Casa'

splitting Admilson;Admilson;;;;;;;;;;;;;;;;;;;;;;;;;;;* myContacts;;;;;Mobile;033 98888-1078;;;;;;;;;;;;;;;Paroquia;Bingo;;;;;;;
number of array elements 51
field 0 string 'Admilson'
field 1 string 'Admilson'
field 28 string '* myContacts'
field 33 string 'Mobile'
field 34 string '033 98888-1078'
field 49 string 'Paroquia'
field 50 string 'Bingo'