Advertisement
celem

ldrtest.sh

Dec 4th, 2012
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/bash
  2. # Acquire LDR data and plot results from Arduino script ldrtest.ino
  3. # Reads two column data from Arduino into a file, then
  4. # creates a graph using gnuplot
  5. # NOTE: stty raw keeps port open
  6. # Edward Comer - December 2012
  7. #
  8. echo -n "Type device name and press [ENTER]: "
  9. read device
  10. echo -n > ${device}.txt
  11.  
  12. # Toggle DTR to restart Arduino, then set baud=9600 and RAW mode to keep port open
  13. stty -F /dev/ttyUSB0 hupcl
  14. stty -F /dev/ttyUSB0 cs8 9600 raw ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
  15.  
  16. # Read Arduino serial port until text END is received
  17. while read line; do
  18.      if [ "$line" != "END" ]; then
  19.           echo "$line" >> ${device}.txt
  20.       echo "Received $line"
  21.      else
  22.           break
  23.      fi
  24. done < /dev/ttyUSB0
  25.  
  26. # create gnuplot graph of LDR results
  27. echo Plotting $device.txt
  28. gnuplot -e "source=\"$device.txt\"; set output \"$device.png\"" plotscript.gp
  29. echo Graph "$device.png" created
  30. # Display plot on screen
  31. eog "$device.png"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement