Hi, I’m new to Arduino and Processing.py.
I am using Processing and Arduino to complete my graduation project.(English is not my native language, sometimes I speak it’s very strange.)
I want to implement the Serial library so that Processing can read different values of different sensors on arduino.I tried to create an ever-changing list of sensor values using split().
I tried to use split() to separate the incoming values, but I kept getting an error. And I don’t know how to use bufferUntil() properly.
Here is my Arduino and Processing code.Can someone help me?
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int val0 = analogRead(A0); //
int val1 = analogRead(A1);
int val2 = analogRead(A2);
int val3 = analogRead(A3);
int val4 = analogRead(A4);
int val5 = analogRead(A5);
Serial.print(val0, DEC);
Serial.print(',');
Serial.print(val1, DEC);
Serial.print(',');
Serial.print(val2, DEC);
Serial.print(',');
Serial.print(val3, DEC);
Serial.print(',');
Serial.print(val4, DEC);
Serial.print(',');
Serial.print(val5, DEC);
Serial.print('\n');
// Serial.println();
delay(1000);
}
add_library("serial")
myPort = Serial(this,"COM3",9600)
def setup():
size(200,200)
myPort.bufferUntil('\n')
def draw():
if myPort.available()>0:
P_dates = myPort.readString()
string01 = P_dates
TRY = string01.split(",")
C = list()
for i in TRY:
C.append(int(i))
println(C)
delay(1000)
def serialEvent(Serial):
inString = p.readString()
These are some of the mistakes I’ve encountered
TypeError: bufferUntil(): 1st arg can't be coerced to int
If I delete bufferUnitl ()
ValueError: invalid literal for int() with base 10: '77 51'
When I changed the program, the output list became strange
if myPort.available()>0:
P_dates = myPort.readString()
string01 = P_dates
TRY = string01.split(",")
C = list()
for i in TRY:
C.append((i))
println(TRY)
I don’t understand why the output value is like this.The values on the serial monitor are correct.
The console values are as follows
[u'49', u'56', u'53', u'53', u'123', u'80\n']
[u'48', u'56', u'53', u'53', u'89', u'60\n']
[u'49', u'55', u'53', u'53', u'94', u'60\n']
[u'49', u'56', u'53', u'53', u'110', u'64\n']
[u'48', u'55', u'52', u'52', u'103', u'60\n']
[u'47', u'55', u'53', u'53', u'91', u'57\n']