I am very frustrated with the slow transfer of data from the Arduino serial COM port to the PlotLine[] in dynamic function. In the Arduino Plot Serial, data is drawn instantly. But when connected to WM with USB able, the plots are very very slow. About 10 and 20 to 1 speed. The Arduino code is sending a 6 pair of integers in ASCI format. Any suggestions as to how speed up.
He Arduino sketch is this
#include <Wire.h>
#include "Adafruit_AS726x.h"
//create the object
Adafruit_AS726x ams;
uint16_t sensorValues[AS726x_NUM_CHANNELS];
void setup() {
Serial.begin(115200);
while (!Serial)
pinMode(LED_BUILTIN, OUTPUT);
//inicia y permite la comunicacion con el sensor
if (!ams.begin()) {
Serial.println("could not connect to sensor! Please check your wiring.");
while (1)
;
}
}
void loop() {
//temperature sensor
//uint8_t temp = ams.readTemperature();
//ams.drvOn(); // descomentar esto si quieres usar el led del sensor para hacer medidas
ams.startMeasurement(); //begin a measurement
//permite que el sensor lea la data cuando este disponible
bool rdy = false;
while (!rdy) {
delay(5);
rdy = ams.dataReady();
}
//ams.drvOff(); //descomentar esto si quieres usar el led del sensor para hacer medidas
//lee los valores!
ams.readRawValues(sensorValues);
//ams.readCalibratedValues(calibratedValues);
//Serial.print("{");
//Serial.print("Temp: ");
//Serial.print(temp);
//Serial.print(",");
//Serial.print(" Violet: ");
Serial.print(sensorValues[AS726x_VIOLET]);
Serial.print(",");
//Serial.print(" Blue: ");
Serial.print(sensorValues[AS726x_BLUE]);
Serial.print(",");
//Serial.print(" Green: ");
Serial.print(sensorValues[AS726x_GREEN]);
Serial.print(",");
//Serial.print(" Yellow: ");
Serial.print(sensorValues[AS726x_YELLOW]);
Serial.print(",");
//Serial.print(" Orange: ");
Serial.print(sensorValues[AS726x_ORANGE]);
Serial.print(",");
//Serial.print(" Red: ");
Serial.print(sensorValues[AS726x_RED]);
//Serial.print("}");
Serial.println();
;
}
I have set up Baud speed to very high, but this makes no difference. Here is the Mathematica Notebook
dev = DeviceOpen["Serial", {"COM3", "BaudRate" -> 115200}]
parseData[{val1__, 44, val2__, 44, val3__, 44, val4__, 44, val5__, 44,
val6__}] :=
ToExpression@
FromCharacterCode@# & /@ {{val1}, {val2}, {val3}, {val4}, {val5}, \
{val6}}
parseData[___] := Sequence[]
rawReadings = {}
Dynamic[ListLinePlot[Transpose[parseData /@ rawReadings],
PlotLegends -> Automatic]]
DeviceClose[dev]