Arduino Uno Universal Test Machine: Motor Not Moving and Erratic LED Behavior

I have developed an Arduino sketch for a Universal Test Machine (UTM) that controls a stepper motor and logs data from a load cell. The full sketch can be found here GitHub - koenner/Arduino-UTM: Universal_Test_Machine.ino.

Observations:

  • None of the move (forward or reverse) or test (compression or tension) features seem to work. The motor does not move at all.
  • The LED indicators behave somewhat erratically and do not seem to correspond to the expected behavior.
  • The hardware itself is verified to be good. I've performed functional checks on the stepper motor, motor driver, LEDs, buttons, and verified the 3.3V and 5V power lines.

Any assistance in debugging this issue would be greatly appreciated!

post sketch here pls

1 Like

Your first sentence is wrong, you have not developed anything yet, you have a wish list. Show us the following

  1. The code using code tags and do a Tools/Auto Format first.
  2. The serial output again in code tags
  3. A wiring diagram
1 Like

I can see this is your first time posting to the forum and welcome. But you have not helped yourself, here. There is no reason not to post your sketch right there on the forum. I don't see it at your link, anyway.
There is no documentation from you to tell us how you have all the pieces connected. Use a block diagram to identify the pieces, including the power supplies and identify the connections.
A schematic would be nice to verify that you have the necessary resistors and possible capacitors necessary for operation of your machine.

1 Like

I am working on a project using an Arduino Uno R3, but my motor control (at minimum) isn't working correctly. Here is the code I'm using:

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h>

#define PUL_MINUS 0
#define STOP_BUTTON 2
#define REVERSE_LED 3
#define TENSILE_LED 4
#define RED_LED 5
#define COMP_LED 6
#define FORWARD_LED 7
#define DIR_MINUS 8
#define SS_PIN 10
#define FORWARD_BUTTON 14
#define COMP_BUTTON 15
#define TENSILE_BUTTON 16
#define REVERSE_BUTTON 17
#define SDA_PIN 18
#define SCL_PIN 19

NAU7802 myScale;
float calibration_factor = 1.0;

File dataFile;

void setup() {
  pinMode(PUL_MINUS, OUTPUT);
  pinMode(STOP_BUTTON, INPUT);
  pinMode(REVERSE_LED, OUTPUT);
  pinMode(TENSILE_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  pinMode(COMP_LED, OUTPUT);
  pinMode(FORWARD_LED, OUTPUT);
  pinMode(DIR_MINUS, OUTPUT);
  pinMode(FORWARD_BUTTON, INPUT);
  pinMode(COMP_BUTTON, INPUT);
  pinMode(TENSILE_BUTTON, INPUT);
  pinMode(REVERSE_BUTTON, INPUT);

  Wire.begin();
  if (!myScale.begin()) {
    Serial.begin(9600);
    Serial.println("Load cell initialization failed!");
  }
  myScale.setSampleRate(NAU7802_SPS_80);

  if (!SD.begin(SS_PIN)) {
    Serial.begin(9600);
    Serial.println("SD card initialization failed!");
  }
  
  Serial.begin(9600);
}

void loop() {
  if (digitalRead(FORWARD_BUTTON) == HIGH) {
    moveForward();
  }

  if (digitalRead(COMP_BUTTON) == HIGH) {
    performCompressionTest();
  }

  if (digitalRead(STOP_BUTTON) == HIGH) {
    stopAll();
  }

  if (digitalRead(TENSILE_BUTTON) == HIGH) {
    performTensileTest();
  }

  if (digitalRead(REVERSE_BUTTON) == HIGH) {
    moveReverse();
  }
}

void moveForward() {
  digitalWrite(FORWARD_LED, HIGH);
  digitalWrite(DIR_MINUS, LOW);
  while (digitalRead(FORWARD_BUTTON) == HIGH) {
    pulseMotor();
  }
  digitalWrite(FORWARD_LED, LOW);
}

void performCompressionTest() {
  digitalWrite(COMP_LED, HIGH);
  digitalWrite(DIR_MINUS, LOW);
  dataFile = SD.open("testData.csv", FILE_WRITE);
  while (digitalRead(STOP_BUTTON) == LOW) {
    pulseMotor();
    logData();
  }
  dataFile.close();
  digitalWrite(COMP_LED, LOW);
}

void performTensileTest() {
  digitalWrite(TENSILE_LED, HIGH);
  digitalWrite(DIR_MINUS, HIGH);
  dataFile = SD.open("testData.csv", FILE_WRITE);
  while (digitalRead(STOP_BUTTON) == LOW) {
    pulseMotor();
    logData();
  }
  dataFile.close();
  digitalWrite(TENSILE_LED, LOW);
}

void moveReverse() {
  digitalWrite(REVERSE_LED, HIGH);
  digitalWrite(DIR_MINUS, HIGH);
  while (digitalRead(REVERSE_BUTTON) == HIGH) {
    pulseMotor();
  }
  digitalWrite(REVERSE_LED, LOW);
}

void pulseMotor() {
  digitalWrite(PUL_MINUS, HIGH);
  delayMicroseconds(2);
  digitalWrite(PUL_MINUS, LOW);
  delayMicroseconds(2);
}

void logData() {
  float load = myScale.getWeight() * calibration_factor;
  dataFile.print(millis());
  dataFile.print(", ");
  dataFile.println(load);
}

void stopAll() {
  digitalWrite(RED_LED, HIGH);
  delay(1000);
  digitalWrite(RED_LED, LOW);
}

My observations are:

  • None of the move (forward or reverse) or test (compression or tension) features seem to work. The motor does not move at all.
  • The LED indicators behave somewhat erratically and do not seem to correspond to the expected behavior.
  • The hardware itself is verified to be good. I've performed functional checks on the stepper motor driver, LEDs, buttons, and verified the 3.3V and 5V power lines.
  • Serial monitor only produces the text "SD"

PDF of wiring diagram attached.

UTM Block Diagram - 080424.pdf (61.4 KB)

Any help with debugging this would be greatly appreciated!

where you learned how buttons are connected?(but with INPUT_PULLUP will work)
pins 0/1 better leave free
for scale module may need own 3V regulator
better powering arduino over USB or with dedicated 5V PSU

it was to expect: every input pin floats until you press button

1 Like
void pulseMotor() {
  digitalWrite(PUL_MINUS, HIGH);
  delayMicroseconds(2);
  digitalWrite(PUL_MINUS, LOW);
  delayMicroseconds(2);
}

Your function pulseMotor() looks as though it will generate a pulse far too fast for operating a stepper motor.

I decided to do a test to find out how fast the pulses it produces were.

I stripped out most of your code as I don't have your hardware.
This left me with the following minimal code:


#define PUL_MINUS 0
#define FORWARD_BUTTON 14

void setup() {
  pinMode(PUL_MINUS, OUTPUT);
  pinMode(FORWARD_BUTTON, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  while (digitalRead(FORWARD_BUTTON) == HIGH) {
    pulseMotor();
  }
}

void pulseMotor() {
  digitalWrite(PUL_MINUS, HIGH);
  delayMicroseconds(2);
  digitalWrite(PUL_MINUS, LOW);
  delayMicroseconds(2);
}

You are using pin D0 to generate the pulses to drive the stepper motor.

Pin D0 is used by the serial interface.
There were no pulses being generated from pin D0 until I commented out the line:

  Serial.begin(9600);

Using the serial interface prevents pin D0 being used to drive the stepper motor.

With that line removed, the code generated pulses with a frequency of 83kHz.

What is the maximum speed that your stepper motor can run at?

Would I want to move the button non-input pin to ground (instead of 5V) if I use the internal pullup? That way, when I press the button it takes the input pin low. I think I'm learning how to wire buttons.

I think I had a brain-fart while reading microseconds.. it processed in my head as milliseconds. Went ahead and gave it a delay of 1250, which gives me about 6rpm. Together with @kolaha 's feedback to resolve the floating pin issue, the forward, reverse, compression test, and tensile test motor movements are working, and responding to button inputs as intended.

@kolaha I am getting a "Load cell initialization failed!" message, which might be resolved per your suggestion to use a 3V regulator. I'll look into what options are out there later this week (will be away for a few days). Can I ask though, why would the Arduino's 3.3V supply not be good enough?

because Arduino board is a development tool, it contains features to start work with µC, at least check its functionality. i personally don't know what is the purpose of 3V pin on 5V PCB, but 3V used to compare with half voltage from Vin, so USB 5V will be disconnected from board 5V when external power (7-15) connected to barrel or Vin pin. originally LP2985-33DBVR rated 150mA but china clones for sure takes weaker part.

yes, this way you reduce 5V presence on PCB or breadboard and with it possibility of short circuit to something sensitive or GND.

Could I use the 5V supply off of the Arduino Uno (China copy: Elegoo)? It looks like the NAU7802 on board the Sparkfun Qwiic Scale breakout board accepts an input of 2.7V-5.5V.

how arduino is powered?

USB port for now. Goal is just to demonstrate that all the functions are working for now.

In the future I would probably try to use an appropriate (maybe 5V) supply via the coax jack.

? 7-15V ? better take good 5V 2A USB charger

of course. power of USB will be enough

Hmm, the load cell still fails to initialize.. "Load cell initialization failed!"

Checked all of my hardware connections. Continuity is good. Switched input power to the Sparkfun Qwiic Scale "3.3V input" from Arduino 3.3V output to Arduino 5V output.


Do you think that the IDE maybe failed to load the library? I see that the IDE does not recognize the library with an orange color, like it does for the others.

change
"<>" to
grafik

line will turquoise but IDE do its work well anyway and unable to make initialization better

  Serial.begin(9600);
  Wire.begin();
  if (!myScale.begin())Serial.println("Load cell initialization failed!");
  myScale.setSampleRate(NAU7802_SPS_80);
  if (!SD.begin(SS_PIN)) Serial.println("SD card initialization failed!");
 

did you try example?

#include <Wire.h>
#include "SparkFun_Qwiic_Scale_NAU7802_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_NAU7802
NAU7802 myScale; //Create instance of the NAU7802 class

void setup(){
  Serial.begin(115200);
  Serial.println("Qwiic Scale Example");
  Wire.begin();
  if (myScale.begin() == false)  {
    Serial.println("Scale not detected. Please check wiring. Freezing...");
    while (1);
  }
  Serial.println("Scale detected!");
}

void loop(){
  if(myScale.available() == true)  {
    int32_t currentReading = myScale.getReading();
    Serial.print("Reading: ");
    Serial.println(currentReading);
  }
}

Okay, so it has something to do with the driver or driver power supply.

I ran the example and get non-zero readings (e.g. 6241), but once I plug in the driver power supply, while running the serial monitor, the readings will drop to "0", and if I re-establish the serial monitor (close and re-open), I'll get the "Scale not detected. Please check wiring. Freezing..." error message.

The load cell itself (DYLY-103) has an EMI jacket on the cable (containing the 4x wires), which I've plugged into ground, but no change.