Sending CSV file to Arduino

Hello All,
I am currently working on a csv file and want to send the file to arduino..

Below is the python script:

import os
import time
import serial
ser = serial.Serial('/dev/cu.usbmodem1421',9600)
os.getcwd()

file = open("PCAArduinoTest.csv")

while 1:
  line = file.readline()
  decoded_bytes = bool(line[0:len(line)-2])
  print(decoded_bytes)
  if not decoded_bytes:
      break
  ser.write(decoded_bytes)
  time.sleep(3)
  file.close

Arduino side

byte eigenvector1=0,eigenvector2=0,eigenvector3=0;
bool eigencompute=false;
bool led_state=true, comp1=false , comp2=false;

char csvstring[256];

int index=0;

void setup(){
Serial.begin(9600);
memset($csvstring,0,sizeof(csvstring));
}

void loop(){
seialData();
clearCube();
}

serialData(){
while (Serial.available()) {
  char ch = Serial.read(); 

  
  if (isDigit(ch)) {
    csvstring[index++] = ch;

    
  } else if (ch == ',') {
    csvstring[index++] = NULL;                   
    eigenvector1 = atoi(csvstring);                     
    comp1 = true;                              
    index = 0;                                      
    memset(csvstring, 0, sizeof(csvstring));

// Else if ch is a new line; then rename as y_new
  } else if (ch == ',') {
    csvstring[index++] = NULL;
    eigenvector2 = atoi(csvstring);
    comp2 = true;
    index = 0;
    memset(csvstring, 0, sizeof(csvstring));
  }
  
  
  eigencompute = comp1 && comp2;
}
}

Please tell me if I am going on the right track..I am unable to see the desired o/p as I want the csv to be seen in the Arduino serial window..

Best Regards..
S..

Please tell me if I am going on the right track.

I don't think so. If I remember correctly, python uses indenting as the sole means of determining what makes a block of code.

After reading one line from the file, and sending it, you close the file. That does not pass the sniff test.

You COULD have tried compiling the Arduino code, even if you don't have an Arduino to run it on, and seen at least one error.

Yes, I have compiled the Arduino code (there were minor syntax code issues)..

But even if I close the port in python I should atleast see some data (atleast 1 byte) in order to put the entire csv to be sent?

On the PC side, you create a Serial instance, but you never open the resulting port. So, nothing is going to go out from the PC.

On the Arduino side, there is not much point in incrementing index when adding the NULL terminator, since you immediately set index to 0;

Resetting the index to zero means, it is like iterating the index for new line..

I have attached the CSV file for your perusal.

Resetting the index to zero means, it is like iterating the index for new line..

I know what resetting the index means. Incrementing it before you set it to 0 is what doesn't make sense.

I have attached the CSV file for your perusal.

To the men's room wall?

Why would we need to see the CSV file, when both your Python code and your Arduino code have flaws that you don't seem to have fixed? Or, if you have, you haven't posted the new(er) versions.

// Else if ch is a new line; then rename as y_new
   } else if (ch == ',') {

That's not a newline.

Google 'LALR(1) parser'.

If the data is comma-separated integers delimited by end-of-line characters with no spaces, the code is something like

int vec[100]; // space for 100 integers
int numbers = 0; // the number of numbers we have read so far

loop() {
  if(there's another character available) {
    char c = read the character();

    if(ch is a comma) {
      numbers ++;
      vec[numbers] = 0;
    }

    else if(ch is an end-of-line) {
      numbers ++;

      do_something_with_this_row_of_data();
    
      // reset the row
      numbers = 0;
      vec[0] = 0;
    }

    else if(ch is a digit) {
      vec[numbers] = vec[numbers] * 10 + (ch - '0');
    }
  }
}

void do_something_with_this_row_of_data() {
  for(int i = 0; i<numbers; i++) {
    if(i!=0) Serial.print(',');
    Serial.print(vec[i]);
  }
  Serial.println();
}

These links may be of interest
Python - Arduino demo

Serial Input Basics - simple reliable ways to receive data. There is also a parse example that works with CSV data.

...R