Giga powered by Vin doesnt run sketch properly

I have a project that is tried and true that runs a linear screw and has a few sensors and an endstop. The first and very important thing it does is runs towards the endstop and set ZERO.
Everything works great while powered by the usb port. I have a regulated switching power supply and no matter what voltage I set it at. 6v 9v 12v it doesnt run my sketch properly goes in the opposite direction of my endstop. I am considering setting my power supply at 5v and feeding that into the 5v rail. Anyone else experience script not running correctly while using Vin?

UPDATE: Possible or Partial Solution below....
By doing the following steps I was able to get 80% function from my project Vin power compared to USB-C. There are still some differences but at least they are not firing my laser trying to burn a hole in the labs bench top at the wrong time or trying to slam my tooling by going the wrong direction.

UPDATE: After about 50 cycles the bug returned running the linear rail the wrong direction. Burned up my stepper driver, fired the laser ruining my tooling and destroyed itself.

Vin power issues possible fix.
Install/Update the latest core version of Arduino Mbed OS Giga Boards: In Arduino IDE go to Tools > Board > Boards Manager and search ‘Giga’. Install/Update Arduino Mbed OS Giga Boards
Burn the bootloader on GIGA R1 WiFi

Update Wi-Fi firmware on GIGA R1 WiFi

To reinstall he latest connectivity firmware and TLS certificates: Reset the flash memory on STM32H747-based devices
Please follow the next guide to test the I2C: https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet/ 

https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet/

Is it stuck waiting/looking for a Serial port that it's never going to find?
Post your setup()

trying to get it to post correctly

void setup() {
    Serial.begin(115200);
    Serial.println("System initializing...");

    // Initialize USB mass storage
    Serial.println("Connecting to USB...");
    while (!msd.connect()) {
        Serial.println("Waiting for USB memory...");
        delay(1000);
    }
    Serial.println("USB memory connected. Mounting...");
    if (usb.mount(&msd) != 0) {
        Serial.println("Failed to mount USB. Halting.");
        while (true);
    }
    Serial.println("USB mounted successfully.");

    // Attempt to read configuration file
    readConfigFile();

    // Initialize motor pins
    pinMode(ENABLE_PIN, OUTPUT);
    pinMode(END_STOP_PIN, INPUT_PULLUP);
    pinMode(SW1_MODE_PIN, INPUT); // Mode switch: HIGH = RUN mode, LOW = LASER mode
    pinMode(LDR_PIN, INPUT);
    digitalWrite(ENABLE_PIN, LOW); // Enable the motor driver

    // Initialize motor settings
    stepper.setMaxSpeed(MAX_SPEED);
    stepper.setAcceleration(ACCELERATION);
    stepper.setMinPulseWidth(MIN_PULSE_WIDTH);
    stepper.setPinsInverted(true, false, false); // Invert direction if needed

    // Initialize the LCD
    Wire.begin();
    int lcdStatus = lcd.begin(16, 2);
    if (lcdStatus != 0) {
        Serial.print("LCD Initialization failed. Status: ");
        Serial.println(lcdStatus);
        while (true); // Halt execution on LCD initialization error
    }
    lcd.backlight();
    lcd.setCursor(0, 0);
    lcd.print("System Starting...");
    delay(2000);
    lcd.clear();
    lcd.print("LCD Initialized!");
    Serial.println("LCD Initialized Successfully");

    // Initialize the laser
    laser.begin();
    Serial.println("Laser initialized.");

    // Initialize DAC for conveyor trigger  
    pinMode(DAC_PIN, OUTPUT);  
    Serial.println("DAC initialized for conveyor trigger");

    // Display splash screen and home the motor
    displaySplashScreen();
    loadKey();
}

I saw your Deletion.
You're "whiling"/waiting for some USB action. That's where it's stuck, yes?

when powered by vin it sends my linear rail the wrong direction I have to power it down before it slams the the rail against the housing. Everything works perfectly under usb power. This is bizarre to me. I thought the only difference is there is a buck converter dropping the voltage to 3.3 and 5. Seems something else is going on.

Maybe g00gle translate is coming up short.

It'll be stuck there till the msd.connect becomes true.

I just dont understand why this would work differently when powered by the usbC as opposed to the Vin. I have a usb memory card in the other usb with config files on it and I am not waiting for anything.

What's all this? The linear rail in the wrong direction and slamming the rail against the housing? Maybe it's slang or something.

I am telling you my sketch controls a liner screw. When it starts up it is supposed to move in the direction of the endstop and set zero. and it does this when powered from the usbC connection. When I power the Giga board with the Vin connection is doesnt operate like it is suppose to and goes in the opposite direction. I have to quickly stop it as a screw is only so long and it will crash the rail against the housing of the linear rail. I see the block diagram. I have seen it before and I dont see any logical reason as to why the power source should make any difference as to how a sketch is executed.

Is that true whether the power source is your PC or a "power cube" ?

yes

Welcome to the Arduino forum.

Can you provide us with a diagram over the devices you have and how they are connected? It's hard to give help based on imagination.

Usually they do, but I'm open minded, so please show your setup. The sketch / script as you call it, will also be nice to have a look at.

I posted my setup above. Its odd there is a difference between Vin and USB-c power but there is. I am going to add some delays in my script to see if it helps. This is for a robot I am building I prefer not to share all the code at this time. Thanks

Yes to a certain extent. I'm talking about a diagram / schematics over your hardware, and how it's wired. If this is new to you, we can give you advice, just ask. :cowboy_hat_face:

I cant share that at this time. So strange as long as the Giga has been out and this issue hasnt been brought up. I wrote about 1500 lines of code and created a few custom libraries. This robot controls a laser has several built in safety features. Pulls config files off of the usb, logs operations in files on the usb, opens up a wifi connection connects to my smtp server and sends error status and operation complete messages. I spent all the time developing the system debugging all the issues as they came up connected to the pc via the usbc and that is how I was powering the Giga. Now when I am ready to run it standalone I find there is a difference powering it from Vin. Looks like some timing delays sprinkled in here and there may or may not solve the issues. I am not doing anything timing critical. It initializes the stepper controller checks the light level on an LDR uses mbed to open and read files from the usb memory stick. First physical thin it trys to to I have to pull the plug cause it sents the linear rail away from the endstop. Very bad cause at that point it doesnt even know where zero is yet. I dont know if anyone can help me if no one is experiencing differences between being powered from the usb-c and the Vin.

Hi @dysonian What version is your GIGA? You can find its version stamped on the underside of the board, next to the hole nearest the antenna.

I have 3 GIGA boards, a V1, two V1.4. None exhibit the behaviour you see with yours, however, my V1 board does have an odd quirk - it won't boot the M4 core until a write is made on the second I2C bus. The other two don't require this.

If yours is a 1st edition, it is possible that it too has a quirk. I would raise a case with Arduino support, consider buying a new board for your production model and relegating (if not RMAd) your current board to development.

p.s. one thing I would try is using a different ground pin when powering thru VIN


Steve I was beginning to wonder if anyone was going to come up with an more plausible answer than blaming it on me my code or assuming I dont know what I am doing. Indeed it is a V1! It seems a common trend on the forms here lots of assumptions. Including you. Steve I really appreciate your response and hopefully it will work properly when I swap out this V1 board with one of the other 7 boards I have 6 are still unopened but the one here I am looking at says v1.6. I have never powered it up. I will swap it and flash it with my sketch and see if there is any difference. Thanks you

I swapped to a v1.6. Malfunctions the same. Still works perfectly powered off of the usb-c. Tried different grounds. Added delays all over the place same... I tried a pull up resistor on the direction pin to force it and I get the same result yet the usb-c always functions properly.

That's disappointing. If you add a while(!Serial) in setup, power by VIN and then connect usb-c, any different?

Also, which pin are you using that sets the direction?

I would also try commenting out all the Serial prints and see what effect that has.

Good idea I will try this...

void setup() {  
    delay(3000);  
    Serial.begin(115200);  
  
    // Wait for Serial connection with a timeout  
    unsigned long startTime = millis();  
    const unsigned long timeout = 5000; // 5 seconds timeout  
  
    while (!Serial && (millis() - startTime < timeout)) {  
        ;  // Do nothing, just wait  
    }  
  
    if (Serial) {  
        Serial.println("Serial connection established.");  
    } else {  
        // Optional: Print a message to indicate no serial connection  
        // (this won't be visible unless Serial is later connected)  
        Serial.println("No Serial connection. Proceeding...");  
    }  
  
    Serial.println("System initializing...");  
     
}