- Haul the wheelchair to the test site. Unlike other projects, I can't test it in my living room
- Hookup the Arduino, breadboard and wires.
- Run and videotape the test.
- Disassemble the chair, return home
- Find, fix, and facepalm for typing if (a=b) instead of if (a==b)
- Repeat
In other words, I have to fake the sensor inputs. This will take a few steps, and more than one post.
Building the Fake Date File (in CSV)
For my project I have 4 sensors planned at the moment and if things go well I may have 5 or 6. Each line in the CSV file will be in this format (the final comma is important):
timestamp, brakeSensor, reverseSensor, leftSignal, rightSignal,
The Arduino Code to generate the CSV file from real sensor input is below:
//Global variables
const int NUMCOL = 5; //How many columns in your CSV file
const char SEP = ','; //Comma is the separator character
long int sensor[NUMCOL]; //long int because the timestamp could get long quickly
const int DELAY_TIME = 10; //How long between sensor readings
//Input pins
const int TS = 0; //time stamp, not really a pin, but...
const int brake = A1; //Arduino Analog Pin 1
const int BRAKE = 1; //Column 1 in the array
const int reverse = A2;
const int REVERSE = 2;
const int left = A3;
const int LEFT = 3;
const int right = A4;
const int RIGHT = 4;
void setup() {
Serial.begin(9600); //Begin a serial connection
}
void loop () {
//Since it's so fast, all readings can all share a single time stamp
sensor[TS] = millis(); //get timestamp
sensor[BRAKE] = analogRead(brake);
sensor[REVERSE] = analogRead(reverse);
sensor[LEFT] = analogRead(left);
sensor[RIGHT] = analogRead(right);
//Print to serial monitor
for (int i = 0; i < NUMCOL; i++) {
Serial.print(sensor[i]);
Serial.print(SEP);
}
//Output the \n character to make the CSV easier to read
Serial.print('\n');
delay(DELAY_TIME);
} // end loop
To get the data to a CSV file, simply open up the Serial Monitor, and copy and paste to Notepad. To make the next steps easier, you will need to do the following:- At the very top, include or or two lines of "dummy data". When reading the file, this will give the serial port time to connect on both ends without risk of missing real data. I used two rows of all zeroes.
- Indicate the end of the file with an '@' character. I actually used @,@,@,@,@ but only one should be needed.
In the next post I will include the code needed to send the sensor data to the Arduino to allow you to "fake it" with your sensors.
Making a Better Wheelchair is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
No comments:
Post a Comment