2:14 AM
0

I am struggling to get my motors to perform the same on each run. The first time I run the program, they will perform the same movement about 8/10 times. The second time I start the program, the movement does not perform the same as the last. It is significantly different. How can I get my motors...

(1) It is not clear what do you mean by "the same exact movement". You need to be more precise. For example, can you tolerate a couple of degrees for a 180 degree movement, (2) It is not clear what do you mean by "decent speed and high torque"? (3) You need to specify more precisely. For example move 180 degrees in one second, or 0.1 second. (4) About the torques, you need to give a spec. Example, is a toy servo Towerpro MG996's of 10kgf.cm good enough for you? Ref: html.alldatasheet.com/html-pdf/1131873/ETC2/MG996R/110/1/…

@tlfong01 I can spare a couple degrees but not much room for that... I need the action to be done in about a second and as for torque I am lifting about 50 grams. I am new to this so adding proper detail is harder for me.

(5) Ah, your updated spec is good enough to start doing experiments. So, let us say, for positioning, the tolerance is 5 degrees for a 180 degree movement, (6) Your updated spec of 50grams is also good, but you need to specify the diameter of the wheel or pulley lefting up the 50g load. For example, if the wheel is 10cm, then radius is 5cm, and the torque is 50gf.5cm, which can be handled by a toy servo or DC motor. (7) The speed of 1 second to do the movement is also OK for toy motors.
(8) Your motor seems to be for high speed applications, such as drilling or racing cards. If you don't need high speed, you can consider a gear motor, which decreases speed, but increases torque.
You might like to skim my answers to motor questions below, to see how I am playing with DC, BLDC, and stepper motors. (9) DC Motor Speed Control using PWM electronics.stackexchange.com/questions/510755/… (10) BLDC Motor Control electronics.stackexchange.com/questions/590373/… (11) DC Motor with encoder electronics.stackexchange.com/questions/566586/…
(12) You might also like to let us know more details of your application, a sketch or a photo would be helpful. Then I can start compiling an answer and upload here.
@Justin Priede: (13) Some more references you might find useful: Always stop the motor at the same position (a) electronics.stackexchange.com/questions/608578/… Always stop the motor at the same position (b) electronics.stackexchange.com/questions/610405/… ESP32 Motor Control Pulse Width Modulator (MCPWM) docs.espressif.com/projects/esp-idf/en/latest/esp32/…
@CoderMike: (14) Yes, so I tried it with a step motor: youtu.be/sJkf4uP4J6c. (15) More details at the end of this chat about using tmc2225 stepping motor driver: chat.stackexchange.com/rooms/134387/….
Now I am using a toy spring balance, and a bag of nuts as load/force to calibrate the stalled torque of the stepper motor I have been testing. My testing plan is summarized below: (a) write a program to move the motor forward and backward between 90 degrees and 45 degrees. Gradually increase the loading, ie, bag of nuts, until the motor can no longer move to the 90 degrees limit. Then do the calculation to get the stalled torque. Below is the video illustrating my plan.: youtu.be/mryE3ayH27o
And by trial and error, I found that the loading of about 88 gram is the loading that the motor can just be able to move to the 90 degrees point. For the weight bigger than that the motor cannot move to the 90 degrees, perhaps 80 or 70 degrees. The radius of the wheel is about 4.5cm. So the stalled torque is 80gf.4.5cm ~= 360gf.cm. I will compile an answer after the OP makes comments or suggestions.

Wow@tlfong01 I cannot thank you enough for the time you are putting into this! I appreciate it more than you know. 50 grams might be causing some misdirection here. That was a guess but it could be fine in terms of experimenting. I have a attachment to my motor that connects to a rectangle of posterboard/cardboard. I am trying to move that flap a tad more than 90 degrees, does not have to be a full 180 degrees to fold a shirt. I am automating this process here: amazon.com/BoxLegend-folding-Clothes-Laundry-flipfold/dp/…
@Milliways the code I have provided works, it is connected to my two motors and interacts with them however I tell them.
I did realize these motors are meant for high speed rather than slow specific movements but I would like to use these if possible rather than buying separate more motors.

@Justin Priede, I agree with you of using the high speed motors in hand. I do have those kind of motor in my workshop. Perhaps I can test them later.
@NomadMaker: Yes, I very much with you that those 9V batteries are no good for testing motors, which might have a big starting current, causing the battery running out very soon.
@Justin Priede: (15) Now I am doing a feasibility study of your DC12V 12000rpm motor, checking out if it can do what my stepper motor can do - moving 180 degrees forward and backward, with a precision of a couple of degrees, using L298N DC motor driver, if possible. (16) My first impression of your AutoToolHome 12V motor, is (a) It is a popular model, (b) well designed, and (c) well documented, / to continue, ...
(17) Some references: (17a) AutoToolHome 6-12V Mini DC Motor High Torque Gear for Traxxas R/C and Power Wheels PCB DIY Electric Drill amazon.com/dp/B01M58POHF (17b) Best Permanent Magnet Motors Buying Guide - GistGear Last Updated: 03/02/2022 gistgear.com/homeimprovement/electrical/permanent-magnet-mot‌​ors
(18) GistGear's long list of motors actually include cheapy stepper motors 28BYJ48 (#13 on the list) which we might also use as a benchmark to compare and contrast with your DC motor.
Your shirt folder project is interesting. So I am googling for a spec: (19) How to Make a T Shirt Folder (Video) - WikiHow 2020sep23 youtube.com/watch?v=7opPALiCqLs&t=3s (20) How to Make a T Shirt Folder (Tutorial) - WikiHow 2021 oct21 wikihow.com/Make-a-T-Shirt-Folder. (21) Ah, locking down lunch time. See you later.
@Justin Priede: "I am trying to move that flap a tad more than 90 degrees,".Actually it is easy to move the flap any degrees: youtu.be/Agk5eDSzpIE.
So I now know how to use a stepper motor to move a flap 180 degrees. However I found the stepper motor is too bulky, and seems not strong because it has no gear. A better choice might be the geared stepper 28Byj48. However, 28Byj48 is unipolar and I need to modify it to become bopolar for my stepper driver. After some consideration, I think I might use a DC motor, as suggested by the OP, but a small version, the geared N20 DC motor. I will also use the L298N, also suggested by the OP.
(22) I am using the N20 gear encoder motor for experiments. If you would also like to try a similar one, I would recommend the following: JGY-370GB Worm Gear DC Encoder Motor 12V 5-128RPM Cover Dustproof Self-Lock Reversible For Automatic Curtain Machinery Parts US16 aliexpress.com/item/….
(23) This worm gear motor is self locking and good for auto home curtain app, but I am not sure if also good for the T shirt folder.

2:14 AM
@tlfong01 Again, I cannot thank you enough for the time you are putting in to help me... as a novice, it is very insightful to see your troubleshooting process and understand how you debug these sort of things.
I have access to a much bigger power supply today during a class which will hopefully give me more reliable results and might be the road to take... I will keep you updated with details of said power supply and how it impacts my code and motors.
If I understand, you are saying DC motors might be able to work for this project? Are you still testing different motors to see which works best? In doing research before I started, I also came across this video which accomplishes the same but in a different way than I would like to do. youtube.com/watch?v=rhWaHSUVGco
He uses a DC motor that seems as powerful as mine... it might provide some useful insight.

Ah, your comments and references are very good. I need to watch the video again before I can give some comments. See you later.

4 hours later…
6:39 AM
I am doing some googling on shirt folder. I skimmed through them and found your youtube video is the most useful.
(24a) Automatic clothes folding machine - Sherry Huang 2019jun13, 12,191 views, 40 subscribers

(24b) How to make a T shirt folding machine - 2016mar21, 359,386 views

(24c) Clothes Folders - BoxLegend, 2020jul17, 41,670 views

(24d) T-SHIRT Folding and Packaging Machine - Speedy-T, 2016sep20 785,022 views

(24e) How to Fold a Shirt - TM Lewin, 2010apr23, 1,637,846 views
I have no idea on which DC motor to use. For this prototyping stage, I will start feasibility study with DC motors with gear and encoder. I am not playing with BLDC motors, because I too little experience (and already fried a couple of those a bit expensive ones).

7:01 AM
And we need to look carefully your motor spec, to get a rough idea of how powerful it is:

7:18 AM
Your motor only weighs 90g and the shaft diameter is only 2.5 mm. My big motors have shaft diameters of 3mm, 4mm, 5mm, and even 6 mm. So I would classify your motor as toy motor grade. Of course it can use a gear box to drive heavy loads, but only slowly.

7:42 AM
I forgot how to use the L298N. So I am reading old posts to refresh my memory.
How to use motor drivers with H-bridge and PWM input, to control direction and speed of DC motors? - EESE 2020jul16 Viewed 2k times
https://electronics.stackexchange.com/questions/510755/how-to-use-motor-drivers-with-h-bridge-and-pwm-input-to-control-direction-and-s

7:56 AM

2 hours later…
10:13 AM
Now I am assembling the N20 + L298N module.

10:27 AM
And I found the Last Minutes Engineers have a very newbie friendly tutorial and pinout.

2 hours later…
12:39 PM
Now I am using a scope to display the N20 quadrature encoder output signals A, B, when motor power is 12VDC. I found motor speed is about 56 rpm (3,333pps).

2 hours later…
2:29 PM
I also noticed we can use PWM - Pulse width modulation to control speeds and perhaps influence torque. I am not sure if it is needed

2:41 PM
Ah, (1) I am sure that for DC motor using L298N, PWM frequency does not affect speed, but duty cycle does, because more current flows each cycle. On the other hand, for stepper motor and stepper motor controller, step pulse frequency does affect speed, higher frequency means higher speed.
(2) But I have not been paying much attention to the relation between torque and frequency, because I know that if I don't have enough torgue, I would get a stronger motor, or increase gear ratio, sacrificing speed, which is not critical in my Micky Mouse projects. Ah, bed time. See you tomorrow.

4 hours later…
6:22 PM
That all makes sense... Hope you sleep well. I know I have thanked you a few times but I wanted to thank you again. I cannot believe someone would give so much time to a stranger. You are helping me out more than you know.