so all I’m trying to do is use processing to read a value from the Serial port of an arduino. I have already connected I just don’t know the correct python method to read the value.
Current code:
def setup():
global arduino
size(10,10)
println(Arduino.list())
arduino = Arduino(this, Arduino.list()[1], 9600)
def draw():
#val = arduino.analogRead(0)
for i in range(10):
val = arduino.readString(i) #<----------------- Here 'readString' doesn't work, what should this be?
print("{} ___ {}".format(frameCount,val))
delay(10000)
# Python Serial Reading
# v1.0.0
# GLV 2022-06-11
add_library("serial")
myPort = Serial(this, "COM2", 9600)
inString = ""
def setup():
size(400, 100)
# This does not work:
#myPort.bufferUntil(ENTER)
# This works:
myPort.bufferUntil(0x0A)
textSize(24);
textAlign(LEFT, CENTER);
fill(0);
noLoop()
def draw():
background(255); # I needed something here
text (inString, 50, height/2);
def serialEvent(Serial):
global inString
# This does not work:
# inString = myPort.readString().trim()
# This works:
inString = myPort.readString()
inString = trim(inString)
println(inString)
arr = inString.split(",")
for i in arr:
print(i)
redraw()
Above code does NOT work with Processing 4.0.b8
You can use a virtual serial port if you do not have hardware.
There is one available here: https://www.hhdsoftware.com/
See bottom for free version.
Use any serial software or code of your choice to send serial data.
I used the Serial Monitor that comes with Arduino software (hardware not required) to send data.