Go Down

Topic: printing multiple variables in columns in serial monitor (Read 2680 times) previous topic - next topic

cmazzoli

so i have my ardunio attached to my RPi and have a sketch running with a temp sensor that gives voltage, sensor value and degree c. what i want is to have those numbers in different columns.

i would like to remove Serial.print("Sensor value: "); Serial.print(", Volts: "); Serial.print(", degrees C: ");
so just the numbers appear, but when i remove them i get a crazy number.

I am still NOOB so please be nice! thanks!

here is the code


const int sensorPin = A0;
const float baselineTemp = 18.36;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Sensor Value, Volts, temperature");
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor value: ");
  Serial.print(sensorVal);
 
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);
 
  Serial.print(", degrees C: ");
  float temperature = (voltage - .5) * 100;
  Serial.println(temperature);
  delay(10000);
}

Delta_G

By getting some crazy number do you mean that the numbers you print get printed without any spaces being printed in between so it looks like one long number?

Why don't you just print spaces in between them?  Or better yet, use tabs so they'll line up in the monitor. 

Code: [Select]


Serial.print(temperature);
Serial.print("\t");
Serial.print(Humidity);
Serial.print("\t");
Serial.print(someOtherVariable)
Serial.println();
If at first you don't succeed, up - home - sudo - enter.

cmazzoli

ok i will do that next. i just want it to be as easy as possible for data logging purposes and still new at this.

if anyone has an easy method to do datalogging from arduino to RPi i am all ears to that too!

thanks for the input!

chris

MarkT

Use CSV format?  Simple to generate, highly portable.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

cmazzoli

yeah i think i got the csv figured out. found a good youtube video on how to set it up using grabserial command in python.

what program would be best to use that data with?


MarkT

yeah i think i got the csv figured out. found a good youtube video on how to set it up using grabserial command in python.

what program would be best to use that data with?
Its your data, you know what you want to do with it!

[although if you're using python clearly matplotlib and possibly pandas are libraries
that could be useful]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up