That all looks reasonable to me.
You will definitely need a resistor on that LED line, 220R should be fine, that’s ~15mA.
The 10K pot for contrast is likely a little overkill, although fine to start with. I’d probably just adjust it til it looks good then set it with a resistor divider.
I’d usually recommend putting something like a 10nF or 100nF capacitor on the wiper of that pot for adjusting the speed control. Not strictly necessary but it’s always a good idea to have a capacitor or buffer driving analog inputs, otherwise the sampling process can disrupt the voltage that’s being sampled. Not an issue here where it’s just controlling the speed, but it’ll save you scratching your head and wondering why you’re not getting to 100% or 0%, for instance.
DRV8825 setup - There’s technically no issue turning the trim-pot while the board is on, but it pays to be careful and use a plastic tipped screwdriver, as well as being careful while probing. 1A seems like a decent starting point, but I would check to see if the motor heats up while it’s on. If it’s too hot to keep your hand on long term, I’d consider lowering the current. It’ll heat up while on and not turning due to the current still flowing to hold it in place.
I’m not sure about the MS1/2/3 designation for the microstepping. That doesn’t match the DRV8825 datasheet which calls them MODE0/1/2 which the few boards I looked at shorten to M0/1/2. For 1/16th microstepping that’d be M0 = low, M1 = low, M2 = high. For 1/8th microstepping it’d be M0 = high, M1 = high, M2 = low. You can control those with the micro if you want, but given they’re unlikely to be adjusted on the fly I’d just set it to 1/8 or 1/16 by linking them to Vcc or GND, respectively. Either 1/8 or 1/16 will work just fine and I doubt you’d see a difference in usage, it just means that at 1/16 you’d need to be outputting pulses faster from the arduino, which isn’t likely to be an issue at your RPM range.
Arduino code:
The #include is correct.
The comment about the LCD pin connections are correct
The line below that doesn’t look right, to me.
// LCD pin connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
For a start, I’d always do this using #defines for clarity, or better yet a const int. Just using numbers like this makes it harder to self-check.
So:
#define LCD_RS 7
#define LCD_E 8
etc.
Except that I don’t think these pin numbers are correct relative to what’s listed above. I can’t remember how Arduino do their pin numbering, but you’ve got RS on D12 and E on D11. Based on how that is above, I’d say it should be more like:
#define LCD_RS 12
#define LCD_E 11
#define LCD_D4 5
#define LCD_D5 4
#define LCD_D6 3
#define LCD_D7 2
// LCD pin connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
Then there’s the stepper setup. Pins 3 4 and 5 seem reasonable but it’s then using A1 and A2 which isn’t. Those should be called out as digital pins, not analog ones. It has also split the connections up all over the place while not needing to based on hardware.
That step code is also kinda awful, honestly. It’s probably ‘ok’ enough to work, but I would strongly recommend not using floating point maths, I definitely wouldn’t be setting the LCD every step and I wouldn’t want to be generating the step pulses using delays. There’s also no way to turn the stepper off without just cutting power. I had a look and it apparently takes around 10ms to write a full refresh to the display, so you’d never get above a 100Hz pulse rate or ~2rpm.
It’s also kinda weird to have the pot setting the step timing and then back calculating the RPM rather than the opposite, even though the math being used is full heavyweight floating point. Also linearly scaling the step timing leads to a 1/x relationship to your pot, so rpm will increase slower at first and then faster later.
Personally, I’d be looking to do something more like:
const int maxRPM = 200;
const int minRPM = 20;
const int minPOT = 100; // pot position that corresponds to minRPM, below that means off
rpm = map(potValue, 100, 1023, minRPM, maxRPM); // slower to faster
if (rpm < minRPM) rpm = 0;
That’ll take the pot value and give you a target RPM of 0 for the first 10% of the pots range then linearly between min and max RPM for the rest.
From there, I’d be looking at using the Arduino timers and using a timer interrupt to do the stepping or perhaps even the tone() function.
Perhaps try:
int StepHz = 0;
const int stepsPerRev = 3200; // 0.9degrees per step so 400 full steps/rev, 1/8 microstepping.
const int RPMtoStepHz = stepsPerRev/60; // Just gives a single simplified calc and forces this step to be compiled to a constant.
Then in your main loop:
if (rpm == 0)
{
noTone(STEP_PIN);
{
else
{
StepHz = rpm * RPMtoStepHz;
tone(STEP_PIN, StepHz);
}
Which should generate a 50% duty cycle square wave on that pin at StepHz frequency with non-blocking code so you can happily run whatever else in the main loop, like the LCD update.
Tone can’t generate anything below 31Hz, so the minimum rpm in this case would be 0.6rpm. It also looks like the max input is ~32kHz, so 600rpm, which seems reasonable.
Using tone() is a bit of a hack, but the alternative would be PWM or the timer hardware directly, which I’ll leave as a further exercise.
Just a note: I really, really hate dealing with AI produced garbage like this, so hopefully this helps but I won’t be engaging with anything technical and AI produced again. It just wastes too much time vs providing suggestions on how to do it properly straight up.