Send alert tone to pc from microcontroller via serial communication

microcontrollerpicserial

I am learning microcontroller for couple of weeks. Yesterday, I have learned how to establish serial communication between PC and microcontroller. I can send texts to pc's hyperterminal from mcu and send text from pc to mcu.

Now, one question arises in my mind. It is how can I send control words to pc from mcu, say send an alert tone to pc from mcu? Is it possible?
Thanks. BTW, I am using PIC microcontroller.

Best Answer

This sounds a bit like a X-Y problem to me.

If you just want to produce a sound whenever your MCU detects some condition, I strongly suggest some sort of buzzer (magnetic or piezo). That's simple, reliable, energy-efficient and cheap. Using a computer just for this task is a huge overkill !

However, I suppose you ask the question this way because you want later on to trigger something more involved that needs your computer. The generic way to solve this problem is to write on the computer some always-on program (a "daemon") that talks to your mcu through serial port (or USB or whatever) and does whatever is necessary, whenever necessary : (python example)

import serial
ser = serial.Serial()
while (True) :
    if Serial.read()=='a' :
        # do something

You could also probably start a standard shell (bash, zsh or whatever is available for your OS) talking through serial port. You need to setup the serial port before that (stty comes to my mind) ; but then you don't need to write / maintain anything on the PC by yourself and you just write commands from your mcu on the serial TX.