Question: connecting arduino with psychopy

Hello,

In your arduino program change char input = Serial.read(); to int input = Serial.read();

Edit: I should also give a comprehensive example on the Python side of things. It also looks like some data is being passed back to the host PC and you might want to also use that.

import serial
import time

def main():
    # open the port
    port = serial.Serial("COM3", 9600)

    # by default, the Arduino resets on connection,
    # give it some time to wake-up.
    time.sleep(1)

    # write data to the port
    port.write('1')
    port.flush()

    # blocks until a response arrives (synchronize CPU<->MCU actions)
    while not port.inWaiting():
        print(port.readline())

    # close, we are done with the port
    port.close()
    return 0

if __name__ == "__main__":
    main()

Furthermore in Arduino, change Serial.print("The Device was on"); to Serial.println("The Device was on"); since port.readline() expects an end-line character.

2 Likes