I moved the print statement to the main loop, controlling it by a state variable set by the ISR instead. After reading the thread I realized that it was a very bad thing to have the Serial.Print() line in the ISR (triggered by a blink from the electricity meter). However, late yesterday night I stumpled upon this thread which is a nice introduction to interrupts. This was the initial reason for this thread as I thought that controlling the data flow with an EOF marker would cure the problem.
I had problems with the sketch somehow getting stuck and I suspected some kind of congestion on the serial port. Pluggy (and all of you): This is very interesting as I am actually working on the same, reading data from my electricity meter. The arduino just sends stuff over and over at 115200 baud. The head and tail and dropping the first part of what s received is incase it ‘joins’ the arduino half way through a transmission. I stop the arduino resetting each time with a 10uF capacitor between gnd and reset.
Rrdtool update /var/lib/chtemp.rrd -t number N:$chtemp Rrdtool update /var/lib/gas.rrd -t number N:$gas Rrdtool update /var/lib/light2.rrd -t number N:$light2 Rrdtool update /var/lib/light.rrd -t number N:$light Rrdtool update /var/lib/temp5.rrd -t number N:$temp5 Rrdtool update /var/lib/temp4.rrd -t number N:$temp4 Rrdtool update /var/lib/temp3.rrd -t number N:$temp3 Rrdtool update /var/lib/temp2.rrd -t number N:$temp2 #rrdtool update /var/lib/temp1.rrd -t number N:$temp1 Rrdtool update /var/lib/avwatts.rrd -t number N:$avwatts Rrdtool update /var/lib/watts.rrd -t number N:$watts Rrdtool update /var/lib/ctadc.rrd -t number N:$ctv #graph -T gif -bitmap-size 800X400 -m 1 /var/www/waveform.gifĮcho $datest $lastarduinotime $lecrevs $gasrevs $chtemp > /root/arduinolog Gasrevs=`cat /root/arduino_bits|cut -d ' ' -f9`Įcho $temp1 $temp2 $temp3 $temp4 $temp5 $chtemp $watts $avwatts $gas > /root/arduinodebug Lecrevs=`cat /root/arduino_bits|cut -d ' ' -f3` Tempp=`cat /root/arduino_bits|cut -d ' ' -f12` Temp1=`cat /root/arduino_bits|cut -d ' ' -f11` Tpvalue=`cat /root/arduino_bits|cut -d ' ' -f21` # touchpad valueĪvwatts=`cat /root/arduino_bits|cut -d ' ' -f22`Ĭtval=`cat /root/arduino_bits|cut -d ' ' -f21`Įcho time $lastarduinotime lasturns $lastturn $prevturn timeperrev $timerev $timerev2 turns $turns watts $watts gasturn $gasturns Prevgas $prevgas Lastgas $lastgasturn gas $gas ctv $ctval $ctv > /root/arduinodebug Watts=`cat arduino_bits|cut -d ' ' -f5|cut -d '.' -f1` Let gas=$ # 111 wh per gas meter turn = 11.1 kWh per cubic metre
Prevgas=`cat /root/arduino_gas|cut -d ' ' -f 25`Įcho $lastgasturn > /root/gasprevioustime Lastgasturn=`cat /root/arduino_gas|cut -d ' ' -f 26` Prevturn=`cat /root/arduino_lec|cut -d ' ' -f 24`Įcho $lastarduinotime $lastminute > /root/arduinodebug
Lastturn=`cat /root/arduino_lec|cut -d ' ' -f 25` Lastarduinotime=`cat arduino_bits|cut -d ' ' -f1` #cat /root/arduino|grep 'WF'|tail -n1 > /root/arduino_wf #cat /dev/ttyUSB5|head -n 2|tail -n 1 > /root/arduino2Ĭat /dev/ttyUSB0|head -n 6|tail -n 3 > /root/arduino # not active for setting upĬat /root/arduino|grep 'LEC'|tail -n1 > /root/arduino_lecĬat /root/arduino|grep 'BITS'|tail -n1 > /root/arduino_bitsĬat /root/arduino|grep 'GAS'|tail -n1 > /root/arduino_gas #stty -F /dev/ttyUSB00 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -clocal Stty -F /dev/ttyUSB00 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -clocal
The bit that deals with the arduino in full : #!/bin/bash What I posted before was just the meat of one of my scripts. If its running from cron, its a effectively a background process. Since Linux is a full multitasking environment, it can do that whilst its doing something else. I use bash scripts running from cron every minute and that then processes stuff to produce these graphs :