Code handling "Error, disabling_serialEvent () in Arduino

I am getting this error when trying to start arduino and processing

Error, disabling serialEvent() for /dev/cu.usbmodem1451 null

      

I am running process 2 and Arduino 1.6.5 on MAC OSX 10.9.5

I am new to processing and arduino. I'm just trying to use three potentiometers to control the RGB values โ€‹โ€‹of the background color.

Arduino code:

int potPin = 0;
//int potPinB = 1;
//int potPinC = 2;

void setup() 
{
 Serial.begin(9600);
}

void loop()
{
  int val = map(analogRead(potPin), 0, 1023, 0, 255);
  Serial.println(val);
  delay(500);
  //int valB = map(analogRead(potPinB), 0, 1023, 0, 255);
  //Serial.println(valB);
  //delay(50);
  //int valC = map(analogRead(potPinA), 0, 1023, 0, 255);
  //Serial.println(valC);
  //delay(50);
}

      

Processing code:

import processing.serial.*;

Serial port;

float val = 0;
//float valB = 1; // another analog input
//float valC = 2; // another analog input

void setup() 
{
  size(500, 500); 
  port = new Serial(this, "/dev/cu.usbmodem1451", 9600);
  port.bufferUntil('\n');
  if (frame != null); 
  frame.setResizable(true);
 }
void draw () 
{
background(val,255,150);
}
void serialEvent (Serial port)
{
  val = float(port.readStringUntil('\n'));
}

      

+1


source to share


1 answer


You might get an error on the serialEvent that you should be handling (floating point perhaps). Also, if you are using bufferUntil()

, you do not need to readStringUntil()

.

Try something like this:

import processing.serial.*;

Serial port;

float val = 0;
//float valB = 1; // another analog input
//float valC = 2; // another analog input

void setup() 
{
  size(500, 500); 
  port = new Serial(this, "/dev/cu.usbmodem1451", 9600);
  port.bufferUntil('\n');
  if (frame != null); 
  frame.setResizable(true);
 }
void draw () 
{
background(val,255,150);
}
void serialEvent (Serial port)
{
  try{
    val = float(port.readString());
  }catch(Exception e){
    e.printStackTrace();
  }
}

      

By just reading one value, readChar () or just read () should work.

If it works. You should be able to send multiple values. Initially, you can send the csv as a format string:



arduinoR,arduinoG,arduinoB\n

      

which you can then read as a string, split () into an array of three values, and then convert each element of the array from String to int. Update Here's an example:

import processing.serial.*; 
int r, g, b; 
void setup() { 
  try { 
    new Serial(this, "/dev/tty.usbmodemfa141", 9600).bufferUntil('\n');
  }
  catch(Exception e) { 
    println("check settings above and usb cable, something went wrong:"); 
    e.printStackTrace();
  }
} 
void draw() { 
  background(r, g, b);
} 
void serialEvent(Serial s) { 
  String data = s.readString(); 
  try { 
    String[] rgb = data.trim().split(",");
    print(rgb);
    if(rgb.length == 3){
      r = int(rgb[0]); 
      g = int(rgb[1]); 
      b = int(rgb[2]);
    }
  }
  catch(Exception e) { 
    e.printStackTrace();
  }
}

      

Later, you can look at sending data as binary: exactly 3 bytes (r, g, b). Good luck :)

+1


source







All Articles