Use bash to receive serial input then do some math with said input then send to virtual serial port for another app to read
1
vote
0
answers
282
views
I have an arduino sending me some numbers through serial @9600 baud. Two values seperated by a comma sent every 500ms or so.
cat /dev/ttyACM0
looks like this: 10.5,20.3 with the numbers ranging from -10 to 100. I have an application which receives this information and puts it on a graph for me to visualize. My problem is the application in question lacks the ability to do any sort of math with the values given so I am stuck with what the arduino can send for graphing.
I need to take the numbers and "condition" them so to speak. Better put in pseudocode below:
read value1 //values parsed from serial using comma as a seperator
read value2 //I have no idea how to do that but I know its doable lol
var kwh = 0;
var lastReadTime = systemTimeMillis();
Loop {
var addKwh = (value1 + value2) * 120 * (systemTimeMillis() - lastReadTime)/1000/60/60/1000
kwh = kwh + addKwh
lastReadTime = systemTimeMillis();
echo $value1 + "," + $value2 + "," + $kwh > virtualSerialPortForOtherApplicationToRead
}
Now - I know what you are thinking - why not do the "conditioning" on the arduino? Well I need to be able to reset this value at the end of the day hence the need for system time which is a pain in the butt to pass back to arduino and have it be reliable.
So my thought is to make a bash script that reads the incoming data from the arduino serial stream and "conditions" it as needed and then send the conditioned data to my other application via a dummy serial port. I am pretty much clueless on how to do the virtual serial port part of this whole thing. And my knowledge of bash is also limited so I really appreciate examples. I guess I also have no idea if any of this is possible but I am hoping to find a solution.
Another reason for bash is I will be able to easily also send the conditioned values to a csv for my own use as well.
Thanks in advance!
Asked by 1431
(11 rep)
Nov 1, 2021, 01:52 AM