Control Arduino GPIO with Windows PowerShell Script

PowerShellGPIO

You can control an Arduino connected to Windows 10 via a USB cable with PowerShell.

Windows 10 provides automatic detection and loading of drivers for Arduino devices. By using a .Net library called Solid.Arduino (https://github.com/SolidSoils/Arduino ) we can control the Arduino IO pins from our script.

Your Arduino should have the StandardFirmata sketch installed (see blog posting https://ianmorrish.wordpress.com/2016/05/21/install-standardfirmata-on-arduino-for-gpio/ )

You can download a pre-compiled copy of Solid.Arduino from

Start PowerShell_ISE.exe and paste in the following code. Update the path to Solid.Arduino to match your location.

You can change the $LEDs array to specify the pins that you have connected LED’s to.

add-type -path ‘C:\Users\imorrish\OneDrive\PowerShell\GPIO\Solid.Arduino.dll’

$connection = New-Object Solid.Arduino.SerialConnection(“COM4”,Solid.Arduino.SerialBaudRate]::Bps_57600)

$session New-Object  Solid.Arduino.ArduinoSession($connection,2000)

Start-Sleep -Seconds 1

$session.GetFirmware()

#Turn on LED’s one by one

$sleepTime 2

[Int[]]$LEDs = 10,11,12,13

ForEach ($led in $LEDs){

 $session.SetDigitalPin($led,$true)

 Start-Sleep $sleepTime

 $session.SetDigitalPin($led,$false)

}

Advertisements

One thought on “Control Arduino GPIO with Windows PowerShell Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s