Pages: [1]   Go Down
Author Topic: Reading data from a text file on my computer  (Read 1368 times)
0 Members and 1 Guest are viewing this topic.
SK-CA
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working on troubleshooting the handling of sensor data on my project. Since connecting and disconnecting everything to correct my errors in logic, then try again, is a royal pain with this project (can't be done in my office), I've hooked up the sensors and outputted a bunch of data to a CSV file (copied and pasted from the Serial Monitor).

The CSV file looks like this:

0,695,730,774
1,695,724,776
2,692,724,774
3,692,720,774
4,687,720,772
5,687,710,772
....
64321,702 ,610,790

Column 1 is a time stamp (from a millis() call) and the other columns are the raw readings from 3 different sensors.

The data I receive from the sensors in a real scenario will be fairly consistent, but getting them to interact together properly and cause the "other stuff" will require a fair bit of fiddling, testing, cursing, and trying new stuff. I already have a good sense of what I need to do, but I know there will be a bunch of fiddling.

Is there a way to EASILY (I'm a noob) read this CSV file and stick the values into 4 (long) int variables

For example, at the end of the reading, this would be the values of each variable
long int currentTime = 64321
int currentSensor1 = 702
int currentSensor2 = 610
int currentSensor3 = 790

If I can get that, I can probably get started on the rest. I do not need to keep the entire history in the Arduino Uno - the current readings will be put into element 0 of a 20 element array like this which is about all the history I need:

Code:
for (int i = 19 ; i >=0 ; i--) {
   timeHistory[i] = timeHistory[i-1];
   sensor1History[i] = sensor1History[i-1]
   //....
}

timeHistory[0] = currentTime;
/....



It would be quite nice if it can be done in close to "real time". Sensor 1 will force an LED to blink whenever it gets over 740 during my testing (it's measuring the speed of a wheel) so I will be using that to get a visual sense of how the others are working.

Thanks.
« Last Edit: October 16, 2012, 01:09:12 am by Geldhart » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there a way to EASILY (I'm a noob) read this CSV file and stick the values into 4 (long) int variables
Read it where? On the Arduino or on the PC?

Code:
for (int i = 19 ; i >=0 ; i--) {
   timeHistory[i] = timeHistory[i-1];
   sensor1History[i] = sensor1History[i-1]
   //....
}
Tell me exactly what happens when i is 0 on the last pass through this loop.

Quote
It would be quite nice if it can be done in close to "real time".
You want to read historical data "real time"? How does that make sense?

Taking action at intervals, as determined by the difference between two timestamps is a different story.

Logged

SK-CA
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there a way to EASILY (I'm a noob) read this CSV file and stick the values into 4 (long) int variables
Read it where? On the Arduino or on the PC?

CSV is stored on the PC, I want to read it on the Ardunio.

Quote
Code:
for (int i = 19 ; i >=0 ; i--) {
   timeHistory[i] = timeHistory[i-1];
   sensor1History[i] = sensor1History[i-1]
   //....
}
Tell me exactly what happens when i is 0 on the last pass through this loop.

Oops, it should be i > 0. The (0) indices are filled in after the for loop.

Quote
Quote
It would be quite nice if it can be done in close to "real time".
You want to read historical data "real time"? How does that make sense?

Taking action at intervals, as determined by the difference between two timestamps is a different story.

Okay, I'll try this again. I am taking action in intervals based on the differences in timestamps and values in the sensor readings. What I would like to do is SIMULATE getting the data in real time if that makes sense.

The sample data in the CSV file was obtained from the Arduino and the sensors with about 1 reading every ms, but that was from a sketch that ONLY read the sensors and sent the comma delimited output to the Serial port. It didn't do anything else. Realistically, 1 reading every 10  - 30 ms would be fine once I put all the pieces together, the smaller the better obviously.

If I was to type in the historical data manually at the Serial Monitor the system would be getting about 1 reading for all 3 sensors per 1000 ms (if I type fast). I would not be able to judge if the system is working properly at that rate, since part of my code testing and fiddling is seeing how "instant" the response to the change in sensor readings is.

For example, 5 seconds into the CSV test file, the wheel was manually stopped for 3 seconds. So what I would like to see is 5 seconds after I start the sketch using the CSV file is for my light on Pin 13 to turn on for 3 seconds, then turn off.

Does that help?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
CSV is stored on the PC, I want to read it on the Ardunio.
You can't. No more than you can, with your PC, read files on my PC.

You could have an application on the PC read the file, and send the contents, one character at a time, to the serial port that the Arduino is on the other end of.
Logged

SK-CA
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is what I am trying to do. How do I get the PC to send the file to the Arduino over the USB port.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49083
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How do I get the PC to send the file to the Arduino over the USB port.
http://arduino.cc/playground/Main/InterfacingWithSoftware
Find you favorite language and have at it.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are a Windows user, try Gobetwino - http://mikmo.dk/gobetwino.html.
Logged

Pages: [1]   Go Up
Jump to: