osx - Processing Code "Error, disabling_serialEvent() in Aurdino -
i receive error when trying run arduino , processing
error, disabling serialevent() /dev/cu.usbmodem1451 null
i running process 2 , arduino 1.6.5 on mac osx 10.9.5
i super new processing , arduino . trying use 3 potentiometers control rgb values of 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; // analog input //float valc = 2; // 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')); }
you might getting error in serialevent should handling (perhaps float conversion). also, if you're using bufferuntil()
, shouldn't need readstringuntil()
.
try this:
import processing.serial.*; serial port; float val = 0; //float valb = 1; // analog input //float valc = 2; // 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(); } }
when reading single value, readchar() or read() should work.
if above works. should able send multiple values. can send csv formatter line:
arduinor,arduinog,arduinob\n
which can read string, split() array of 3 values, convert each array element string int. update here 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 , usb cable, 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 on can @ sending data binary: 3 bytes (r,g,b). have fun :)
Comments
Post a Comment