-
-
Save garethfoote/0f2f026b2d84e8e6901b2448ad6fdb11 to your computer and use it in GitHub Desktop.
This is an example of how to connect to an Arduino automatically in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
Serial arduino; | |
void setup() { | |
// Create a canvas | |
size( 800, 600 ); | |
// Get a list of serial ports | |
String ports[] = Serial.list(); | |
int id = 0; | |
// Find an Arduino tty.usb* port | |
for ( int i = 0; i < ports.length; i++ ) { | |
if ( ports[i].indexOf( "tty.usb" ) != -1 ) | |
id = i; | |
} | |
// Connect to the Arduino | |
println( "Connecting to: " + ports[id] ); | |
arduino = new Serial( this, ports[id], 9600 ); | |
} | |
void draw() { | |
} | |
// New Serial Data Event | |
void serialEvent(Serial p) { | |
println( p.readChar() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment