Hi, I’m new to Python and PsychoPy, and I plan to set up the communication between Arduino Uno and PsychoPy through pyserial using the custom code element. I have tested the code in Arduino and Python3, and everything went well. However, when I use the PsychoPy, it returns no result. So, quite desperate right now.
…
The code for Arduino:
void setup() {
pinMode(12,OUTPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available()>0)
{
char input=Serial.read();
if(input==‘1’){
digitalWrite(12,HIGH);
delay(1000);
digitalWrite(12,LOW);
Serial.print(“The Device was on”);
}
else if(input==‘0’){
digitalWrite(12, LOW);
}
}
}
The code for PsychoPy:
import serial
port=serial.Serial(‘COM3’,9600)
port.write(‘1’) //as I have installed python3, the code I run through cmd is port.write(b’1’)
port.close()
Any help will be much appreciated!
Many thanks,
Tongyu