Read Serial Value (From Arduino)

This is my lousy attempt to convert an old Java Mode sketch from the link below to Python Mode: :snake:

"""
 * Efficient Serial Reading (v1.01)
 * GoToLoop (2018-Nov-22)
 *
 * Discourse.Processing.org/t/read-serial-value-from-arduino/5829/2
 *
 * Forum.Processing.org/two/discussion/16618/
 * processing-with-arduino-void-serialevent#Item_5
"""

add_library('serial')

PORT_INDEX, BAUDS = 0, 9600
myString = ''

def setup():
    noLoop()
    ports = Serial.list()
    Serial(this, ports[PORT_INDEX], BAUDS).bufferUntil(ENTER)


def draw(): print myString


def serialEvent(s):
    global myString
    myString = s.readString().trim()
    redraw()

Since I don’t have any of such hardware, I can’t tell whether it’ll work or not. :no_mouth:

You should ask in the repo below if it doesn’t work for you: :face_with_head_bandage: