Missing Magn on serial plotter

Hi
Magn is missing on serial plotter, where is the error?

//https://github.com/curiores/ArduinoTutorials/blob/main/BasicFilters/ArduinoImplementations/LowPass/SimpleExamples/butterworth2.ino


int Magn ;

//Ux
float input_voltage = 0.0;
float x[] = {0, 0, 0};
float y[] = {0, 0, 0};
int k = 0;
//Uy
///////
float input_voltage2 = 0.0;
float x2[] = {0, 0, 0};
float y2[] = {0, 0, 0};
int k2 = 0;
/////////////
void setup()
{
  Serial.begin(115200);

  pinMode(PA8, PWM);
  pinMode(PA9, PWM);
  TIMER1_BASE->CCER = (1 << 4) | (1 << 0); //cc1e/cc2e enable
  TIMER1_BASE->CCMR1 = (1 << 13) | (1 << 12) | (1 << 5) | (1 << 4); //toogle mode
  TIMER1_BASE->PSC = 0;
  //TIMER1_BASE->ARR=2879;
  TIMER1_BASE->ARR = 1181 * 2; // 15.2kHz
  TIMER1_BASE->CCR1 = 0 ;
  //TIMER1_BASE->CCR2=1439 ;//
  TIMER1_BASE->CCR2 = 1181 ;
  TIMER1_BASE->CR1 = 1;

}

void loop()
{
  // Ux
  int analog_value = analogRead(PA0); // Ux
  int analog_value2 = analogRead(PA1);//Uy
  //Ux
  input_voltage = (analog_value * 5.0) / 1024.0;
  x[0] =  input_voltage;

  input_voltage2 = (analog_value2 * 5.0) / 1024.0;
  x2[0] =  input_voltage2;
  //Ux
  float b[] = {0.00024132, 0.00048264, 0.00024132};
  float a[] = {1.95558189, -0.95654717};
  y[0] = a[0] * y[1] + a[1] * y[2] +
         b[0] * x[0] + b[1] * x[1] + b[2] * x[2];
  //Uy
  //////////
  float b2[] = {0.00024132, 0.00048264, 0.00024132};
  float a2[] = {1.95558189, -0.95654717};
  y2[0] = a2[0] * y2[1] + a2[1] * y2[2] +
          b2[0] * x2[0] + b2[1] * x2[1] + b2[2] * x2[2];

  if (k % 3 == 0)


    Magn = sqrt(pow((2 * y[0]), 2) + pow(2 * y2[0], 2) );


  {
    
    Serial.print("   Magn =");
    Serial.print(Magn);  
    Serial.print("   Uxf = ");
    Serial.print(2 * y[0]); // Ux filtered
    Serial.print("   Uyf =  ");
    Serial.print(2 * y2[0] + 5); // Uy filtered

    Serial.println();
  }

  delay(1); // Wait 1ms
  for (int i = 1; i >= 0; i--) {
    x[i + 1] = x[i]; // store xi
    y[i + 1] = y[i]; // store yi
  }

  k = k + 1;

  delay(1); // Wait 1ms
  for (int i = 1; i >= 0; i--) {
    x2[i + 1] = x2[i]; // store x2i
    y2[i + 1] = y2[i]; // store y2i
  }

  k2 = k2 + 1;


}

Should this not be

 (k % 3 == 0)

{
    Magn = sqrt(pow((2 * y[0]), 2) + pow(2 * y2[0], 2) );

I changed = no different.

 if (k % 3 == 0)

  {
    Magn = sqrt(pow((2 * y[0]), 2) + pow(2 * y2[0], 2) );

    Serial.print("   Uxf = ");
    Serial.print(2 * y[0]); // Ux filtered
    Serial.print("   Uyf =  ");
    Serial.print(2 * y2[0] + 5); // Uy filtered
    Serial.print("   Magn =");
    Serial.print(Magn);

    Serial.println();
  }

On serial monitor I have it but is missing in serial plotter.

Hi @tom321.

You are using an inconsistent and non-standard data format. It is amazing you are getting anything at all in the plotter.

Try it again after changing your sketch to use a supported data format like this:

Uxf:11,Uyf:42,Magn:123
 {
    //Magn = sqrt(pow((2 * y[0]), 2) + pow(2 * y2[0], 2) );

   // Serial.print("   Uxf = ");
   // Serial.print(2 * y[0]); // Ux filtered
  //  Serial.print("   Uyf =  ");
   // Serial.print(2 * y2[0] + 5); // Uy filtered
    Serial.print("   Magn =");
    Serial.println(33);

   // Serial.println();
 }

serial monitor is printing 33 serial plotter this

You are still not using a supported data format.

Please look very carefully at the example data I provided in my previous reply. If you are having difficulty modifying your sketch to use that format, just let us know exactly where you are stuck and we'll help you out.

Add a space after the =.

Thanks, you solved the problem.

Please note this is not a supported data format. It might happen to work now, but there is no guarantee it will continue to work. In fact, it will not work if you use Arduino IDE 2.x.

Serial plotter requires a space between "=" sign and a value.
So you need edit the line

writing it as:
Serial.print(" Magn = ");

The Serial Plotter data format is documented here:

https://github.com/arduino/Arduino/blob/master/build/shared/ArduinoSerialPlotterProtocol.md#serialplotter-protocol

The first thing I should state is that there are inaccuracies in this documentation. Unfortunately the people who wrote it and accepted it didn't bother to actually verify that the information was accurate. For this reason, it claims support for spaces in label names when in fact such label names were not supported from the very start.

But beyond that detail, other information provided there is sound.

Note that nowhere in the documentation does it mention support for = as a label-value separator. The only supported label-value separator is :

I don't understand why everyone here is so set on using an unsupported format.

Not everyone, but OP only.
The OP is using the incorrect format, but it occasionally works for him.
So it's easier to tell him to add a single space between the "=" and the data than to explain that he's got it completely wrong

I disagree. The code changes required to do it right are utterly trivial. So why not do it right?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.