I was hoping to get some guidance on a project that involves serial printing of several analog values. I want those data values to be printed into columns side by side.
I am new to this so my code could the entirely wrong approach. The only information I have found is to use the "\t" to get the next value to go over in the next column.
here is the code I have so far.
int fsrPin0 = 0;
int fsrReading0;
int fsrPin1 = 1;
int fsrReading1;
int fsrPin2 = 2;
int fsrReading2;
int fsrPin3 = 3;
int fsrReading3;
int fsrPin4 = 4;
int fsrReading4;
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
fsrReading0 = analogRead(fsrPin0);
Serial.print("fsrReading0= ");
Serial.println(fsrReading0);
delay(500);
fsrReading1 = analogRead(fsrPin1);
Serial.print("fsrReading1 = ");
Serial.println(fsrReading1);
delay(500);
fsrReading2 = analogRead(fsrPin2);
Serial.print("fsrReading2 = ");
Serial.println(fsrReading2);
delay(500);
fsrReading3 = analogRead(fsrPin3);
Serial.print("fsrReading3 = ");
Serial.println(fsrReading3);
delay(500);
fsrReading4 = analogRead(fsrPin4);
Serial.print("fsrReading4 = ");
Serial.println(fsrReading4);
delay(500);
}
hey guys as it turns out I was using the serial.println and serial.print commands incorrectly and thats why my data was jumbled up. Here is the corrected code for keeping multiple sensors in their own columns (For export to matlab, excel etc).
This is a small excerpt. notice the println statement doesn't come in until the last sensor.
Jaunty: I'm using this approach for solving the proposed task, all my data is time-stamped by a DS1307 RTC who is already hooked in to the circuit, we use semicolons";" for separating the data columns:
#define semicolon ';' // Semicolon ';'
#define colons ':' // Colon ':'
#define slash '/' // Slash '/'
print2digits(tm.Day);
//
Serial.write(slash);
Serial.print(tm.Month);
//
Serial.write(slash);
//Serial.print(tmYearToCalendar(tm.Year)); // Prints full 4-digit year
Serial.print((tmYearToCalendar(tm.Year) - 2000)); // Prints only last 2-digit year
//
Serial.print(semicolon);
print2digits(tm.Hour);
//
Serial.write(colons);
print2digits(tm.Minute);
// If you want seconds logged also, uncomment this block
// Serial.write(colons);
// print2digits(tm.Second);
//
Serial.print(semicolon);
Serial.print((float)DHT11.temperature, 1);
//
Serial.print(semicolon);
Serial.print((float)DHT11.humidity, 0);
//
Serial.print(semicolon);
Serial.print((float)Baro, 1);
//
Serial.print(semicolon);
Serial.print((float)dewPoint(DHT11.temperature, DHT11.humidity),1);
//
Serial.print(semicolon);
Serial.println((float)dewPointFast(DHT11.temperature, DHT11.humidity),1);