Message Boards Message Boards

GROUPS:

Read Arduino Serial Monitor sensor that returns CSV data?

Posted 6 months ago
732 Views
|
0 Replies
|
0 Total Likes
|

I am reading a sensor that returns data CSV with multiple real numbers but my code not reading the numbers. I will like to create a graph

dev = DeviceOpen["Serial", {"COM8", "BaudRate" -> 9600}]
(*This is for windows platform port format.Replace COMx with x been \
the port number and budrate same as in sketch*)

data = {};

int = {};

task = RunScheduledTask[
  If[DeviceExecute[dev, "SerialReadyQ"], 
   Module[{csv, raw}, csv = FromCharacterCode[DeviceReadBuffer[dev]];
    raw = Flatten[Cases[ImportString[csv, "CSV"], {_Real}]];
    volt = ToExpression[raw, TraditionalForm];
    data = Join[data, int];]], 2]

(*Print[Dynamic[int]]

Dynamic[ListLinePlot[data]]*)

Sample of data pritned in serial monitor

22,514.00,316.00,1211.00,1013.00,1423.00,358.00

22,514.00,316.00,1210.00,1013.00,1423.00,358.00

22,514.00,298.00,1210.00,1012.00,1423.00,358.00

22,514.00,316.00,1210.00,1013.00,1421.00,358.00

23,514.00,316.00,1210.00,1013.00,1423.00,358.00

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract