# Read Serial Value (From Arduino)

**URL:** <https://discourse.processing.org/t/read-serial-value-from-arduino/5829>\
**Category:** Processing.py\
**Created:** [November 22, 2018, 12:54pm UTC](https://discourse.processing.org/t/read-serial-value-from-arduino/5829 "2018-11-22T12:54:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 22, 2018, 1:51pm UTC](https://discourse.processing.org/t/read-serial-value-from-arduino/5829/2 "2018-11-22T13:51:52Z")

</div>

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

- [Forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item\_5](http://Forum.Processing.org/two/discussion/16618/processing-with-arduino-void-serialevent#Item_5)

```python
"""
 * 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. 😶

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

> <https://github.com/jdf/Processing.py-Bugs/issues/157>

---

_[View the full topic](https://discourse.processing.org/t/read-serial-value-from-arduino/5829)._
