Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

A semi working bash data logger script
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

A semi working bash data logger script

by josheeg on Mon Apr 27, 2009 8:20 am

Hi here is my contribution to the community. A bash data logger but I told the arduino to count and spit it out the port...
My script seems to miss numbers maby the arduino updates faster than my bash loop.
I am running ubuntu desktop that has gnome...
I would like to run this in a server.
The info I built things from were from ...
linuxcommand.com
searching under "/dev/ttyUSB0 arduino"
they showed 2 ways to get a bash script to get data one continuous how can I make that run in the background? Then it could continuously dump to the text file.
Or
Is the line of text that suposidly runs and gets one line from the serial port....
can I not just get one line and print it?

Possible solutions
do in seperate terminal windows logging to different files?
run background process load into text file?
write in c.
different way to take one line in bash?
possible difference in character strings to numerical data..???

Bash SCRIPT
#!/bin/bash
# this is the arduino logger
#hook up 4 arduino's and 4 bash files


echo "the arduino logger v2"

#initilise ports from playground example & form post
stty -F /dev/ttyUSB0 cs8 115200 ignbrk -brkint -icrnl -imaxbel -opost
-onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
noflsh -ixon -crtscts -clocal

#loop
number=0
sline=0

while [ $number -lt 10 ]; do

#get info from port from arduino playground & form post . form post
runs once... >> does not overwrite
#linuxcomand.org Assigning a command's result to a variable
com1=$(tail -f /dev/ttyUSB0|head -n 2|tail -n 1)

#format strings
sline="timestamp , $number, arduino 1, $com1"
echo $sline >> eeg_log.csv
echo $sline

number=$((number + 1))

done

OUTPUT:
timestamp 0 arduino 1 1825
timestamp 1 arduino 1 1845
timestamp 2 arduino 1 1865
timestamp 3 arduino 1 1884
timestamp 4 arduino 1 1904
timestamp 5 arduino 1 1924
timestamp 6 arduino 1 1944
timestamp 7 arduino 1 1964
timestamp 8 arduino 1 1984
timestamp 9 arduino 1 2004


Tod bot C code... attach C to mysql...???
josheeg
 
Posts: 213
Joined: Wed Jan 16, 2008 8:38 am

Re: A semi working bash data logger script

by eil on Wed May 06, 2009 4:07 am

If you're going to run the loop continuously, make sure you add a 'sleep' command so you don't push CPU utilization to 100% with the loop when nothing's happening.

To run an application in the background, just append a '&' to the command line, like:

Code: Select all | TOGGLE FULL SIZE
/usr/local/bin/logger.sh &
eil
 
Posts: 440
Joined: Sun Aug 31, 2008 11:09 pm

Re: A semi working bash data logger script

by josheeg on Wed May 06, 2009 6:34 am

c is how im doing it now bash is mising numbers tod bot blog has info on it search /dev/ttyUSB0 arduino
josheeg
 
Posts: 213
Joined: Wed Jan 16, 2008 8:38 am

Please be positive and constructive with your questions and comments.