Problem using winsound in python with arduino

I'm trying to play notes using winsound in my laptop by initiation it via a serial input from arduino. This is just a part of the small project-To play notes using asynchronous input to arduino. But the code is not working.Here is the code and the problem explained further.

Arduino code-

void setup(){ Serial.begin(9600); }

void loop(){ Serial.println(1); delay(2000); }

Python code-

import serial import winsound from time import sleep ser = serial.Serial('COM4', 9600)

while True: x=ser.readline() print x if(x==1):

winsound.Beep(261, 200)

When i run this,1 is printed every 2 seconds,but no note is played.But if i change it to if(x!=1),it does play after x is printed as 1.So basically,x is not equal to 1 when the line "winsound.Beep(261, 200)" is executed.How is this possible?It is always 1 according to the code as well. It might be a problem of the input timings to the computer.But i am just guessing and unable to crack it. I know this is a basic level problem,but i'm using winsound for the first time.Anyone who can help with this????

you should use x == '1' as 1 is probably a string / char ...

I’ve tried that as well.Didn’t work either :roll_eyes: :roll_eyes:

have you tried x == ?

as readline() reads all chars until EOL?

That was it! :D working now..Thanx! :D