Serial plotter not working

I wanted to display the output signal waveform live in the serial plotter but it does not shows maybe I have something missing in my code .

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
String UID = "94 5C 78 13";
byte lock = 0;
byte readCard[4];
byte a = 0;

Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  servo.write(70);
  lcd.begin();
  lcd.backlight();
  servo.attach(3);
  SPI.begin();
  rfid.PCD_Init();
}

void loop() {
  lcd.setCursor(4, 0);
  lcd.print("Welcome!");
  lcd.setCursor(1, 1);
  lcd.print("Put your card");
  
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scanning");
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    lcd.print(".");
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
    
  }
  ID.toUpperCase();

  if (ID.substring(1) == UID && lock == 0 ) {
    servo.write(70);
    lcd.clear();
    
    delay(1500);
    lcd.clear();
    lock = 1;
    //if (ID.substring(1) == UID && lock == 1 ) 
    servo.write(160);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door is open");
    lcd.setCursor(1, 1);
    lcd.print("for a while");
    delay(1500);
    lcd.clear();
    lock = 0;
    delay(1500);
    servo.write(70);
   }
   else {
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("Wrong card!");
    lcd.setCursor(1, 1);
    lcd.print("Door is locked");
    delay(1500);
    lcd.clear();
    Serial.println(F("Scanned UID:"));
    String ID = "";
  for ( uint8_t i = 0; i < 4; i++) {  //
    readCard[i] = rfid.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    Serial.print(" ");
    delay(500);
    a += 3;
  }
   Serial.println("");
   rfid.PICC_HaltA();
   lcd.clear();
    
  }
}

what does the serial monitor display?

2 Likes

there's no display in serial plotter but in serial monitor the scanned UID is printed. I want to display the waveform on plotter

you cannot mix normal text output and plot data when attempting to plot - the text corrupts the plot
comment out the serial.print() statements such as "RFID = XXXXX"
just transmit numeric data to be plotted,
e.g. Serial.print(X); Serial.print(' ');Serial.println(Y);

1 Like

okay, i get it now, so I will make again another separate code ? can you show me how to do that

if you do a web search for arduino serial plotter you will find plenty of examples

i dont know how to place this in code .. i really need help asap

this plots sine waves

/*
 * Created by ArduinoGetStarted.com
 *
 * This example code is in the public domain
 *
 * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-serial-plotter
 */

void setup() {
  Serial.begin(115200);
}

void loop() {
  for(int i = 0; i < 360; i += 5) {
    float y1 = 1 * sin(i * M_PI / 180);
    float y2 = 2 * sin((i + 90)* M_PI / 180);
    float y3 = 5 * sin((i + 180)* M_PI / 180);

    Serial.print(y1);
    Serial.print("\t"); // a space ' ' or  tab '\t' character is printed between the two values.
    Serial.print(y2);
    Serial.print("\t"); // a space ' ' or  tab '\t' character is printed between the two values.
    Serial.println(y3); // the last value is followed by a carriage return and a newline characters.

    delay(1);
  }
}

serial monitor output

0.00	2.00	-0.00
0.09	1.99	-0.44
0.17	1.97	-0.87
0.26	1.93	-1.29
0.34	1.88	-1.71
0.42	1.81	-2.11

serial plotter output
image

2 Likes

You can mix text and data like:

RFID:1234 X:456 Y:789

and the plotter will use the text as labels for the legend and hover-over popups per:

2 Likes

Hello sir, can you show me how to display it's output signal. I really need it today :pleading_face:

@janeshle do this:

  1. Carefully read every post in this forum topic again. Make sure to try the example sketch horace shared on your own Arduino board to prove to yourself that you can use Serial Plotter with a sketch that produces output in the correct format.
  2. Carefully read the documentation page DaveX linked. Make sure to try the example sketches that are shared there.
  3. Use what you learned from reading those things to make your best attempt at correcting your own sketch.

After that, if you still have any questions or problems, come back here with the following things:

  • Your updated sketch
  • A detailed description of any specific problems or questions you might have

I tried to upload your code in my Arduino it works the serial plotter display the sine wave . But Im having trouble displaying my output signal using RFID

I have tried those code and it work but I'm having trouble displaying my output signal with rfid

What output signal waveform?

How do you read the output signal waveform into the Arduino?

1 Like

the output signal frequency generated by the circuit that I made with RFID

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9
#define SS_PIN  10
byte readCard[4];
byte a = 0;


MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  
  while (!Serial);
  SPI.begin();
  mfrc522.PCD_Init();
  delay(4);
  mfrc522.PCD_DumpVersionToSerial();
 
}

void loop() {
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return 0;
  }

  
  
  a = 0;
  Serial.println(F("Scanned PICC's UID:"));
  for ( uint8_t i = 0; i < 4; i++) {  
    readCard[i] = mfrc522.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    Serial.print(" ");
    delay(500);
    a += 3;
    RFID:1234; X:456; Y:789;
  }
  Serial.println("");
  mfrc522.PICC_HaltA();
  return 1;
}

Is this correct? I try to read its output first without the LCD and servo only RFID and arduino

#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
String UID = "94 5C 78 13";
byte lock = 0;
byte readCard[4];
byte a = 0;

Servo servo;
LiquidCrystal_I2C lcd(0x27, 16, 2);
MFRC522 rfid(SS_PIN, RST_PIN);
//MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  servo.write(70);
  lcd.begin();
  lcd.backlight();
  servo.attach(3);
  SPI.begin();
  rfid.PCD_Init();
  
  delay(4);
  rfid.PCD_DumpVersionToSerial();
  
}

void loop() {
  lcd.setCursor(4, 0);
  lcd.print("Welcome!");
  lcd.setCursor(1, 1);
  lcd.print("Put your card");
  
  if ( ! rfid.PICC_IsNewCardPresent())
    return;
  if ( ! rfid.PICC_ReadCardSerial())
    return;

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Scanning");
  String ID = "";
  for (byte i = 0; i < rfid.uid.size; i++) {
    lcd.print(".");
    ID.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
    ID.concat(String(rfid.uid.uidByte[i], HEX));
    delay(300);
    
  }
  ID.toUpperCase();

  if (ID.substring(1) == UID && lock == 0 ) {
    servo.write(70);
    lcd.clear();
    delay(1500);
    lcd.clear();
     Serial.println(F("Scanned UID:"));
    String ID = "";
  for ( uint8_t i = 0; i < 4; i++) {  
    readCard[i] = rfid.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    Serial.print(" ");
    delay(500);
    a += 3;
  }
    lock = 1;
    servo.write(160);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door is open");
    lcd.setCursor(1, 1);
    lcd.print("for a while");
    delay(1500);
    lcd.clear();
    lock = 0;
    delay(1500);
    servo.write(70);
   }
   else {
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("Wrong card!");
    lcd.setCursor(1, 1);
    lcd.print("Door is locked");
    delay(1500);
    lcd.clear();
    Serial.println(F("Scanned UID:"));
    String ID = "";
  for ( uint8_t i = 0; i < 4; i++) {  
    readCard[i] = rfid.uid.uidByte[i];
    Serial.print(readCard[i], HEX);
    Serial.print(" ");
    delay(500);
    a += 3;
  }
   Serial.println("");
   rfid.PICC_HaltA();
   lcd.clear();
    
  }
}

I do not see how that code would produce this legend:

Maybe try switching to the serial monitor and showing what output prints there.

For the serial plotter to graph sanely, each line should be either just numbers, or prefixed integers like:

X1:15 X2:77 X3:90
X1:16 X2:78 X3:91
X1:15 X2:77 X3:90
X1:14 X2:76 X3:89

If you want this chunk to plot 4 traces:

...you might write it as:

   for ( uint8_t i = 0; i < 4; i++) {  
    readCard[i] = rfid.uid.uidByte[i];
    Serial.print("byte");
    Serial.print(i);
    Serial.print(":");
    Serial.print(readCard[i], DEC);
    Serial.print(" ");
    delay(500);
    a += 3;
  }

...to emit data like:

byte0:12 byte1:34 byte2:56 byte3:78
byte0:12 byte1:34 byte2:56 byte3:78
byte0:12 byte1:34 byte2:56 byte3:78
byte0:12 byte1:34 byte2:56 byte3:78
byte0:12 byte1:34 byte2:56 byte3:78
...

with the byte0...byte3 legend labels. But if you mix in lines with different formats, it will confuse the plotter.

Your graph shows a mix of odd legend text and three square wave looking traces. I guess that if you looked at the Serial.print(...) output in the Serial Monitor, you'd have a mix of line formats. Maybe a header line with the strings in the legend, then some alternating 3-value lines with what shows up on the plot .

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