does someone have working code in Processing for Serial processing from Arduino ( a line at a time )
in
Integration and Hardware
•
1 year ago
I am fairly new to Processing, so pardon the newbie question
int firstSensor = 0;
int secondSensor = 0;
int reset = 0;
int serve = 0;
int inByte = 0;
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
randomSeed(10);
//establishContact(); // send a byte to establish contact until Processing responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
inByte = Serial.read();
firstSensor = random(385);
secondSensor = random(385);
reset = random(0,2);
serve = random(0,2);
if (reset == 1) {
serve = 0;
}
Serial.print(firstSensor);
Serial.print(',');
Serial.print(secondSensor);
Serial.print(',');
Serial.print(reset);
Serial.print(',');
Serial.println(serve);
}
}
I can read the data in python:
#!/usr/bin/env python
import serial
from time import sleep
s = serial.Serial(port='/dev/tty.usbmodem411', baudrate=9600)
while (1):
sleep(1)
s.write('\n')
l = s.readline().strip()
print l
but I can't get this to work in Processing:
I am trying to use serialEvent and bufferUntil, but no matter what I try, absolutely nothing comes over.
Does anyone have any working code that would take the output of the arduino in processing?
thanks,
Jerry
1