powershell and arduino serial communication

After struggling to get a bash script to send data from curl correctly to my arduino over serial I resorted to windows and found that communication over serial can be quickly achieved using the Powershell (the new cmd). I naively assumed it would be easier in linux than windows however the Powershell does seem to be quite a match for bash. I achieved what had taken me hours in Linux in about 10 minutes. The following example code shows the connection to the arduino and how to send data to any serial device This can of course be formed into a more sophisticated script or just run line by line:

$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one #opens serial port - adjust parameters accordingly
$port.open() #opens serial connection
$port.Write("Hello World") #writes your content to the serial connection
$port.Close() #closes serial connection

If you are not sure of the name of your serial ports then you can list them in the powershell:

[System.IO.Ports.SerialPort]::getportnames()

Tags: , , , , , , ,

powershell and arduino serial communication

  1. Klaus says:

    Cool! Exactly what I am trying to do. Setting some DOs in the Arduino using PowerShell. Do you have by any chance a complete example with PowerShell script and Arduino sketch?

    Thanks,

    Klaus

    • chemicaloliver says:

      It’s so long since I did this I don’t have anything left really…sorry. I moved to Linux full time about 2.5yrs ago and haven’t really used windows for anything serious since. The powershell is something that still does intrigue me but not enough to sacrifice the benefits of linux for me.

Leave a Reply