Data exchanges via PORTS - Arduino and Processing

BASIC QUESTION: : reading and / writing short data streams (char, int, binary. strings).VIA THE ports

The code for each side (IDE and PDE) is from a tutorial web site: https://forum.arduino.cc/index.php?topic=434516.0
The IDE does read the individual characters for a key-in on the "Serial Monitor,: using Serial.read() coding.
The PDE uses “myPort.write” code to put something somewhere. The IDE code does not registers anything on the port, not even the number of “available” items on the port.

I will copy/paste the IDE and PDE code below. (This q/a systems needs an attachment facility).
----------- IDE ---------------------------------------------------------------------------------------------
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;

void setup() {
Serial.begin(9600);
Serial.println("");
}
void loop() {
recvWithEndMarker();
showNewData();
}

void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = ‘|’;
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = ‘\0’; // terminate the string
ndx = 0;
newData = true;
}
}
---------- PDE -----------------------------------------------------------
size(200, 200); //make our canvas 200 x 200 pixels big
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, “COM5”, 9600);
}

void draw() {

if (mousePressed == true)
{ //if we clicked in the window
myPort.write(“hallo”); //send a 1
println(“test”);
} else
{ //otherwise
myPort.write(‘0’); //send a 0
}
}

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

:)

Ahhhh. Thank you for this information. I have to ackowledge that this is one of the more courteous fora (fora?) I’ve encountered. I will work on the proper (and easier to read) format this evening (June 30).

Thomas (Tom) Kane a.k.a.“kmot”)

Is this satisfactory?
kmot

My apology. I am not sure if I corrected my post correctly/

HOW DO I DELETE ALL THE CODING AND THeN REPLACE IT WITH MUCH LESS CODE?
TOM KANE (“kmot”)

This is formatted:

String str1 = "CCCP";
char data[] = {'C', 'C', 'C', 'P'};
String str2 = new String(data);
println(str1);  // Prints "CCCP" to the console
println(str2);  // Prints "CCCP" to the console

This is not formatted:

String str1 = “CCCP”;
char data[] = {‘C’, ‘C’, ‘C’, ‘P’};
String str2 = new String(data);
println(str1); // Prints “CCCP” to the console
println(str2); // Prints “CCCP” to the console

I borrowed above from here because it had single and double quotes:
https://processing.org/reference/String.html

If it is formatted correctly the community can hover over it and easily copy it in the top right.

If it is not formatted it is difficult to read and the quotes have to be corrected if you cut and paste code.
Try a cut and past into Processing and see the difference.

Use the edit button (looks like a pencil or pen) to edit your original post:
image

https://discourse.processing.org/faq#format-your-code

:)

1 Like

Ahhh. thank you. More space between lines to make reading easier. Good plan.

Thomas (Tom) Kane / “kmot”

"Problem" resolved. Slower cycling of the two applications (PDE and IDE) demonstrated that the desired data is being sent AND received. Anotehr problem arose, but I will present a new topic to request assistance. Thank you for the admin and editing assistance.
Thomas Kane