This page documents some projects using the Arduino prototype board.
One way in which the simple Arduino boards (i.e., no attached SD card or network port) send informaton to the PC is with the console. The terminal sees the input stream on one of the computers COM ports (aka serial port).
Sometimes it is nice to take this data and stream it to a host computer and either save it, or perhaps also do some processing.
The data stream will be re-directed from the COM port to a file and a stream. Note, you can also have data streamed directly to a database. The action section of the script can be replaces with almost anything your want.
# Script assumes COM3 ... the first command lists the available ports# It also assumes a baud rate of 9600 bps, no parity, 8 bits, 1 stop bit
$portList = [System.IO.Ports.SerialPort]::getportnames()
$portList
$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.open()
Start-Sleep 2 # wait 2 seconds until Arduino is ready
$port.Write("93c") # writes your content to the serial connection
$myFile = New-Item "C:\Users\i1kc\Documents\ArduinoLog.txt"try {
while($myinput = $port.ReadLine()) {
# Write the line to the console and the file ...
$myinput# You could do some calculations here, or call other programs
catch [TimeoutException] {
$myinput | Write-File $myFile -Append
}
}
# Error handling code here
}finally {
# Any cleanup code goes here
}
$port.Close() #closes serial connection
Geology Department
http://www.pdx.edu/geology
Copyright © 1994-2015 · K.M. Cruikshank ·
http://geomechanics.research.pdx.edu