#!/bin/bash
# Acquire LDR data and plot results from Arduino script ldrtest.ino
# Reads two column data from Arduino into a file, then
# creates a graph using gnuplot
# NOTE: stty raw keeps port open
# Edward Comer - December 2012
#
echo -n "Type device name and press [ENTER]: "
read device
echo -n > ${device}.txt
# Toggle DTR to restart Arduino, then set baud=9600 and RAW mode to keep port open
stty -F /dev/ttyUSB0 hupcl
stty -F /dev/ttyUSB0 cs8 9600 raw ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
# Read Arduino serial port until text END is received
while read line; do
if [ "$line" != "END" ]; then
echo "$line" >> ${device}.txt
echo "Received $line"
else
break
fi
done < /dev/ttyUSB0
# create gnuplot graph of LDR results
echo Plotting $device.txt
gnuplot -e "source=\"$device.txt\"; set output \"$device.png\"" plotscript.gp
echo Graph "$device.png" created
# Display plot on screen
eog "$device.png"
Comments