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;
}