Serial.readString() acting very strange

edited April 2014 in Arduino

Hello everyone,

I have the following arduino code:

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

void loop(){
  Serial.println("hello");
  delay(50);  
}

and processing:

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

void setup() 
{
  size(200, 200);
  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  println(Serial.list()[9]);
  String portName = Serial.list()[9];
  myPort = new Serial(this, portName, 9600);
  myPort.clear();
}

void draw()
{
  while( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
    //println(val);
    int lf = 10;
    String v = null;
    v = myPort.readString();
    if(v != null){
      println(v);
    }
  }
}

I am expecting processing to be printing out "hello", but it ends up looking like this

> o
> 
> el
> o
> 
> ello
> ello
> 
> 
> ell
> 
> 
> el
> o
> 
> e
> lo
> 
> ello
> 
> 
> ell
> 
> 
> el
> o

Any ideas what is going on here?

Answers

Sign In or Register to comment.