Sine Wave Sketch not appearing on Serial Plotter

Does anyone know why the following sketch does not print out on the Serial Plotter?

// y(t) = A sin(wt + p)
// Where A = Amplitide, w = Angular Velocity, t = Time & p = Phase Shift

int t = 0;
float y1;
float y2;
float y3;

void setup() {
  Serial.begin(9600);
  delay(200);
}

void loop() {
  for (t = 0; t < 361; t++){
    y1 = 1 * sin((PI/180.0 * t) + 0);
    y2 = 3 * sin((2 * PI/180.0 * t) + 45);
    y3 = 6 * sin((5 * PI/180.0 * t) + 180);

    Serial.print(y1);
    Serial.print(" ");
    Serial.print(y2);
    Serial.print(" ");
    Serial.print(y3);
    delay(10);
  }

}

The Serial Plotter expects each sample set to be terminated by a newline. In your code you only use Serial.print(), so the output becomes one continuous stream without any record separators.

Try changing the last print statement to:

Serial.println(y3);

instead of:

Serial.print(y3);

You may also find that using tabs ('\t') as separators works better than spaces.

One additional observation: your phase shifts of 45 and 180 are being interpreted as radians, not degrees. If those values are intended to be degrees, they should be converted to radians before being added to the sine argument.

Try
Serial.println(y3);

from post #2

from post #3

@InquisitiveMind

Schoolboy error, many thanks for pointing it out.

I did realise they were in radians but wanted to get the serial plotter working first.

Thank you for the speedy replies, problem solved!

==>
New Line

@InquisitiveMind

How do you use tabs? Where does the ‘ \ t ‘ go?

Don't know if you meant a phase shift of 45° and 180° ?
If so redo the math to properly add degrees before converting to radians.

    y1 = 1 * sin(( t + 0 )  * (PI/180.0) );
    y2 = 3 * sin((2 * (t+45) * (PI/180.0) );
    y3 = 6 * sin((5 * (t + 180) * (PI/180.0) );

Already sorted that, thanks.

The tab character simply replaces the spaces between the values. For example:

Serial.print(y1);
Serial.print('\t');
Serial.print(y2);
Serial.print('\t');
Serial.println(y3);

Both forms work:

Serial.print('\t');

and

Serial.print("\t");

The single-quote version sends a single tab character, while the double-quote version sends a string containing one tab character.

For the Arduino Serial Plotter, a complete sample line would then look something like:

0.12    1.45    -0.87

(where the gaps are tabs), followed by the newline generated by println().

@InquisitiveMind thank you!

You will also want to "print" a minimum (a static value below your traces' minimum) and a maximum (a static value above your traces' maximum) to keep the graph from auto-adjusting and slewing up and down.

// line plotter using constant minimum and maximum values to keep graph from resizing

const int aMIN =  -23;
const int aMAX = 1023;
const int graphoffset = 1000;

unsigned long dTimer, dTimeout = 500;

void setup() {
  Serial.begin(1115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  int a0r = analogRead(A0), a1r = analogRead(A1);
  byte d13r = digitalRead(LED_BUILTIN);
  Serial.print(aMIN); // minimum value data point to plot
  Serial.print(","); // separator between data points
  Serial.print(a0r); // floating value data point
  Serial.print(",");
  Serial.print(a1r);
  Serial.print(",");
  Serial.print(d13r * graphoffset); // plot LED_BUILTIN value
  Serial.print(",");
  Serial.print(aMAX); // maximum value data point to plot
  Serial.println(); // CR/LF sends this set of data points to line plotter

  if (millis() - dTimer >= dTimeout) { // compare "now" to timeout variable
    dTimer = millis(); // reset timer
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); // invert digital reading
  }
}

I have seen the above style in the global space and not in the loop() function! Does this style belong to literate programming?

The variables could be local or global.

Is there really any diffeence between variable definition and function call? I see that int a0r = analogReadd(A0) is a function call service.

Variables assigned for clarity in formatting.

It is just initializing variables and it exists since the C language was developed 50+ yrs ago.
Instead of initializing a variable with a constant or another variable, it is initialized by doing a function call.

Seen it a lot with one variable per line.

int a0r = analogRead(A0), 
    a1r = analogRead(A1);

Also used in for loops with 2 (or more) indices

for (int i = 0; j = strlen(str); i < j; i++, j--)
{
  if (str[i] !=  str[j]) ....
}

Since the statement appears inside the loop() function, I would refer to it as a variable update, in contrast to variable initialization, which is performed only once.

@GolamMostafa
It are local variables which are initialized every time loop() is called again from main()