Coding Help For Shirt Catching Robot

Hi All

I am an operations manager with a small bit of an engineering background and with an upcoming engineering degree that I am going into however my company is looking to get a stepper motor to start moving after a laser trigger is broken. I did do some coding in Highschool with Arduinos however it was a while ago and I am trying to get back into it to try to get this system working so that we can catch shirts from out oven. I am using a Motorshield V2 from HiLetgo(amazon special) on a V3 Arduino Uno.
The code that I had ChatGPT write is posted after this message. I also have the motorshield libtrary installed into the arduion ide.

#include <Wire.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <utility/imumaths.h>
#include <Adafruit_MS_Stepper.h>

// Define pins
const int laserPin = A0; // Analog pin connected to the phototransistor

// Create stepper motor object
Adafruit_MS_Stepper stepper = Adafruit_MS_Stepper(200, 2); // 200 steps per revolution, motor connected to port 1

// Define thresholds and parameters
const int threshold = 500; // Change this value based on your setup
const int stepsPerRevolution = 200; // Change this to your motor's specification
const int stepSpeed = 10; // Speed of the stepper motor (higher is faster)

void setup() {
  Serial.begin(9600);

  // Initialize the motor shield
  if (!stepper.begin()) {
    Serial.println("Motor Shield not detected. Check connections.");
    while (1);
  }

  // Set the speed of the motor
  stepper.setSpeed(200);

  // Set initial position
  stepper.setCurrentPosition(0);
}

void loop() {
  int laserValue = analogRead(1);
  Serial.println(laserValue);

  if (laserValue < threshold) {
    // Laser is broken, move stepper motor
    stepper.step(200); // Move one revolution
    delay(1000); // Optional: delay to prevent continuous movement
  }
}

Welcome to the forum

Do you have a question ?

I Do Sorry, I am trying to mainly figure out why might I be getting compiling errors for the 3rd through 5th lines because currently I am running into the problem where i get an error saying no such directory. I am using IDE 2.3.2 and both the adafruit servo driver and Motorshield V2 libraries are installed however I am still getting the compiling errors

C:\Users\joeyt\Documents\Arduino\Shirt_robot\Shirt_robot.ino:2:10: fatal error: utility/Adafruit_PWM_ServoDriver.h: No such file or directory
#include "utility/Adafruit_PWM_ServoDriver.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: utility/Adafruit_PWM_ServoDriver.h: No such file or directory

#include "utility/Adafruit_MS_PWMServoDriver.h"

Where exactly is this library installed on your PC and how did you install it ?

i Installed it through the IDE itself I am not 100 percent sure where it is on my computer

Which version of the IDE are you using ?

How exactly did you install it "through the IDE" ?

Which OS are you using ?

I am using IDE version 2.3.2
I went to the manage libraries tab and clicked install with the all dependencies
and I am on Windows 11 pro

With the quote marks, it is looking in the local directory, as compared with the angle brackets <> when it looks in the installed libraries.

Typical chatGPT nonsense in that code.

It puts the "Adafruit_PWM_ServoDriver.h" file in the same directory as the sketch, or it gets the error again.

1 Like

Which is NOT a current controlled stepper motor driver, and won't work with most modern low impedance stepper motors. Post a link to the motor you have.
Leo..

I purchased this Stepper motor, https://www.amazon.com/dp/B00EYIFW70?ref=ppx_yo2ov_dt_b_fed_asin_title.
It most likely wont be what I end up with after some review I think I might have to go with a bigger one or end up going with a DC motor that I control through an esc

That 30 Ohm high-impedance Adafruit motor will work with that shield.
Fine for low step rates, but don't expect torque at higher speeds from that motor. For that you need a low impedance motor with a current controlled driver and a 24volt supply.
Leo..

I managed to get the PWM Servo Driver error to resolve itself now the IDE is complaining about the imumaths line of code.

I have also installed the Adafruit_BNO055 library through the IDE as well.

Post the full error message

How was the problem with the PWM servo library resolved ?

One of the other users I showed the code to mentioned that it was not in so it was not searching locally for the library so changing the code to this resolved the compiling problem.

#include <Adafruit_PWMServoDriver.h>