Serial issue on Uno R4?

I have a program that executes properly on an Uno R4 when the board is connected by usb to my computer. When I power it by other means however (I've tried both a 10amp switching power supply as well as a barrel connector adapter) it will not run. Does the R4 automatically load something when the usb is connected? Or is it something in my code or setup? I know it's sloppy right now, still cleaning it up.

#include "EasyNextionLibrary.h"  // Include EasyNextionLibrary
#include <SPI.h>
#define SS_M1 11
#define DIR_M1 2
#define PWM_M1 9
#define ENABLE_MOTORS 8
int pwm1;
boolean dir1;


EasyNex myNex(Serial1);  // Create an object of EasyNex class with the name < myNex >
                        // Set as parameter the Hardware Serial you are going to use
  

void setup() {
  myNex.begin(9600);  // Begin the object with a baud rate of 9600
   
  unsigned int configWord;

  // put your setup code here, to run once:
  pinMode(SS_M1, OUTPUT); digitalWrite(SS_M1, LOW);  // HIGH = not selected
  pinMode(DIR_M1, OUTPUT);
  pinMode(PWM_M1, OUTPUT);  digitalWrite(PWM_M1, LOW);
  pinMode(ENABLE_MOTORS, OUTPUT); 
  digitalWrite(ENABLE_MOTORS, HIGH);  // HIGH = disabled

 
  configWord = 0b0000010000001100;

  SPI.beginTransaction(SPISettings(14000000, LSBFIRST, SPI_MODE1));


// Motor 1
  digitalWrite(SS_M1, LOW);
  SPI.transfer(lowByte(configWord));
  SPI.transfer(highByte(configWord));
  digitalWrite(SS_M1, HIGH);

//Set initial actuator settings to pull at 0 speed for safety
  dir1 = 0;
  pwm1 = 255;
  digitalWrite(ENABLE_MOTORS, LOW);
  dir1 = 0;
  pwm1 = 127;
  digitalWrite(SS_M1, LOW);
  digitalWrite(DIR_M1, dir1);
  analogWrite(PWM_M1, pwm1);
}



void loop() {

  myNex.NextionListen();  // This function must be called repeatedly to respond to touch events
                       // from Nextion touch panel.
}

void trigger5()  {
 digitalWrite(SS_M1, HIGH);
}

void trigger4() {
  float breath = myNex.readNumber("n2.val");
  float insp = myNex.readNumber("n0.val");
  insp = insp/1000;
  float expi = myNex.readNumber("n1.val");
  expi = expi/1000;
  float tidal = myNex.readNumber("n3.val");
  float length = tidal/500;
  
  length = length;//*2.3333;
  float timeinsp = length / insp;
  timeinsp = timeinsp * 255;
  float timeexp = length / expi;
  timeexp = timeexp * 255;
  uint32_t myintimer = myNex.readNumber("n0.val");
  myintimer = myintimer * 1000;
  uint32_t myouttimer = myNex.readNumber("n1.val");
  myouttimer = myouttimer * 1000;
  uint8_t speedin = timeinsp;
  uint8_t speedout = timeexp;
  uint32_t breathstot = myNex.readNumber("n4.val");
  uint32_t breaths = 0;
  do {
  dir1 = 1;
  pwm1 = speedin;
  digitalWrite(DIR_M1, dir1);
  analogWrite(PWM_M1, pwm1);
  delayMicroseconds(myintimer);
  dir1 = 0;
  pwm1 = speedout;
  digitalWrite(DIR_M1, dir1);
  analogWrite(PWM_M1, pwm1);
  delayMicroseconds(myouttimer);
  breaths++;
  } while (breaths < breathstot);

}


No

Are you sure that it is not running rather than nothing being displayed on the screen ?

Have the screen and R4 got a common GND connection ?

The code is driving a linear actuator through a multimoto control board hat. It works fine when the usb is connected to the computer, but doesn't move when it's powered elsewhere. And yes, the ground is shared. I've even tried another brand new board to no avail.

Put some LED blink "heartbeat" code in your sketch to see whether it is running

Please post your full sketch, using code tags when you do

Hi, that is my full sketch. There is also a Nextion HMI involved.

Sorry - too many topics and not enough code in most of them :grinning:

Turns out it WAS my ground. Thanks for solving that!

He shoots, he wins !

Obviously it was a guess on my part, but it is a common (or lack of common) problem

Good luck with your project going foward