Prototyping Class
December 15, 2021

Connecting Processing to Arduino

In this project, I connected the Processing app to the Arduino device in order to represent the signal from the Arduino project in the visual form.

The code for this purpose is:

import processing.serial.*;

Serial arduinoConnection;

int sensor = 0;
int x = 0;

void setup() {
  printArray( arduinoConnection.list() );
    //println( arduinoConnection.list() );
  size (1200, 600);
  arduinoConnection = new Serial(this, Serial.list()[2], 9600);
}

void draw() {
 // create a running line graph
 // x = time, y = sensor value
 float y = map( sensor, height/2, height, height/2, height );
 float bright = map( sensor, 0, 1, 255, 0 );
 fill( bright,0,0 );
 rect( x,(height/2)+y,8,8*y );
 x++;
 
 if( x >= width ) { // we've run off the edge
   background(192);
   x = 0;
 }
}

And here is how it looks like:

Graphic representation of the signal from Arduino in the Processing app

Please, leave your comments!