Go Down

Topic: Comma separated value simple sender (Read 2651 times) previous topic - next topic

pasha_ram

Apr 16, 2018, 06:28 pm Last Edit: Apr 16, 2018, 06:30 pm by pasha_ram
Hello World!

Trying to understand serial data exchange. Tried to search, honestly, but too much topics containing keywords such csv, send and serial.

I want to send CSV data from one arduino board to another. The second (reciever) board operates ok with CSV data sent by Serial from my PC (just simple 0-255, 0-255 values entered from serial monitor). But i'm too weak in programming and do not realizing how to send separated values from the first (sender) board properly using the Serial.println() command

Here is a code of my simple sender
Code: [Select]

void setup() {
    Serial.begin(9600);
}

void loop() {

  int sensorValue = analogRead(A0);

  int ledvalue = sensorValue * (255.0 / 1023.0);
 
  Serial.println(ledvalue);
}


I need to send ledvalue and ledvalue separated by comma in one line. In this case from just one sensor, but I suspecting that sending 2 sensors such way will not complicate much the code.

PaulS

Quote
I need to send ledvalue and ledvalue separated by comma in one line.
What do you mean by "in one line"? Do you know what Serial.print() does vs. Serial.println()?

Code: [Select]
Serial.print(firstValue);
Serial.print(",");
Serial.println(secondValue);

The result is two comma-separated values followed by a carriage return and line feed.

Robin2

Have a look at the 3rd example in Serial Input Basics

You can send data in a compatible format with code like this
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

pasha_ram

The result is two comma-separated values followed by a carriage return and line feed.
Thank you, Paul(we are namesakes). This helps me to understand print and println difference.

Have a look at the 3rd example in Serial Input Basics

You can send data in a compatible format with code like this
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


...R

Thanks a lot, Robin, I'll also try it.


pasha_ram

Have a look at the 3rd example in Serial Input Basics

You can send data in a compatible format with code like this
Code: [Select]
Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker


...R

This saves the day, everything works like a charm

Go Up