# Port Serial en "Size"

**URL:** <https://discourse.processing.org/t/port-serial-en-size/7568>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [January 16, 2019, 7:21pm UTC](https://discourse.processing.org/t/port-serial-en-size/7568 "2019-01-16T19:21:46Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 20, 2019, 2:06am UTC](https://discourse.processing.org/t/port-serial-en-size/7568/8 "2019-01-20T02:06:48Z")

</div>

did you check on how to use CP5 Textarea

[http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5textarea/ControlP5textarea.pde](http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5textarea/ControlP5textarea.pde)

i not see any

```auto
myTextarea.setText("test");

```

try like

```auto
// https://discourse.processing.org/t/port-serial-en-size/7568
// v01 2 cp5 button and 2 text()
// v02 instead text() 3 cp5 textarea ( in, out, console )
// http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5textarea/ControlP5textarea.pde
// https://github.com/sojamo/controlp5/blob/master/examples/extra/ControlP5console/ControlP5console.pde

import controlP5.*; //import ControlP5 library
ControlP5 cp5; //create cp5 object
Textarea inTXT, outTXT, sysTXT;
Println console;

import processing.serial.*;
Serial port;
String portName;
boolean serOn = true;//false;//true;

PFont font;
String outtxt="we send:";
String intxt="we got:";

void setup() { 
  size(800, 500); //window size, (width, height)
  font = createFont("calibre light bold", 20);
  setup_communication();
  setup_buttons();
  println("key [c] clear");
}

void draw() { //same as loop in arduino ide
  background(150, 200, 200); // background color of window (r, g, b) or (0 to 255)
  instream();
  fill(25, 115, 235); //text color (r, g, b)
  text("SERIAL PORT "+portName, 100, 30); //lets give title to our window
}

void setup_communication() {
  printArray(Serial.list()); //prints all available serial ports
  portName = Serial.list()[1]; // change the [1] acc the list you got printed
  println("try connect to "+portName);
  if (serOn) port = new Serial(this, portName, 9600);
}

void setup_buttons() {
  //so when you press any button on the GUI, it sends particular char over serial port
  cp5 = new ControlP5(this);

  cp5.addButton("A")
    .setPosition(30, height-70) //x and y coordinates of upper left corner of button
    .setSize(60, 60) //(width, height)
    .setFont(font);   

  cp5.addButton("B")
    .setPosition(130, height-70) //x and y coordinates of upper left corner of button
    .setSize(60, 60) //(width, height)
    .setFont(font);

  int tposX=20, tposY=40, tw=width-40, th=100;
  outTXT = cp5.addTextarea("outtxt")
    .setPosition(tposX, tposY)
    .setSize(tw, th)
    .setFont(createFont("arial", 12))
    .setLineHeight(14)
    .setColor(color(128))
    .setColorBackground(color(255, 100))
    .setColorForeground(color(255, 100));
  ;
  outTXT.setText(outtxt);

  tposY += th+10; 
  th = 200; // move down
  inTXT = cp5.addTextarea("intxt")
    .setPosition(tposX, tposY)
    .setSize(tw, th)
    .setFont(createFont("arial", 12))
    .setLineHeight(14)
    .setColor(color(128))
    .setColorBackground(color(200, 200, 0, 100))
    .setColorForeground(color(255, 100));
  ;
  inTXT.setText(intxt);

  tposY += th+10; 
  th = 60; // move down
  sysTXT = cp5.addTextarea("systxt")
    .setPosition(tposX, tposY)
    .setSize(tw, th)
    .setFont(createFont("arial", 12))
    .setLineHeight(14)
    .setColor(color(128))
    .setColorBackground(color(200, 0, 0, 100))
    .setColorForeground(color(255, 100));
  ;
  console = cp5.addConsole(sysTXT);
}

void A() {
  if (serOn) port.write('A');
  println("send A"); // _______ add kll
  outtxt += "\nA";
  outTXT.setText(outtxt);
} 
void B() {
  if (serOn) port.write('B');
  println("send B"); // _______ add kll
  outtxt += "\nB";
  outTXT.setText(outtxt);
}

void instream() {
  if ( serOn && port.available() > 0) { // If data is available,
    int inByte = port.read(); // read it and store it in intxt
    if ( inByte == 10 ) intxt += "\n";
    else intxt += str(inByte);
    inTXT.setText(intxt);
  }
}

void keyPressed() {
  if ( key == 'c' ) { 
    intxt = ""; 
    inTXT.setText(intxt);
    outtxt = "";
    outTXT.setText(outtxt);
  }
}

```

 ![2019-01-20_10-30-15_snap](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0a46ebf21c5bf21b67f3a0f8a44e7cb60dbf8b41.png)

---

_[View the full topic](https://discourse.processing.org/t/port-serial-en-size/7568)._
