Go Down

Topic: Python equivalent of Processing's serialEvent()? (Read 4046 times) previous topic - next topic


I currently have an Arduino sketch that communicates with Processing using <> delimited packets over serial, similar to other examples posted on the forums: http://forum.arduino.cc/index.php?topic=288234.0

Processing has a nice little function serialEvent() that I use as an independent thread to parse my data as it arrives in Processing: https://processing.org/reference/libraries/serial/serialEvent_.html

Is there a similar utility function for Python? We are porting our code to Python and I'm working my way through some of the forum Python examples, especially those based on pySerial (e.g. http://forum.arduino.cc/index.php?topic=225329.0) as well as an example I have found elsewhere that incorporates PyQt: http://shop.wickeddevice.com/2011/05/16/a-slick-threaded-gui-for-arduino-projects-with-python-and-qt/

I just wanted to see before I got too far if there was a trivial way in Python to mimic Processing's serialEvent()

Thanks much


Feb 04, 2015, 11:55 am Last Edit: Feb 04, 2015, 12:30 pm by Robin2
I think you would have to create a separate beackground Thread in Python which would repeatedly call the function recvFromArduino(): that is in my Python demo. I have used that arrangement myself.

Another thought ...
You can easily organize a Python program the same way as the Arduino setup() and loop() system.
In the Arduino serialEvent() is exactly the same as having this code as the last thing in loop()

Code: [Select]
if (Serial.available() > 0) {

Two or three hours spent thinking and reading documentation solves most programming problems.


Thanks very much-- for this reply and for your other posts!

Go Up