# Giving wrong value while reading data from serial port

**URL:** <https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 16, 2019, 12:23pm UTC](https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447 "2019-12-16T12:23:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamgsshetty](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@iamgsshetty](https://discourse.processing.org/u/iamgsshetty)\
**Post date:** [December 16, 2019, 12:23pm UTC](https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447/1 "2019-12-16T12:23:10Z")

</div>

processing code:-

```auto
import processing.serial.*;
Serial myport;

float v1,v2,a,cda=0.0,how=0.0,water=0.0;
void setup()
{
  myport = new Serial(this, Serial.list()[0], 9600);
}

void draw()
{
  if(0<myport.available())
  {
    cda=myport.read();
    how=myport.read();
    water=myport.read();
     println(cda);
     println(how);
     println(water);
  }
  
}

```

Output:-

> 49.0  
> 57.0  
> 46.0  
> 48.0  
> 53.0  
> 13.0  
> 10.0  
> 55.0  
> 50.0  
> 46.0  
> 56.0  
> 50.0  
> 13.0  
> 10.0  
> -1.0  
> 49.0  
> 57.0  
> 46.0  
> 48.0  
> 53.0  
> 13.0  
> 10.0  
> 55.0  
> 50.0  
> 46.0  
> 56.0  
> 50.0  
> 13.0  
> 10.0  
> -1.0  
> 49.0  
> 57.0  
> 46.0  
> 48.0  
> 53.0  
> 13.0  
> 10.0  
> 55.0  
> 50.0  
> 46.0  
> 56.0  
> 50.0  
> 13.0  
> 10.0  
> -1.0  
> .  
> .  
> .

Serial port output:-

> 19.08  
> 72.85  
> 19.08  
> 72.85  
> 19.08  
> 72.85  
> 19.08  
> 72.85  
> 19.08  
> 72.85  
> 19.08  
> 72.85  
> 19.08  
> 72.85  
> .  
> .  
> .

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 16, 2019, 1:06pm UTC](https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447/2 "2019-12-16T13:06:47Z")

</div>

•Please format your code

The output is perfectly fine and exactly what your Code should do. You might want to take a look at the Serial read() function.

Then you can see that read() gives back an int between 0 and 255 representing the byte being sent over. You are sending 19.08CRLN72.85CRLN, and what you get is 4957464853131055504656501310-1 where :

```auto
'1' = 49;
'9' = 57;
'.' = 46;
'0' = 48;
'5' = 53; //apparently it‘s 19.05, not 19.08
Carriage Return = 13;
Line Feed = 10;

'7' = 55;
'2' = 50;
'.' = 46;
'8' = 56;
'2' = 50; //apparently it’s 72.82
CR = 13;
LF = 10;

```

---

<div class="post-metadata">

**Author:** ![iamgsshetty](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@iamgsshetty](https://discourse.processing.org/u/iamgsshetty)\
**Post date:** [December 16, 2019, 1:12pm UTC](https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447/3 "2019-12-16T13:12:33Z")

</div>

so what should I write instead of serial.read() to get the input right?

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 16, 2019, 1:14pm UTC](https://discourse.processing.org/t/giving-wrong-value-while-reading-data-from-serial-port/16447/4 "2019-12-16T13:14:48Z")

</div>

You should use readStringUntil(10); , to read the String until it reaches the LineFeed (or maybe CR, but that‘s up to you).

Then just use float(String) to convert it to float.
