<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with readstring() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=readstring%28%29</link>
      <pubDate>Sun, 08 Aug 2021 18:39:28 +0000</pubDate>
         <description>Tagged with readstring() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedreadstring%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>no Graph with data from Arduino?</title>
      <link>https://forum.processing.org/two/discussion/14060/no-graph-with-data-from-arduino</link>
      <pubDate>Fri, 18 Dec 2015 12:30:24 +0000</pubDate>
      <dc:creator>hb9bqb</dc:creator>
      <guid isPermaLink="false">14060@/two/discussions</guid>
      <description><![CDATA[<p>tried a simple example to draw a Graph from arduino data. No graph visible? Running on Windows 10</p>

<p>import processing.serial.*;</p>

<p>Serial myPort;        // The serial port
 int xPos = 0;         // horizontal position of the graph</p>

<p>void setup () {
 // set the window size:
 size(400, 600);</p>

<p>// List all the available serial ports
 println(Serial.list());</p>

<p>// open Serial.list()[0].
 // Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[1], 9600);
// myPort = new Serial(this, "COM8", 9600);</p>

<p>// don't generate a serialEvent() unless you get a newline character:
 myPort.bufferUntil('\n');
 // set inital background:
 //background(0);  schwarzer Hintergrund
 background (100,100,255);
 }
 void draw () {
 // everything happens in the serialEvent()
 }</p>

<p>void serialEvent (Serial myPort) {
 // get the ASCII string:
 String inString = myPort.readStringUntil('\n');</p>

<p>if (inString != null) {
 // trim off any whitespace:
 inString = trim(inString);
 // convert to an int and map to the screen height:
 float inByte = float(inString);</p>

<p>inByte = map(inByte, 0, 1023, 0, height);
println(inString);  // to see if datas are incoming</p>

<p>// draw the line:
 stroke(0,0,0);
 line(xPos, height, xPos, height - inByte);</p>

<p>// at the edge of the screen, go back to the beginning:
 if (xPos &gt;= width) {
 xPos = 0;
 background(0); 
//background (216,225,165);
 } 
 else {
 // increment the horizontal position:
 xPos++;
 }
 }
 }</p>
]]></description>
   </item>
   <item>
      <title>String Headache</title>
      <link>https://forum.processing.org/two/discussion/23253/string-headache</link>
      <pubDate>Thu, 29 Jun 2017 07:16:53 +0000</pubDate>
      <dc:creator>YORKIE</dc:creator>
      <guid isPermaLink="false">23253@/two/discussions</guid>
      <description><![CDATA[<p>Hi Guys,
I have a string coming from a navigation PC, containing an easting and northing.
The string being sent looks exactly like this:</p>

<p><code>E238620.31 N2829868.73 FP 238620.31&lt;CR&gt;&lt;LF&gt;</code></p>

<p>Now the string works on another system ( a video overlay system), so I know its there, but I would like to work with it in Processing, and I can't for the life of me see it. I just keep getting "null"</p>

<p>Something tells be it could have something to do with the CR and LF
I cant change the string at all that is what it is.</p>

<p>Ive been going down the route of &gt;&gt;&gt;&gt;&gt; String inBuffer = myPort.readString();</p>

<p>Any help would greatly be appreciated.</p>

<p>Cheers</p>

<p>Nik</p>
]]></description>
   </item>
   <item>
      <title>How can I split up serial data into multiple variables</title>
      <link>https://forum.processing.org/two/discussion/22033/how-can-i-split-up-serial-data-into-multiple-variables</link>
      <pubDate>Sun, 16 Apr 2017 13:57:43 +0000</pubDate>
      <dc:creator>EndlessOyster</dc:creator>
      <guid isPermaLink="false">22033@/two/discussions</guid>
      <description><![CDATA[<p>Im sending data from arduino to processing. I have six variables to send. Currently Im doing it through serial and Ive got processing to receive the data, currently it arrvies in processing as 6 lines of data. How can I set it up so I can have 6 variables in processing.</p>
]]></description>
   </item>
   <item>
      <title>How do i go about picking certain items from serial data</title>
      <link>https://forum.processing.org/two/discussion/16063/how-do-i-go-about-picking-certain-items-from-serial-data</link>
      <pubDate>Sun, 17 Apr 2016 16:39:17 +0000</pubDate>
      <dc:creator>philtkp</dc:creator>
      <guid isPermaLink="false">16063@/two/discussions</guid>
      <description><![CDATA[<p>Hi,
I using a LSM9DS1 9 Degrees of Freedom IMU Breakout from Sparkfun. I can read the data using Processing this is the data that is being sent from the Arduino.</p>

<pre><code>LSM9DS1 9-axis motion sensor...
LSM9DS1 accel/gyroI AM 68 I should be 68
LSM9DS1 magnetometerI AM 3D I should be 3D
LSM9DS1 is online...
accel sensitivity is 16.38 LSB/mg
gyro sensitivity is 0.13 LSB/mdps
mag sensitivity is 8.19 LSB/mGauss
Perform gyro and accel self test
 Calibrate gyro and accel
accel biases (mg)
-21.97
-71.11
-44.25
gyro biases (dps)
-0.87
1.33
-1.67
mag biases (mG)
18.07
9.64
-64.33
LSM9DS1 initialized for active data mode....
-2.52, 174.62, 146.33
</code></pre>

<p>I'm having problems just selecting the parts of data I would like to display and use.
like Display "LSM9DS1 9-axis motion sensor..." and "LSM9DS1 is online..." and "LSM9DS1 initialized for active data mode...."
then use the remaining data (X,Y,Z) to update my rotating cube. the cube response to the data if I only send the X,Y,Z but I get errors when sending all the data. is there a way I can do this?</p>

<p>This is the code I'm using at this time</p>

<pre><code>void serialEvent(Serial p) 
{
  String incoming = p.readString(); // reads all the data correctly
    println(incoming);



  if ((incoming.length() &gt; 8))
  {
    String[] list = split(incoming, " ");
    if ( (list.length &gt; 0) &amp;&amp; (list[0].equals("mode....")) ) 
    { 
      println("mode.... was found");

    }
  }
}
</code></pre>

<p>I'm having trouble understanding the proper way to go about this, any help would be greatly appreciated</p>
]]></description>
   </item>
   <item>
      <title>myPort.available always 0</title>
      <link>https://forum.processing.org/two/discussion/14534/myport-available-always-0</link>
      <pubDate>Tue, 19 Jan 2016 15:35:27 +0000</pubDate>
      <dc:creator>langrenne</dc:creator>
      <guid isPermaLink="false">14534@/two/discussions</guid>
      <description><![CDATA[<p>Hy,</p>

<p>I'm on Linux kubuntu.
I would like receive data from an arduino nano (3 axis motion for head tracking).
The arduino code works because I can read data with Pure Data (Pd).
The arduino is on port [32] (/dev/ttyUSB0)</p>

<p>I use the common code:</p>

<pre><code>// Example by Tom Igoe

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

void setup() {
  // List all the available serial ports
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[32], 9600);
  myPort.clear();
  // Throw out the first reading, in case we started reading 
  // in the middle of a string from the sender.
  myString = myPort.readStringUntil(lf);  
  myString = null;
}

void draw() {
  println(myPort.available());

  while (myPort.available() &gt; 0) {
    myString = myPort.readStringUntil(lf);
    if (myString != null) {
      println(myString);
    }
  }
}
</code></pre>

<p>But myPort.available is always 0. I can't read anything.</p>

<p>Can someone help me ?</p>

<p>thanks</p>
]]></description>
   </item>
   <item>
      <title>Arduino and Processing</title>
      <link>https://forum.processing.org/two/discussion/15102/arduino-and-processing</link>
      <pubDate>Wed, 24 Feb 2016 23:14:15 +0000</pubDate>
      <dc:creator>iLegendX</dc:creator>
      <guid isPermaLink="false">15102@/two/discussions</guid>
      <description><![CDATA[<p>I have the arduino and ultrasonic HC-SR04. I want to help please us.
The arduino want to measure the distance and what gives the serial. Communicates with the processing and when the distance is greater than 150cm displays an image, if less playing video.
My problem is that I run the processing but the video plays either away or close.
Please help me. I beginner!!</p>

<p>Arduino is from a library NewPing
    // ---------------------------------------------------------------------------
    // Example NewPing library sketch that does a ping about 20 times per second.
    // ---------------------------------------------------------------------------</p>

<pre><code>#include &lt;NewPing.h&gt;

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  Serial.println("cm");
}
</code></pre>

<p>Processing</p>

<pre><code>// Video
import processing.video.*;
Movie movie;

// Image
PImage img;  // Declare variable "a" of type PImage

// Serial
import processing.serial.*;
Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port


void setup() {
  size(640, 360);
  background(0);

  printArray(Serial.list());
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 115200);

  // Load and play the video in a loop
  movie = new Movie(this, "transit.mov");
  movie.loop();
  img = loadImage("moonwalk.jpg");  // Load the image into the program
}

void movieEvent(Movie m) {
  m.read();
}

void draw() {
  if (movie.available() == true) {
    movie.read(); 
  }
  image(movie, 0, 0, width, height);

  if ( myPort.available() &gt; 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }  


  if (val&gt;130) {
    image(img, 0, 0);
  } else {
    image(movie, 0, 0, width, height);
  }
  println(val);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Does serial.bufferUntil work with any character?</title>
      <link>https://forum.processing.org/two/discussion/15177/does-serial-bufferuntil-work-with-any-character</link>
      <pubDate>Sun, 28 Feb 2016 18:42:44 +0000</pubDate>
      <dc:creator>RetiredProgrammer</dc:creator>
      <guid isPermaLink="false">15177@/two/discussions</guid>
      <description><![CDATA[<p>Every example I have seen uses either a newline or linefeed. Hoes it work with say *,#,% or ??</p>
]]></description>
   </item>
   <item>
      <title>Problem with save data from serial port</title>
      <link>https://forum.processing.org/two/discussion/14931/problem-with-save-data-from-serial-port</link>
      <pubDate>Mon, 15 Feb 2016 18:23:54 +0000</pubDate>
      <dc:creator>Pedro_Henrique</dc:creator>
      <guid isPermaLink="false">14931@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys I'm new with Processing development and I having some problems. here's the issue: I'm using an Arduino to measuere temperature and just wanna to send it to Processing by serial communication and store it in to a .txt file.
I have already searched a solution in Processing tutorials and in this forum, but didn't find yet.
Any help is welcome!!
Here is my code (the comments are in Portuguese):</p>

<pre>
//Ler os dados da porta serial e salvar num arquivo .txt

import processing.serial.*;
import cc.arduino.*;

Serial portaCOM5; //Cria um objeto da classe Serial
String dados, COM5; //Dados em ASCII recebidos do Arduino
int val ;// Dados recebidos pela porta serial

//Banco de dados
PrintWriter arquivo; 

void setup ()
{
  size (200, 200);
  frameRate(10);   
  
     
   println(Serial.list ()); //Lista no Prompt de Comando todas as portas seriais disponíveis
   
   COM5 = Serial.list()[0]; //Recebe a porta USB escolhida
   portaCOM5= new Serial(this, "COM5", 9600); //taxa de transfarencia 9600bps
   portaCOM5.bufferUntil('\n');
      
        //Banco de dados:
   arquivo = createWriter("temperaturas"+"_"+month()+"-"+day()+"-"+year()+"_"+hour()+"-"+minute()+"-"+
            second()+".txt"); //cria um arquivo para armazenar as temperaturas
    
    arquivo.print("Monitoramento de Temperatura DHT11");
    arquivo.println();    
  
}

void draw()
{
  background (255); //Ajusta cor de fundo como branca
  
  }
   
void serialEvent(Serial portaCOM5)
{
  
     COM5= Serial.list()[0]; //Recebe a porta USB escolhida
       
      
  while (portaCOM5.available()&gt;0)
  {
     val = portaCOM5.readString();
     arquivo.println();
  }
         
  arquivo.flush(); // Writes the remaining data to the file
  arquivo.close(); // Finishes the file
         
}

</pre>

<p>PS: When I check the monitor serial from Arduino, the data are there, so I believe anything here is wrong.</p>

<p>Thanks!!!!</p>
]]></description>
   </item>
   <item>
      <title>How to draw a complete color wheel?</title>
      <link>https://forum.processing.org/two/discussion/14032/how-to-draw-a-complete-color-wheel</link>
      <pubDate>Wed, 16 Dec 2015 22:27:03 +0000</pubDate>
      <dc:creator>Gears</dc:creator>
      <guid isPermaLink="false">14032@/two/discussions</guid>
      <description><![CDATA[<p>Hello people,</p>

<p>I'm trying to create a program that I can use to control the LED strips inside my PC using Arduino. I currently have communication and a lot of other parts working already, but I am stuck on a small problem.</p>

<p>I am able to draw a color wheel or rectangle in this case that <strong>should</strong> represent all colors available. The program looks at the value under the mouse while it is pressed, and sends this to the Arduino. The problem I am having is that the colors nearest to the edge are not picked up as pure red (255,0,0), green or blue. The closest value I can get is: (255,32,32).</p>

<p>What I have tried so far is changing the size of the rectangle to exclude the missing colors being rendered off-screen. I have found that the code reading the color value under the cursor is correct - I did this by drawing a plain pure red rectangle in the corner, which returned the correct value (255,0,0). I also found that simply subtracting 32 from the values is incorrect, as on pure white you will find the value to be (223,223,223).</p>

<p>This causes significant problems with my LEDs, as a value of 32 on the PWM pin will light the corresponding color up by quite a bit because of the non-linear relationship between LED volt and brightness.</p>

<p>So to reiterate my question: how do I draw a color circle or rectangle from which I can get 100% red, blue and green as well?</p>

<p>Here is my code:</p>

<pre><code>import processing.serial.*; 

Serial myPort;    // The serial port
String inString;  // Input string from serial port
int lf = 10;      // ASCII linefeed 
int[] rgb = new int[3];
PImage m;

void setup(){
  size(400,400);
  frameRate(120);
  smooth(4);
  ellipseMode(CENTER);
  background(255);

  colorMode(HSB, 400);
  for (int i = 0; i &lt; 400; i++) {
    for (int j = 0; j &lt; 400; j++) {
      stroke(i, j, 400);
      point(i, j);
    }
  }
  m=get();

  myPort = new Serial(this, Serial.list()[1], 9600); 
  myPort.bufferUntil(lf);
}

void draw(){
  image(m,0,0);
  if(mousePressed){
    color c = get(mouseX,mouseY);
    fill(c);
    stroke(0);
    ellipse(mouseX,mouseY,30,30);
    rgb[0] = c &gt;&gt; 16 &amp; 0xFF;
    rgb[1] = c &gt;&gt; 8 &amp; 0xFF;
    rgb[2] = c &amp; 0xFF;

    fill(0);
    text(rgb[0], 10,70);
    text(rgb[1], 10,90);
    text(rgb[2], 10,110);

    String test = ",";
    test += str(rgb[0]);
    test += "+";
    test += str(rgb[1]);
    test += "+";
    test += str(rgb[2]);
    test += "\n";

    myPort.write(test);
  }
  fill(0);
  text("Received: " + inString, 10,50);
}

void serialEvent(Serial p) { 
  inString = p.readString(); 
} 
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to verify the Serial.list()</title>
      <link>https://forum.processing.org/two/discussion/13849/how-to-verify-the-serial-list</link>
      <pubDate>Wed, 09 Dec 2015 00:36:46 +0000</pubDate>
      <dc:creator>salvatore_94</dc:creator>
      <guid isPermaLink="false">13849@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,
i'm trying to figure out how can i know what are the ports in the serial array.
I'm using this code:</p>

<pre><code>    while(i&lt;Serial.list().length&amp;&amp;!trovato){
              if((Serial.list()[i]=="COM1")||(Serial.list()[i]=="COM2")||(Serial.list()[i]=="COM3")||(Serial.list()[i]=="COM4")||(Serial.list()[i]=="COM5"))
</code></pre>

<p>The if condition is always false, but if i print the Serial.list() array i can see that i have a COM4 and the lenght is 1.
I need to use that because i don't know if arduino will be connected on another COM on an other PC.</p>

<p>The full if is</p>

<pre><code>        int i=0;
                while(i&lt;Serial.list().length&amp;&amp;!trovato){
                  if((Serial.list()[i]=="COM1")||(Serial.list()[i]=="COM2")||(Serial.list()[i]=="COM3")||(Serial.list()[i]=="COM4")||(Serial.list()[i]=="COM5")){
                    pos=i;
                    trovato=true;
                  }
                  else
                  i++;
                }
                if(trovato){
                  porta= new Serial(this, Serial.list()[pos], 9600);
                  porta_connessa=true;
                }
                else
                  porta_connessa=false;
</code></pre>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to pass large string between a server sketch and a client sketch?</title>
      <link>https://forum.processing.org/two/discussion/13764/how-to-pass-large-string-between-a-server-sketch-and-a-client-sketch</link>
      <pubDate>Thu, 03 Dec 2015 18:53:34 +0000</pubDate>
      <dc:creator>el_pablo</dc:creator>
      <guid isPermaLink="false">13764@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys,</p>

<p>I'm trying to send a large json from a client to a server. The JSON is a 64x64 matrix where each cell has a RGB color. So it is basically a string of 24000+ characters including the separators.</p>

<p>Everything works fine if I keep the string lenght under 8000 characters (8 bit color), but when trying to pass to large one I only get partial data.</p>

<p>Here's a code sample of my <strong>draw()</strong></p>

<pre><code>void draw () {

  client = server.available();

  if ( client != null) {

      data = client.readString();

      if (data != null) {

        println (data);
        //json = new JSONData(data);

        //if (json.command != null)
        //  commandMap.get(json.command).execute(); 

        data = null;
      }
    }
  }

  // Some code
}
</code></pre>

<p>Is there something wrong with it? I'm quite a newbie with the client-server concept.</p>

<p>Thanks</p>
]]></description>
   </item>
   <item>
      <title>My sketch reads one pixel from arduino, then gives me an ArrayIndexOutOfBoundsException</title>
      <link>https://forum.processing.org/two/discussion/13794/my-sketch-reads-one-pixel-from-arduino-then-gives-me-an-arrayindexoutofboundsexception</link>
      <pubDate>Sat, 05 Dec 2015 19:22:01 +0000</pubDate>
      <dc:creator>Dirruk</dc:creator>
      <guid isPermaLink="false">13794@/two/discussions</guid>
      <description><![CDATA[<p>Dear Forum,</p>

<p>I'm building a drawbot that draws bitmaps. I'm almost there -thanks to the good people here-, but I can't get my head around this issue here.</p>

<p>I have a Processing sketch that can parse coordinates from a string from my arduino, display the corresponding pixel on screen and send the brightness of that pixel back to the arduino. Then I have an arduino code that can move to the next pixel and send its location coordinates as a string.</p>

<p>This seems to work, but only for one pixel. Then processing sends me and ArrayIndexOutOfBoundsException. I guess I need to flush a string somewhere. But I don't know which one. The debuggerer somehow gets stuck on my sketch too. So some advice would be really helpful.</p>

<p>Here's the Processing sketch:</p>

<pre><code>    import processing.serial.*; //import the Serial library

    Serial myPort;  //the Serial port object
    String strIn = "";  //Declare a string with name strIn, this will store the coordinates received from the arduino
    String strOut = "";  //Declare a string with name strOut, this will store the coordinates and corrseponding geryvalue of a pixel in the bitmap.
    String portName = "";  //apparently this is necessary
    String coordinates;
    int locX= 0;
    int locY= 0;

    PImage img;

    void setup()
    {

      size(182, 262);  //This is the size of the canvas and the range of the printer //&lt;&gt;//
      // Make a new instance of a PImage by loading an image file
      img = loadImage("parel.bmp");
      tint(255, 100);
      image (img, 0, 0);
      String portName = Serial.list()[0];
      myPort = new Serial(this, portName, 9600);
    }


    void draw()
    { 
      if (myPort.available() &gt; 0)                     // If data is available,
      {
        strIn = myPort.readStringUntil('\n');         // read it and store it in a string called strIn
        String[] coordinates = split(strIn, ",");    
        //Cut the strIn string at the comma into two strings called coordinates. 
        //We expect a message coming in something like "XXX,YYY"
        int locX = int(trim(coordinates[0]));        //This says that the first string is an integer called LocX
        int locY = int(trim(coordinates[1]));       //This says that the next string is an integer called LocX
        color pix = img.get(locX, locY);             //look up the colour of the requested pixel
        stroke(pix);                                 //show the pixel on the canvas on screen
        point(locX, locY);
        int Bright = round(brightness(pix));        //sending pix will send a large negative string, so we will just send the brightness
        strOut = locX + "," + locY + "," + Bright + "L" + "\n";  //put all the needed values into a string called strOut
        myPort.write(strOut);                                    //send it over serial port to the arduino to parse
        }
    }
</code></pre>

<p>And here's the arduino sketch:</p>

<pre><code>// Jerry Wirerammer lives!

unsigned int xPos ;           //this integer sets the X position of the robot
unsigned int yPos   ;         //this integer sets the Y position of the robot
unsigned int xGoal  ;        //this integer sets the X location of the pixel where the mothership thinks the robot is. If the Robot is in position, it can put a dot.
unsigned int yGoal   ;       //this integer sets the X location of the pixel where the mothership thinks the robot is. If the Robot is in position, it can put a dot.
unsigned int GreyValue ;
char val;
int CanvasWidth = 182;
int CanvasHeight = 263;
String received ;

void setup() {

  Serial.begin(9600);                             //Serial communication, we are using it


  goHome();        //move to the 0,0 position.
}



void loop() {


  Serial.print(xPos);
  Serial.print(",");
  Serial.println(yPos);


  if ( Serial.available() ) // if data is available to read
  {
    val = Serial.read();    // read it and store it in 'val'
    if ( val != 'L' ) {     // if not an 'L'
      received += val;          // add it to the received string
    }

    else {
      // if 'L' was received (our designated termination char)
      //Look for the location of the first comma
      int commaIndex = received.indexOf(',');
      //  Search for the next comma just after the first
      int secondCommaIndex = received.indexOf(',', commaIndex + 1);

      String firstValue = received.substring(0, commaIndex);  //the first series of characters before the first comma
      String secondValue = received.substring(commaIndex + 1, secondCommaIndex); //the next series of characters between the first and second comma
      String thirdValue = received.substring(secondCommaIndex); //the final series of characters before the L that we didn't add to the "received" string

      xGoal = firstValue.toInt();
      yGoal = secondValue.toInt();
      GreyValue = thirdValue.toInt();

/*    debugging purposes only:
      Serial.print("received:");
      Serial.println(received);
      Serial.print("xGoal =");
      Serial.println(xGoal);
      Serial.print("yGoal =");
      Serial.println(yGoal);
      Serial.print("xPos =");
      Serial.println(xPos);
      Serial.print("yPos =");
      Serial.println(yPos);
*/

      received = "";                // Flush the string so we can receive new data
    }
  }
  else {
    delay (1000); // wait a bit and try again
  }


  if (xGoal == xPos) {
    if (yGoal == yPos) {
      MoveOn();
    }
  }
}


void MoveOn() //this subroutine tells the robot how to move to the next position.
{
  if (xPos != CanvasWidth) {   //if we are not at the end of the x axis
    xPos = xPos + 1;          //and adjust x position by increasing by one
  }
  else if (yPos != CanvasHeight) { //if we are not at the end of the y axis
    xPos = 0;           //and adjust x position to its starting value
    yPos = yPos + 1;                  //and adjust y position by increasing by one
  }
  else {
    delay(1);                       //Do nothing. This will make the robot print the last pixel over and over again.
  }
}




void goHome() //this subroutine tells the robot how to move to position 0,0
{
  while (xPos != 0) {         //if we are not x position 0
    xPos = xPos - 1;          //and adjust x position by increasing by one
    //this will repeat until we are at position x=0
  }

  while (yPos != 0) {         //if we are not x position 0
    yPos = yPos - 1;          //and adjust x position by increasing by one
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Problem reading a RFID reader</title>
      <link>https://forum.processing.org/two/discussion/12920/problem-reading-a-rfid-reader</link>
      <pubDate>Fri, 09 Oct 2015 23:43:31 +0000</pubDate>
      <dc:creator>elunicotomas</dc:creator>
      <guid isPermaLink="false">12920@/two/discussions</guid>
      <description><![CDATA[<p>Hi there,</p>

<p>I have this <strong>SparkFun RFID Starter Kit</strong> (<a rel="nofollow" href="https://www.sparkfun.com/products/13198?_ga=1.242738306.1686357739.1444361942">https://www.sparkfun.com/products/13198?_ga=1.242738306.1686357739.1444361942</a>), I followed the steps in the <strong>HookUp guide</strong> (<a rel="nofollow" href="https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide?_ga=1.177165093.1278763627.1444260091">https://learn.sparkfun.com/tutorials/sparkfun-rfid-starter-kit-hookup-guide?_ga=1.177165093.1278763627.1444260091</a>), and It seems that is working fine, although I'm not getting the same reads as the guide.</p>

<p>Example: 
The guide shows this screenshot of the Arduino serial port while reading the card:</p>

<p><img src="https://cdn.sparkfun.com/assets/learn_tutorials/2/2/8/scanned_card.png" alt="" /></p>

<p>And I get this value:</p>

<p><img src="http://i.imgur.com/gOXIgET.png" alt="" /></p>

<p>If I swipe the card another time, I get this reading:</p>

<p><img src="http://i.imgur.com/ceUHcxq.png" alt="" /></p>

<p>What are those little squares? I guess is some kind of character but I don't know which, or why is there.</p>

<p>Any ideas?</p>

<p>I am also trying this RFID reader in Processing. To change a message in the screen if someone swipes the card.</p>

<p>Initial screen:</p>

<p><img src="http://i.imgur.com/z7jKar7.png" alt="" /></p>

<p>After one read:</p>

<p><img src="http://i.imgur.com/7sM4HTt.png" alt="" /></p>

<p>The text "saldo en 0" should have changed to "deposito $50"", but it shouldn't.</p>

<p>Any ideas?</p>

<p>Thanks!!</p>

<p>The code:</p>

<pre><code>import processing.serial.*;
Serial myPort;
String inString = "texto inicial";
String mensaje;

void setup () {
  size(400, 300);        
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  background(0);
}
void draw () {
  background(0);
  String s = inString;
  String comparador = "4500B8C02A17";
  textSize(24);
  fill(100);
  text(s, height/3, width/3); 

  if (comparador.equals(s) == true) {
    mensaje = "deposito $50";
  } else {
    mensaje = "saldo en 0";
  }
  text(mensaje, height/3, width/3+30);
}

void serialEvent (Serial myPort) {
  inString = myPort.readStringUntil('\n');
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to have data in a file without having the buffer full</title>
      <link>https://forum.processing.org/two/discussion/12646/how-to-have-data-in-a-file-without-having-the-buffer-full</link>
      <pubDate>Tue, 22 Sep 2015 21:26:18 +0000</pubDate>
      <dc:creator>AndreaRojasM</dc:creator>
      <guid isPermaLink="false">12646@/two/discussions</guid>
      <description><![CDATA[<p>I have this code, it works almost fine, it read the data at the serial and saves it in a .txt file, i run the program during 16 seconds and all i got is a 8 seconds of data, i'm quite sure there's a delay of 8 seconds (kind of) later i let the program run for 24 seconds and i get 16 seconds of data (quite sure i got a delay of 8) now i'm letting the 8 seconds, and i start to trying to obtain the data from second 8 til 15 for example and i didn't get data cuz it seemed to me that the buffer isn't full, i would like to have data without having to wait for the buffer to be completely full.</p>

<p>Any idea?
Also, any idea if it's possible for me to no wait the fisrt 8 seconds.</p>

<p>Thanks</p>

<pre><code>                import processing.serial.*;
                PrintWriter output;

                Serial myPort;  // The serial port

                void setup() {

                  output = createWriter("andyPiezoBuzzerADXL335.txt");
                  // Open whatever port is the one you're using.
                  myPort = new Serial(this, "COM4", 9600);
                }

                void draw()
                {
                  while (myPort.available () &gt; 0) {
                    String inBuffer = myPort.readString();   
                    if (inBuffer != null) {  // != not equal
                      output.println(inBuffer);
                      delay(3000);
                    }
                  }


                  output.flush(); // Write the remaining data

                  output.close(); // Finish the file

                    exit(); // Stop the program
                } 
</code></pre>
]]></description>
   </item>
   <item>
      <title>line() not drawing anything.</title>
      <link>https://forum.processing.org/two/discussion/12550/line-not-drawing-anything</link>
      <pubDate>Wed, 16 Sep 2015 21:50:24 +0000</pubDate>
      <dc:creator>amoondra</dc:creator>
      <guid isPermaLink="false">12550@/two/discussions</guid>
      <description><![CDATA[<p>Hi. I am pretty new to processing so bear with me for silly mistakes.I am trying to draw a trace of data received on serial port. I am able to receive it but i am not able to draw in using line. It just seems to not respond. The code is following which is derived form code i found online</p>

<pre><code>import processing.serial.*;

Serial myPort;  // Create object from Serial class
float val, screen_increment, old_x=0, old_y=0;      // Data received from the serial port
String inString;  // Input string from serial port


void setup() 
{

  size(1000, 600);
  String portName = Serial.list()[2];//Set the Serial port COM    
  myPort = new Serial(this, portName, 9600);//Set up the serial port
  myPort.bufferUntil('\n');//read in data until a line feed, so the arduino must do a println
  background(208,24,24);//make the background that cool blood red
}//setup

void draw()
{
//nothing in here, this is kind of like the void loop in arduino
}

void serialEvent(Serial myPort) { //this is called whenever data is sent over by the arduino

  inString = myPort.readString();//read in the new data, and store in inString
  inString = trim(inString);//get rid of any crap that isn't numbers, like the line feed
  val = float(inString);//convert the string into a number we can use

  val=map(val,0,4096,0,600);

  strokeWeight(5);//beef up our white line
  stroke(255, 255, 255);//make the line white

  //drawing the line
  println(old_x,old_y,screen_increment,600-val);
  line(old_x, old_y, screen_increment, 600-val);


  //store the current x, y as the old x,y, so it is used next time
  old_x = screen_increment;
  old_y = 600-val;

  //increment the x coordinate,  you can play with this value to speed things up
  screen_increment=screen_increment+2;

  //this is needed to reset things when the line crashes into the end of the screen
  if(screen_increment&gt;(1000)){
    background(208,24,24); //refresh the screen, erases everything
    screen_increment=-50; //make the increment back to 0, 
    //but used 50, so it sweeps better into the screen
    //reset the old x,y values
  old_x = -50;
  old_y = 0;

  }

}
</code></pre>

<p>SInce i have added a println the output of the code <code>println(old_x,old_y,screen_increment,600-val);</code> is following which seems correct to me</p>

<pre><code>    0.0 0.0 0.0 302.9297
    0.0 302.9297 2.0 303.8086
    2.0 303.8086 4.0 300.29297
    4.0 300.29297 6.0 297.36328
    6.0 297.36328 8.0 295.60547
    8.0 295.60547 10.0 294.87305
    10.0 294.87305 12.0 294.14062
    12.0 294.14062 14.0 294.87305
    14.0 294.87305 16.0 296.77734
</code></pre>

<p>All I see is blank red screen</p>

<p>Please Help</p>
]]></description>
   </item>
   <item>
      <title>Arduino to Processing importing variables.</title>
      <link>https://forum.processing.org/two/discussion/12386/arduino-to-processing-importing-variables</link>
      <pubDate>Thu, 03 Sep 2015 18:47:08 +0000</pubDate>
      <dc:creator>jfanals</dc:creator>
      <guid isPermaLink="false">12386@/two/discussions</guid>
      <description><![CDATA[<p>Hey all, I am quite new at that world, but I would like to know why does it happen to me. The thing is that I created a variable on Arduino which receives a random number between 0 and 100; however, I wanted to print in on Processing but it is not recognized because instead of that it writes COM3, the port where Arduino is connected. 
By the way, here is the Arduino code:</p>

<p>void setup() 
{
//initialize serial communications at a 9600 baud rate</p>

<p>Serial.begin(9600);
}</p>

<p>void loop()
{</p>

<p>int num = random(0, 100);</p>

<p>Serial.println(num);</p>

<p>delay(100);</p>

<p>}</p>

<p>And here the Processing one:</p>

<p>import vsync.*;</p>

<p>import processing.serial.*;</p>

<p>Serial myPort;</p>

<p>void setup() {</p>

<p>myPort = new Serial(this, Serial.list()[0], 9600);</p>

<p>}</p>

<p>void draw() {</p>

<p>println(Serial.list());</p>

<p>delay(1000);
}</p>

<p>I don't know if I am missing some libraries but I am kinda stocked for hours.</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>Is there a way to know when a port is connected?</title>
      <link>https://forum.processing.org/two/discussion/12142/is-there-a-way-to-know-when-a-port-is-connected</link>
      <pubDate>Tue, 18 Aug 2015 22:48:00 +0000</pubDate>
      <dc:creator>Mino32</dc:creator>
      <guid isPermaLink="false">12142@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys!! I have the code bellow:</p>

<pre><code>    import processing.serial.*; 

    PrintWriter output;
    Serial myPort;    // The serial port
    PFont myFont;     // The display font
    String inString;  // Input string from serial port
    int lf = 10;      // ASCII linefeed 
    char uno = ' '; //To compare data
    boolean hay_puerto = false; //True if there are ports on the list

    void setup() 
    { 
      size(400, 200); 
      output = createWriter("data.txt"); //Create txt file
      noLoop();
`//To know if there is a port `
      String[] s  = Serial.list();
      println(s.length);
      if (s.length!=0)
      {
        hay_puerto = true;
      } else
      {
        hay_puerto = false;
      }

`//If there is a port, start connection`
      if (hay_puerto)
      {
        myPort = new Serial(this, Serial.list()[0], 9600); 
        myPort.bufferUntil(lf);
      } else
      {
        println("No serial port connected");
      }
    } 

    void draw() 
    { 
      background(0); 
      text("received: " + inString, 10, 50);
    } 

    void serialEvent(Serial p) 
    {
      uno = myPort.readChar();
      if (uno == '$')
      {
        inString = myPort.readString();

        if (inString != null) 
        {
          println(inString);
          output.println(inString);
        }
      } else
      {
        myPort.clear();
      }
      //inString = p.readString();
      redraw();
    }

    void keyPressed()
    {
      if (key=='x')
      {
        output.flush();  //writes data in the file
        output.close();  //Closes document
        exit();
      }
    }
</code></pre>

<p>My question is: Is there another way to know if the port is available? I mean, in my code I check for the size of the port list, and if it is zero it means that there is no port. If I don't do this, the program gets an error because there is no port. The problem is happen when I connect the port (while running the program), my program does not detect it so it does not do anything when I send something.</p>

<p>I hope my question is clear, and thanks :).</p>
]]></description>
   </item>
   <item>
      <title>[Serial Problem] Conditions not working even thought the values match!</title>
      <link>https://forum.processing.org/two/discussion/10812/serial-problem-conditions-not-working-even-thought-the-values-match</link>
      <pubDate>Thu, 14 May 2015 22:37:32 +0000</pubDate>
      <dc:creator>tnowroz</dc:creator>
      <guid isPermaLink="false">10812@/two/discussions</guid>
      <description><![CDATA[<p>What I am trying to do is read some IR signals.</p>

<p>The code in Arduino is:</p>

<pre><code> /*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * <a href="http://arcfn.com" target="_blank" rel="nofollow">http://arcfn.com</a>
 */


 #include &lt;IRremote.h&gt;


 int RECV_PIN = 7;

 IRrecv irrecv(RECV_PIN);

 decode_results results;


 void setup() {

    Serial.begin(9600);

    irrecv.enableIRIn(); // Start the receiver  
}


void loop() {

  if (irrecv.decode(&amp;results)) {

    Serial.println(results.value);

    irrecv.resume(); // Receive the next value

  }

  delay(100);

}
</code></pre>

<p>It reads the IR signals, and suppose, Now I want to get this at Processing and want to open a webpage for that.</p>

<pre><code> // Example by Tom Igoe

 import processing.serial.*;

 Serial myPort;    // The serial port

 String inString;  // Input string from serial port

 int lf = 10;      // ASCII linefeed


 void setup() {

    size(400,200);

    // List all the available serial ports:

    println(Serial.list());

    // Open the port you are using at the rate you want:hat 

    myPort = new Serial(this, "COM9", 9600);

    myPort.bufferUntil(lf);

 }

 void draw() {

   background(0);

   text("received: " + inString, 10,50);


 }

 void serialEvent(Serial p) {

   inString = p.readString();


   if(inString.equals("544993039")){

    String[] params = { "start www.google.com" };

    open(params);


   }
 }
</code></pre>

<p>`</p>

<p>But however even though the signal of that value is caught in the receiver, but the codes do not get executed! :/</p>

<p>I am 100% sure that the signal reaches the receiver as Arduino seems to do what I want it to do when I send signals, for example when I use this code:
<code>if(results.value == 544993039) { digitalWrite(8, HIGH);  }</code></p>

<p>Anything connected to pin 8 seems to work just fine.</p>

<p>but in Processing:</p>

<pre><code>if(inString.equals("544993039")){

        String[] params = { "start www.google.com" };

        open(params);


       }
</code></pre>

<p>Nothing seems to happen. Can anybody help me please?</p>
]]></description>
   </item>
   <item>
      <title>sending Analog values from Arduino into Processing via Serial Library</title>
      <link>https://forum.processing.org/two/discussion/10452/sending-analog-values-from-arduino-into-processing-via-serial-library</link>
      <pubDate>Wed, 22 Apr 2015 05:39:48 +0000</pubDate>
      <dc:creator>fxmech</dc:creator>
      <guid isPermaLink="false">10452@/two/discussions</guid>
      <description><![CDATA[<p>I am stuck trying to send 3 analog values (potentiometer inputs) from arduino into processing.
the values are 0-1023 (10bit)... I cant figure out how to do it..
 as a test sketch I tried this for the arduino side:</p>

<pre><code>void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int a = -11023;
  int b = 564;
  int c=analogRead(0);
   Serial.println(a);
   Serial.print(",");
   Serial.print(b);
   Serial.print(',');
   Serial.print(c);
   Serial.print(',');
  delay(500);
}
</code></pre>

<p>and this for processing:</p>

<pre><code>    import processing.serial.*;
    Serial myPort;
    int value;

    void setup()
    {
      myPort = new Serial(this, Serial.list()[0], 9600);
    }

    void draw()
    {
    }

    void serialEvent(Serial p) {
      // get message till line break (ASCII &gt; 13)
      String message = myPort.readStringUntil(',');
      if(message != null){
        value = int(message);
        println(value);
      }
    }
</code></pre>

<p>All I get are zeros on the serial monitor...
The idea is to ultimately send data to processing in groups of 3 (for the 3 sensors) and assign them to 3 variables in processing but I can see Im not grasping the concept of serial transmission :(</p>
]]></description>
   </item>
   <item>
      <title>Remove a Line Break</title>
      <link>https://forum.processing.org/two/discussion/10226/remove-a-line-break</link>
      <pubDate>Tue, 07 Apr 2015 14:57:18 +0000</pubDate>
      <dc:creator>fahadkalis</dc:creator>
      <guid isPermaLink="false">10226@/two/discussions</guid>
      <description><![CDATA[<p>I am writing a program, to get serial input string and then add three COMMAs with it.
but I am facing a problem of a line gap (carriage return+linefeed)  b/w string and COMMAs.
Can you plz guide me on how do I resolve this problem and remove the line gap.
below in my code.</p>

<pre><code>import processing.serial.*;
Serial serialPort;
String input;

void setup() {
  serialPort = new Serial(this,"COM4",9600);
  serialPort.bufferUntil('\n'); }

void draw() {
  background(1);
}

void serialEvent(Serial serialPort) {
  input = serialPort.readString();
  for (int i=0 ; i&lt;3; i++) {
  input = input + ",";
  }
println(input);
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>