michalmonday / CSV-Parser-for-Arduino

It turns CSV string into an associative array (like dict in python)
MIT License
58 stars 12 forks source link

'Namespace' object has no attribute 'csv', reading_from_computer_python #25

Open nenp93 opened 10 months ago

nenp93 commented 10 months ago

Hello, I'm completely new to arduino and python. I need to give my arduino due coordinates from a csv file, which a programs creates on my pc. The arduino is used to controll a robot arm. I'm trying to dive in arduino an python programming and tried to run the example ,,reading_from_computer_python''. I copied the sketch for arduino and uploaded it successfully. When I try to run python --csv hurricanes-csv in the command window on my pc, the following error occures: line 42, in with open(args.csv .name, 'rb') as f: ^^^^^^^^ AttributeError: 'Namespace' object has no attribute 'csv'. Did you mean: 'csv '?

What am I doing wrong?

michalmonday commented 10 months ago

Hello, It looks like in your example there's a space between args.csv and .name. I think removing that space should fix the error, but let me me know if that's not the case.

It doesn't look like that space is in the original file: image

nenp93 commented 10 months ago

Hello, thanks for the fast respond. To my shame it was the space. I don't know how it went there. The next error is: line 74, in s.port = COM3 ^^^^ NameError: name 'COM3' is not defined

My arduino is connected with COM 3. Could you please help me again?

with best regards

michalmonday commented 10 months ago

In Python strings need to be enclosed in single or double quote characters like:

s.port = "COM3"

Otherwise the program would think that "COM3" is a variable. Btw if you take a look at the arduino_serial.py example, it automatically finds a port with "arduino" in its name, if multiple ports like that are found then it lets the user to select which one to use.

nenp93 commented 10 months ago

Allright it worked. But the next issue is right around the corner. Independant which USB port from my Arduino Due I am using, the command window doesn't receive or doesn't print the data. After I run the command, it looks like on the screenshot and I can only close the window. I can't type anything. Screenshot 2023-12-20 164404

michalmonday commented 10 months ago

Is Arduino Due running the reading_from_computer_python.ino example?

nenp93 commented 10 months ago

yes

michalmonday commented 10 months ago

It looks like the reading_from_computer_python.ino example has a bug that only happens when clock of the board is too fast.

A quick workaround would be to replace this line:

cp << Serial.read();

with this line:

cp << Serial.readString();

I'm going to fix it properly in the future

nenp93 commented 10 months ago

unfortunately the quick workaround does'nt solve the problem. I will keep on trying.

michalmonday commented 10 months ago

I modified the reading_from_computer_python.ino example and added the new one reading_from_computer_python_row_by_row which should use much less memory.