Load Cell and Stepper Motor Control

I am currently working on a project that requires me to use a motor with an attached arm to displace a control surface on an airplane. The motor is attached to the stabilizer, and at the opposite end of the arm there is an assembly containing a ball joint, load cell, and clamp. I am trying to run code so that I can displace the motor a certain distance (about 5-10 degrees) and have the load cell reading the force on the trailing edge at each step. I am using a nema 23 stepper motor (200 steps/rev, 1.8 degrees/step) with a built in 47:1 planetary gearbox. I am using an arduino uno and a dm542T driver, as well as the HX711 amplifier for the load cell. I am assuming I need a loop but not entirely sure how to do so. My code is below, I appreciate any advice to help me output the data simultaneously.

#include <Arduino.h>
#include "HX711.h" 
#include <AccelStepper.h> // Include Load Cell Amplifier, Arduino Board, Stepper Motor libraries

HX711 scale; 

// Initialize pins for stepper motor 
const int stpP = 9;
const int dirP = 8;

// Initialize pins for load cell amplifier
const int LOADCELL_DOUT_PIN = 3;
const int LOADCELL_SCK_PIN = 2;

// Steps per revolution, degree per step
int stepsPerRevolution = 200; 
float degreesPerRevolution = 1.8; 

AccelStepper stepper(AccelStepper::FULL2WIRE, stpP, dirP); 
void setup() {
  Serial.begin(9600); // Initialize Serial Monitor 
  
  // Set initial parameters for stepper motor 
  stepper.setMaxSpeed(200);
  stepper.setAcceleration(100); 
  stepper.setSpeed(200); 

  // Start moving stepper motor to set number of degrees
  stepper.moveTo(degToSteps(90));

  // Initialize load cell/load cell amplifier 
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);

  // Set scale to zero to begin
   scale.tare(); 
   scale.set_scale(21.5891); // calibrate load cell 
  
}

void loop() {
  long reading = scale.get_units(20);
  Serial.print("Result:");
  Serial.println(reading);
  stepper.run();  // move motor 
  

}

float degToSteps(float deg) {
return(stepsPerRevolution/degreesPerRevolution)*deg;
}

It sounds like a math matter higly dependant om the mechanical arrangement.

Does the controller board for the stepper also attach to the stabilizer or are there a bunch of wires going to the stabilizer? I think you need to revise your description! I suspect you need to displace the control surface, not the motor.

Yes, I apologize for ambiguity. The motor driver,
motor, power supply all sit on the stabilizer, with the arm connecting to the trailing edge of the control surface. I am in fact trying to displace the control surface. Ideally, the motor would move the surface ~ 5 degrees up, return to zero, ~ 5 degrees down, and return to zero again.

Additionally, there should be a simultaneous load cell reading for each step of the motor.

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