Serial Monitor Not Working

Hi!
I am working on a self-stabilizing rocket, but I have encountered some issues. When I try to print anything in the serial monitor, nothing seems to be showing up. This problem occurs after I clear the monitor or when I switch boards (Nano Every to UnoR3)

#include <MPU6050_tockn.h>  //scl =A5 / sda =A4 /vcc =5v / grn =grn
// #include <MPU6050.h>
#include <Servo.h>
// #include <Wire.h>
// Purple orange Arduino
// Blue red 5V
// Green brown Ground

int ledping = 7;  //led pin
int ledpinr = 6;

int buzzer = 5;  // buzzer pin

int servopin1 = 9;  // Servo pin
int servopin2 = 10;
int servopin3 = 11;
int servopin4 = 12;

Servo servo1;  // Servo object
Servo servo2;
Servo servo3;
Servo servo4;

int pos = 0;  //position

MPU6050 mpu6050(Wire);

long timer = 0;

void setup() {
  Serial.begin(9600);
  // Wire.initialize();
  // MPU6050.getRotationX();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);
  servo1.attach(servopin1);  //attach object to pin
  servo2.attach(servopin2);
  servo3.attach(servopin3);
  servo4.attach(servopin4);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.println("Setup");
  Serial.println("init run");
}

void loop() {
  digitalWrite(ledpinr, HIGH);
  digitalWrite(ledping, HIGH);
  digitalWrite(buzzer, HIGH);
  mpu6050.update();
  if (millis() - timer > 1000) {
    Serial.print("angleX : ");  // print
    Serial.print(mpu6050.getAngleX());
    mpu6050.update();
    Serial.print("  angleY : ");
    Serial.print(mpu6050.getAngleY());
    Serial.print("  angleZ : ");
    Serial.println(mpu6050.getAngleZ());
    timer = millis();
  }
  //x-axis / roll
  if (abs(mpu6050.getAngleX()) < 1) {
    servo2.write(90);
    //set to 90 degrees
  }
  servo2.write(90 - mpu6050.getAngleY());  //unstable angle

  if (mpu6050.getAngleX() == 0) {
    servo1.write(90);  //set to 90 degrees
  }
  servo1.write(90 + mpu6050.getAngleY());  //unstable angle

  //y-axis / pitch

  if (mpu6050.getAngleY() == 0) {
    servo3.write(90);  //set to 90 degrees
  }
  servo3.write(90 + mpu6050.getAngleX());  //unstable angle

  if (mpu6050.getAngleZ() == 0) {
    servo4.write(90);  //set to 90 degrees
  }
  servo4.write(90 - mpu6050.getAngleX());  //unstable angle
}

Please tell us that you TURNED ON the serial monitor and you have set it's baud rate to match you code.

Yeah I did that... It still isn't working

Hint: Any changes on the USP will cause the PC to enumerate the USB port, this is by design. Try this link for a good explanation: https://www.reeve.com/Documents/Articles%20Papers/Reeve_USBPortMgmtGuide.pdf You can go to the tool menu and select the correct port.

I tried that, but the Serial Monitor is still not printing anything

Hi @gthemonster. When I'm having trouble with serial output, I like to do a quick check with the most simple possible sketch. If this works, then I know the problem has something to do with my real sketch. If it doesn't work, then I know the problem is not related to my sketch code. It seems maybe a little silly, but it allows me to be sure I'm focusing my troubleshooting efforts in the right direction.

Try uploading this sketch to your Arduino board:

  1. Copy and paste this code as a new sketch in Arduino IDE:
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      Serial.println("hello");
      delay(1000);
    }
    
  2. Upload the sketch to your Arduino board.
  3. Select Tools > Serial Monitor from the Arduino IDE menus to open the Serial Monitor view if it is not already open.
  4. Make sure the baud rate menu at the top right corner of the Serial Monitor panel is set to "9600".
  5. Clear the monitor.

Do you now see the word "hello" being printed in the Serial Monitor's output field once a second?

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