Raw Data using serial port


I’m trying to follow the instructions as mentioned in the following link. I was wondering if Psychopy saves the output of the serial port anywhere or is is only keeps track of timestamps of input stimuli and serial port start and end. Any help with this is appreciated. Thanks in advance.


Hi @wanderinguser,

Not by default, however you can ask for the serial port to be read at a given point using port.read() where port is the name of your serial port if that’s helpful?



@Kimberley_Dundas Thanks for getting back to me. I tried to do it with coding instead of using the builder. The experiment runs without any error, but still, I cannot find the signal output anywhere, am I missing something in my code?

I would highly recommend that you use Builder to add your stimuli etc., as this will give the best timing possible. It looks like you are using the Builder interface and adding code components here though, which is absolutely fine.

So the code you have here looks like it’s in the begin experiment tab. Those two if statements should be in an each frame tab, as the status of image_2 needs to be checked on each frame. If they’re here, the first will never return true.

Could I just check what you’re wanting to receive from the serial port? Are you expecting it to send a response when the trigger is received?



@Kimberley_Dundas I tried Builder too using serial out input stimuli, getting the same result. I’m trying to get raw signal output data from serial output. To achieve that do I need to follow the change the code location from the experiment tab to each frame tab?


Just checking I understand - do you need to send any triggers at all to your serial device? Or just read the output?

In both cases, the port.read()/port.readline() commands would need to be in the each frame tab, yes.

No exactly, I’m trying to show an image and get the raw signal out put somewhere recorded. A setup like this basically.

I changed the code to this format.

The experiment starts and it shows the first image and never gets to the second one. The screen keeps showing the first image without quitting. This is the output of the program.

Please let me know if I need to change anything to make it work.

The star just indicates that you have made unsaved changes to the code in that tab.

If you don’t need to send anything, you actually only need the final two lines of code in the each frame tab, so you’d have the following in the Begin Experiment tab:

import serial
port = serial.Serial('/dev/tty.usbserial-DP04VYDC', baudrate = 115200)
res = []

And then in the Each Frame tab:

This would append the value read from the port on every frame. I should caution though that this will use a lot of memory (depending on what you’re collecting) and potentially cause dropped frames if there’s a lot of data being sent from the serial port.

Hope this helps,


Hi Kim,

Thanks for your response. This is what I currently have, it gets stuck on the text_2 part with the loading logo appearing and never gets to the image_2 part. Not sure if there is something wrong with my setup or if is this the same issue that you mentioned about memory. My laptop doesn’t show any sign of lagging at all. It would be really nice to know your input on this problem.


Would you be able to share your .psyexp file at all so that I can take a look?



@Kimberley_Dundas Absolutely. I attached it to this message. Thanks in advance for your help.

cat_dog_exp_code.psyexp (35.7 KB)