So I have 7 different sensor I’d like to send to Processing, then use each of their values as variables inside different webcam filters.

I’m going off of this tutorial which has been helpful, but it doesn’t give linear steps – more like different techniques depending on what you’re trying to use it for. In that tutorial, it shows two ways to initialize connection between Serial and Arduino – the Punctuation method and the Call-and-response method. I used the Punctuation method.

To sum up the Punctuation method, you put the sensor values into one string, separated with commas. Once the values are sent over, you split the string and put all of the values into an array. Once in an array, you can individually take out each of the values and turn them into variables that are usable in the draw loop.

My Processing sketch runs perfectly fine sometimes. Otherwise it will give either this error :

  Error, disabling serialEvent() for /dev/cu.usbmodem1421

Or this one :

enter image description here

Does anyone see anything fishy with the syntax or structure I’m setting up? (I took out all filter functions except the temp -> blur to make debugging easier.)

// get the serial lib :
import processing.serial.*;

// give port a variable :
Serial port;

// get the webcam lib :
import processing.video.*;

// give webcam a variable :
Capture webcam;

// sensors
int cap1, cap2, piezo, temp, axisX, axisY, axisZ;

void setup() {
  size(480, 360, P2D);

  webcam = new Capture(this, width, height, 24);

  String portName = "/dev/cu.usbmodem1421";
  port = new Serial(this, portName, 9600);

void captureEvent(Capture webcam) {

void serialEvent(Serial port) {

  String reading = port.readStringUntil('\n');
  if (reading != null) {
    reading = trim(reading);

    int values[] = int(split(reading, ','));

    for (int valNum = 0; valNum < values.length; valNum++) {
      print(values[valNum] + "|");

    if (values.length > 1) {
      cap1 = values[0];
      cap2 = values[1];
      piezo = values[2]; 
      temp = values[3];
      axisX = values[4];
      axisY = values[5];
      axisZ = values[6];

void draw() {

  // temp  
  float t;
  if (temp >= 100) { //when analog pin unplugged 
    t = 6;
  } else {
    t = 0;

  image(webcam, 0, 0);
  filter(BLUR, t);

//if down key pressed, saveImage();
void saveImage()

void keyPressed() {
  if (key == CODED) {
    if (keyCode == DOWN) { 

I’m thinking it’s an issue with memory, or maybe the way I’m sending/receiving the data is shoddy.

Apparently one of the disadvantages to using Punctuation rather than Call-and-response is that it can slow down the program if it contains a lot of graphic work… but why would it work in perfect time sometimes and then not work at all?

Any insight would be amazing!!

  • What did the print in SerialEvent print out just before the error? Also, why if (values.length > 1)? Seems like if (values.length > 6) would work better Mar 31, 2016 at 3:25
  • 1
    The baudrate is really low, try a higher one (115200) maybe it is just a timing problem (pipe full/unready). Remember changing both - arduino and your program.
    – moestly
    Mar 31, 2016 at 8:54


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.