This was on my laptop, still can’t find it on my Mac!
src/msgAggregatorWorker.ts
- let discardFirstLine = true;
This was on my laptop, still can’t find it on my Mac!
Issue resolved, many thanks to all who contributed.
Safari on Mac not compatible but will explore on the laptop! Thanks
yes (for good reasons) but it will work with another browser.
Had Macs for about 15 years and have always used Safari. There have been a few incompatibilities but never felt the need to install another browser! What do you mean by good reasons?
See my note in the post I linked
Thank you for the explanation!
It does look good, however although the console showed the data, the graph function would not work. This was using Edge on a Windows 11 Laptop, so not sure what’s going on there!
Just wondering if there is anyway to show the first point where i = 0, which should be zero for the sin and 220 for the cos? All other points after 0 are fine!
For me, it was displaying the first point where i = 0, sin = 0, cos = 220.
Is the problem that the code has started running before the Serial Plotter has opened fully?
Or is it because the screen keeps scrolling and you can't stop it at the right time?
Here is some modified code that waits for a push button (connected between buttonPin and GND) to be pressed before starting to plot.
I've used a for loop so that it only plots a single cycle from 0° to 360°.
Pressing the button again will plot another cycle.
int i = 0;
float ySin;
float yCos;
int buttonPin = 2;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
delay(200);
}
void loop() {
while (digitalRead(buttonPin)) {
// do nothing until button is pressed
}
for (int i = 0; i <= 360; i++) {
Serial.print("_:-250 __:250 "); // Prevent change to Y axis scale by plotter's auto-scaling feature.
ySin = 220 * sin((PI / 180.0) * i);
yCos = 220 * cos((PI / 180.0) * i);
Serial.print("Sin:");
Serial.print(ySin);
Serial.print(" ");
Serial.print("Cos:");
Serial.println(yCos);
delay(1);
}
}
I've got the number of points plotted set to 500, but it still stops after plotting to 360° the first time around.
I don’t think that is the issue as it is only the first point. I will give your code a try and see what happens. Many thanks for taking the time to help me, it is much appreciated.
Definitely missing the first point, tried it on the laptop and the Mac (although is still on 50 points) both miss the first point. Rather odd!!
I tried incrementing by 15 and it is much clearer that the first point corresponds to i = 15.
Yes, I repeated your test and can confirm that it is not plotting the first point at 0°.
When I thought it started at 0°, I think I was influenced by using IDE 1.8.16, which does start at 0°, and also the Serial Monitor.
I've no Idea why it is doing this.
Looks fine apart from the anomaly in the centre!
This is because I was plotting right up to 360°, and then starting again at the next point with 0° - which is obviously the same value printed a second time.
Easily solved by only plotting from 0° to 359°.
Easily solved by only plotting from 0° to 359°.
This still gives the anomaly unfortunately. I can get a perfect first cycle by setting i = -1, subsequent cycles still have the anomaly though. It’s obviously a bug within the Serial Plotter!
The problem can be worked around by adding the following line to your setup function:
Serial.println();
The problem can be worked around by adding the following line to your
setupfunction:
Thank you, it works perfectly!
I'm glad it is working now. Discarding all data received prior to the first newline is actually something the developer of the Arduino IDE 2.x plotter implemented intentionally:
- let discardFirstLine = true;
- // when the serial is real fast, the first line can be incomplete and contain incomplete messages
- // so we need to discard it and start aggregating from the first encountered separator
- let joinMessages = messages.join("");
- if (discardFirstLine) {
- separatorRegex.lastIndex = 0; // Reset lastIndex to ensure match happens from beginning of string
- const separatorMatch = separatorRegex.exec(joinMessages);
- if (separatorMatch && separatorMatch.index > -1) {
- joinMessages = joinMessages.substring(
- separatorMatch.index + separatorMatch[0].length
- );
- discardFirstLine = false;
- } else {
- return {
- datasetNames: [],
- parsedLines: [],
- };
- }
- }
is actually something the developer of the Arduino IDE 2.x plotter implemented intentionally
The workaround is reasonable, and adding a println() before starting dumping stuff out is reasonable.
it would be great if the decision was documented outside the code (with the rationale).
I'm glad it is working now. Discarding all data received prior to the first newline is actually something the developer of the Arduino IDE 2.x plotter implemented intentionally:
Thanks for the info, this is getting beyond my knowledge now but I have something that works.
On my Laptop, I am running IDE 2.3.5 and the addition of the Serial.println() , the sine wave starts on 0,0. On my MAC however, running IDE 2.3.6, I still need to set i = -1 to get the sine wave to start at 0,0
Not sure if it’s IDE 2.3.5 vs IDE 2.3.6 or Windows vs MAC OS, I feel I know what the Apple bashers will say though. ![]()