Go Down

Topic: Serial Plotter isn't working anymore (Read 665 times) previous topic - next topic

PrSx

Hi everyone,

I made a code to use a mpu6050 accelerometer :

Code: [Select]

#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
}

void loop() {   
  mpu6050.update();
  Serial.print(mpu6050.getAccY()*9.81);
  Serial.print(",");

  if ((millis() / 1000) % 2 == 0) {
    Serial.print(1);
  }
  else {
    Serial.print(0);
  }
  Serial.print(",");
}


At first everything was working fine, I could visualize data from both the serial monitor and plotter but in the last couple of days the plotter stopped showing the data after a few seconds even though I didn't change anything in the code and I can still see my data coming from the sensor on the monitor. Does anyone know how I could fix this?

Here are the details of what I have:
Board: Arduino Nano
Processor: ATmega328P (Old Bootloader)
Programmer: Arduino as ISP

Thanks!

Note: I did try to change (in the IDE) the processor and the programmer but it didn't change the results

pert

I didn't change anything in the code
Are you sure about that? That code never would have worked. Each data set must be followed by a newline. But your code never prints a newline to Serial. So the data is plotted as a single set with an infinite number of elements. To make it work, you need to change the second to last line from:
Code: [Select]
  Serial.print(",");
to:
Code: [Select]
  Serial.println(",");

PrSx

#2
Oct 11, 2018, 01:57 am Last Edit: Oct 11, 2018, 01:58 am by PrSx
OK so I changed
Code: [Select]
Serial.print(mpu6050.getAccY()) to :
Code: [Select]
Serial.println(mpu6050.getAccY()) and it works fine now.

It also works with what you suggested (even a bit better).

Huge thanks to you!

pert

You're welcome. I'm glad to hear it's working now.
Enjoy!
Per

Go Up