A bash data logger from multiple arduino's+bug

I thought if I was to have my server do one thing at a time…
Load values from the arduino into a .csv file a text file that can be loaded into a mysql database by a script from multiple arduinos.
I searched and found com ports or seiral ports show up in /dev/USB# in linux /dev/USB0 was my first because I didn’t have any other serial port devices that showed up as USB… FTDI…

But I had the arduino start at 0 and count… but I am missing values… when I select it to it seems to load the value in in time… but maby the arduino loads the com port register before the computer pulls it off…

Or the script does not take a single line it takes 24 lines and only prints the first one?

I was hoping I could have a arduino port /dev/ttyUSB# >> comma seperated list…

could it do this as a background process?

in this format

time stamp, sample1,sample2…

But to do that I would need the program to load the results from one line one sample then put it in a vareable get it from eatch then put them together & print.

If I just pointed it directly would I miss that much data?

#!/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

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

I think the problem is tail will always point to the end of the file and the Arduino is printing significantly faster than you’re logging…

have you thought about how quickly your arduinos are going to give you data to log? I presume its not going to be this quick if reading some real world variable for logging.

Rather than have the arduinos continuously throw data at the pc ( which might get missed ), how about having your pc request data from the arduinos 1 at a time, then get a response, then move on to next arduino.

if getting data at same time is important you could have a trigger pin, send a pulse down it to get all arduinos to snapshot their readings and store until the pc requests the data.

that makes sence… tail gets the end and the arduino is communicating faster than the bash script can pull in.

I wonder if my problem is…- the bash loop taking too long.

  • if so then the reads in order then write to file could possibly work.
  • could creating background process to run eatch input into a output file make it work?
  • then script to run at the end of x size file to format the csv file nicely & output to database mysql.
  • maby I need a PCI bus ads1256 is a 24 bit per sample 30K samples per second A/D converter… :frowning: :-/

might run into problems with file I/O if you’re reading from it at the same time as writing? can you compile the data once you’ve finished reading from the arduinos?

What is it you’re reading and how often?

I am reading 1 ads1256 from 1 arduino then outputing to the serial / usb converter port at the highest speed possible…

I plan to once gizmoforyou sends me the EEG analog to digital converter board 115200 bits per second.
But my example counts
I=0
loop
I++
print I
back to loop

It might make sence to use the logging as a txt file as background processes for eatch arduino or write it in c and compile on GCC with optimisations like it tod bot blog…