Everything is Talkative

Aus hyperdramatik
Zur Navigation springen Zur Suche springen

ARDUINO <-- Serial --> PROCESSING

51112384011_2b0f4a0673.jpg

1 download and install newest version of Processing (https://processing.org)

2 download and install newest version of Arduino (https://www.arduino.cc)

Now that you know a bit about Netzwerke, take a look at the Arduino Serial library functions: file:///C:/Program%20Files%20(x86)/Arduino/reference/www.arduino.cc/en/Reference/Serial.html

and the Processing Serial Library functions: file:///C:/Users/hanna/OneDrive/Documents/processing-3.5.4/modes/java/reference/libraries/serial/index.html


Arduino and Processing have a set of examples that demonstrate sending data back and forth between them.

SerialCallResponse

ARDUINO > open > examples > communication: SerialCallResponse

this Arduino example code uses the function:

Serial.write(sensorValue); // Writes binary data to the serial port. This data is sent as a byte or series of bytes.

file:///C:/Program%20Files%20(x86)/Arduino/reference/www.arduino.cc/en/Serial/Write.html

the Processing example code then uses the following function to read the value:

int inByte = myPort.read();


SerialCallResponseASCII

ARDUINO > open > examples > communication: SerialCallResponseASCII

this Arduino example code uses the function:

Serial.print(sensorValue); // Prints data to the serial port as human-readable ASCII text.


the Processing example code then uses the following functions to read and trim the incoming value:

String myString = myPort.readStringUntil('\n');

myString = trim(myString); // removes any bytes other than the linefeed

int sensors[] = split(myString, ','); // split the string at the commas

you can also convert the String to an Integer at the same time:

int sensors[] = int(split(myString, ',')); // split the string at the commas and convert the sections into integers