examples/basics/sketch.js
function setup() {
  createCanvas(windowWidth, windowHeight);

  // Instantiate our SerialPort object
  serial = new p5.SerialPort();

  // Get a list the ports available
  // You should have a callback defined to see the results
  serial.list();

  // Assuming our Arduino is connected, let's open the connection to it
  // Change this to the name of your arduino's serial port
  serial.open("/dev/cu.usbmodem1411");

  // Here are the callbacks that you can register

  // When we connect to the underlying server
  serial.on('connected', serverConnected);

  // When we get a list of serial ports that are available
  serial.on('list', gotList);
  // OR
  //serial.onList(gotList);

  // When we some data from the serial port
  serial.on('data', gotData);
  // OR
  //serial.onData(gotData);

  // When or if we get an error
  serial.on('error', gotError);
  // OR
  //serial.onError(gotError);

  // When our serial port is opened and ready for read/write
  serial.on('open', gotOpen);
  // OR
  //serial.onOpen(gotOpen);

  // Callback to get the raw data, as it comes in for handling yourself
  //serial.on('rawdata', gotRawData);
  // OR
  //serial.onRawData(gotRawData);
}
function setup() {
  createCanvas(windowWidth, windowHeight);

  // Instantiate our SerialPort object
  serial = new p5.SerialPort();

  // Get a list the ports available
  // You should have a callback defined to see the results
  serial.list();

  // Assuming our Arduino is connected, let's open the connection to it
  // Change this to the name of your arduino's serial port
  serial.open("/dev/cu.usbmodem1411");

  // Here are the callbacks that you can register

  // When we connect to the underlying server
  serial.on('connected', serverConnected);

  // When we get a list of serial ports that are available
  serial.on('list', gotList);
  // OR
  //serial.onList(gotList);

  // When we some data from the serial port
  serial.on('data', gotData);
  // OR
  //serial.onData(gotData);

  // When or if we get an error
  serial.on('error', gotError);
  // OR
  //serial.onError(gotError);

  // When our serial port is opened and ready for read/write
  serial.on('open', gotOpen);
  // OR
  //serial.onOpen(gotOpen);

  // Callback to get the raw data, as it comes in for handling yourself
  //serial.on('rawdata', gotRawData);
  // OR
  //serial.onRawData(gotRawData);
}
function setup ( ) { createCanvas ( windowWidth , windowHeight ) ; // Instantiate our SerialPort object serial = new p5 . SerialPort ( ) ; // Get a list the ports available // You should have a callback defined to see the results serial . list ( ) ; // Assuming our Arduino is connected, let's open the connection to it // Change this to the name of your arduino's serial port serial . open ( "/dev/cu.usbmodem1411" ) ; // Here are the callbacks that you can register // When we connect to the underlying server serial . on ( 'connected' , serverConnected ) ; // When we get a list of serial ports that are available serial . on ( 'list' , gotList ) ; // OR //serial.onList(gotList); // When we some data from the serial port serial . on ( 'data' , gotData ) ; // OR //serial.onData(gotData); // When or if we get an error serial . on ( 'error' , gotError ) ; // OR //serial.onError(gotError); // When our serial port is opened and ready for read/write serial . on ( 'open' , gotOpen ) ; // OR //serial.onOpen(gotOpen); // Callback to get the raw data, as it comes in for handling yourself //serial.on('rawdata', gotRawData); // OR //serial.onRawData(gotRawData); }
you'll use this to write incoming data to the canvas
you ll use this to write incoming data to the canvas