Serial connection + working with strings

edited November 2014 in Arduino

I want to get 5 numbers from Arduino at the moment, the Arduino program looks like this

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

void loop() { Serial.println ("45 56 56 65"); }

This is my Processing programm, and it doesn't work for some reason

import processing.serial.*;

int data [];

Serial myPort; String val;

void setup () { size (400,400);

String portName = Serial.list()[0]; myPort = new Serial (this, portName, 9600); myPort.bufferUntil('\n'); }

void draw () {

}

void serialEvent (Serial myPort) { val = myPort.readStringUntil('\n'); val = val.substring(0, val.indexOf("\n"));
data = int(split(val, ' ')); }

Thank you for your help, Alex

Answers

  • Answer ✓

    found the issue

  • The idea in this forum is to share solutions as well as problems... :-)
    It can help somebody else searching for a solution.

    Sometime, the solution to this problem is to trim() the received string.

Sign In or Register to comment.