2

I am very new to the world of raspberrypi and I am probably making some beginner mistakes. I am trying to move a NEMA17 motor (stepper motor) using a Raspberry Pi 3B+ and a4988 driver.

First I set the driver voltage to 12v (since Imax = Vref/(8Rs); Vref=1.5A8*0.1 Ohm ; vref=12v).

So, after this adjustment and measuring it with the multimeter I connected the motor to the driver (Red wire to 2A, Blue wire to 2B, Green wire to 1A, Black to 1B).

I also connected the voltage of 5V (pins 4 y 6) and 12 v after transform it.

Additionally I connected MS1, MS2 and MS3 of the driver with pins 8, 10 and 12 of the Raspberry Pi . Finally I connected pins 38 and 40 of the Raspberry Pi to the step and dir pins respectively.

Something like this:

enter image description here

The code I used is from this page (https://www.iotdesignpro.com/projects/raspberry-pi-stepper-motor-control-through-a-webpage-using-flask) I paste the link to the page as I don't want to overwhelm the reader writting here all the code.

After switching on the transformer the driver gets very hot and the motor makes noises but does not run. I followed all the instructions on the page copied above. What am I doing wrong?

Any contribution will be welcome. Thank you in advance.

I paste photos of the connection:

enter image description here enter image description here enter image description here

enter image description here

14
  • 1
    There are too many possibilities. I suggest you do one thing at a time. Perhaps just a simple program to pulse the stepper? You need to localise the fault(s).
    – joan
    Commented May 14, 2021 at 19:37
  • 1
    And unless you properly anchor the power cable and cover the power connections you may not live to try other methods.
    – Milliways
    Commented May 14, 2021 at 22:11
  • @Adrián P.L., Welcome and nice to meet you. I very much appreciate your very considerate, very concise and yet very detailed question, which is, in short: "How can Rpi3B+ use the A4988 driver to drive a NEMA17 stepper motor? I am thinking to writing up an answer this gloomy, locking down Saturday afternoon. It would be nice if you can let me know the web links to the following: (a) The NEMA stepper motor, (b) The A4988 driver module, (c) the PSU (not too important though). And can I assume that you are using the most update Rpi buster OS? Have a great project. Cheers.
    – tlfong01
    Commented May 15, 2021 at 2:33
  • Before answering a question, I usually search the forum for related questions, to avoid reinventing the wheels. The search results is disappointing: either superficial answers, or generic answers not related to the specific ddriver A4988. This is the search summary: (1) Related Questions on Rpi SE (given by Rpi SE built in search system) (a) 4 rPi2 model B v1.1 smoke comes out near power port, (b) 1 Updated info/software/advice on using Raspberry Pi to control stepper motor drivers, (c) 0 Can this DC Motor Driver feed my RPi?, / to continue, ...
    – tlfong01
    Commented May 15, 2021 at 2:59
  • / cont'd, ... (d) 1 Rpi GPIO Interface L298N DC Motor Driver Troubleshooting Problem, (e) 1 Robot Buggy Not Moving Once Set On Surface, (f) 0 brushless dc motor connection, (2) Search "A4988" found 5 results (a) Which driver for controlling bipolar stepper motor with a raspberry pi? Asked 4 years ago, Viewed 587 times raspberrypi.stackexchange.com/questions/55632/…, / to continue, ...
    – tlfong01
    Commented May 15, 2021 at 3:00

3 Answers 3

1

Question

How can Rpi3B+ use the A4988 driver to drive a NEMA17 stepper motor?


Answer

a4988 test

  1. Introduction

    1.1 Prerequisite knowledge and skills required

    The OP says he is a newbie in Rpi and stepping motor. So I would recommend him to first skim References 1 ~ 4 below, to get a rough idea on stepping motors and drivers.

    There is no hurry to get to know Rpi now, because we will start testing offline, by hand, then by simple 555 timer/signal generator, and only finally by Rpi.


  1. Offline testing of A4988 stepping motor driver and NEMA17 motor in full step mode and DC signal by hand

a4988 module

test wiring


  1. A4899 offline test, using sig gen square wave step pulse, PWM signal for Enable) and ms1, ms2, ms3 microstepping config

stepper motor test


/ to continue, ...


References

(1) A4988 Datasheet – Allergo

(2) A4988 Stepper Motor Driver Module – AliExpress US$0.6

(3) Tutorial on stepper motors (eg, 28BYJ48) and drivers (eg, ULN2003, L293D) - EESE, Asked 2019apr27, Viewed 885 times

(4) Stepping Motors Fundamentals (AN907) - MicroChip

(5) Drive a Nema 17 stepper motor with the RpiMotorLib Python library for A4988 (RpiMotorLib and Flask) - DiyProjects, 2021feb09

(6) A4988 Stepping Motor Driver Q&A (schematic and photos) - tlfong01 EESE, 2021apr14

(7) AliExpress HK42BYG250-001 Stepper Motor NEMA17 | High torque 1.2A 38mm stepper motor for 3D printer 42 with speed feedback - CN¥25

(8) XY-PWM Square Wave Signal Generator (How can Rpi4B python UART talk to XY PWM Signal Generators? - Asked 2019oct20, Viewed 641 times)

(9) Raspberry Pi PWM Generation using Python (Tutorial) - ElectronicWings 2019mar

(10) Raspberry Pi PWM Generation using Python (Demo Program Source Code) - ElectronicWings 2019mar

(11) Control Stepper Motor with A4988 Driver Module & Arduino - LastMinuteEngineers https://lastminuteengineers.com/a4988-stepper-motor-driver-arduino-tutorial/

(12) NEMA Stepper Motors Tutorial - Reprap 2018jan20

(13) NEMA 17 Stepper motor spec - Reprap 2020dec01

(14) NEMA 17 and 28-BYJ48 Stepper Motor Pinout, Wiring Spec - Components 101, 2019aug19

(15) Stepping Motor Step rates - Reprap 2017jun25


Appendices

Appendix A - The A4988 stepping motor driver module used in this answer

(2) A4988 Stepper Motor Driver Module – AliExpress US$0.6

a4988 module


Appendix B - The NEMA17 stepping motor tested in this answer

(7) AliExpress HK42BYG250-001 Stepper Motor NEMA17 | High torque 1.2A 38mm stepper motor for 3D printer 42 with speed feedback - CN¥25

stepper motor 1


stepper motor 2


Appendix C - A4988 Stepping Motor Driver and NEMA17 Stepping Motor Test Schematic

a4988 full step test


Appendix D - 12V 1A PSU for NEMA17 Stepping Motor

psu 12V 1A

/ to continue, ...


1

I've successfully used a Raspberry Pi with an A4988 driver board in order to spin a stepper motor. I've noticed a few differences between what you've done and what I've done, and one of these might be the problem.

Have you connected the nRESET and nSLEEP pins on your A4988 board to anything? Different boards are slightly different from each other, but with the boards that I have, nRESET and nSLEEP both need to be connected to HIGH (3.3v) in order for the motor to spin. If you leave those pins unconnected, then the driver probably won't spin the motor. (The instructions that you linked to say to connect the nRESET and nSLEEP pins to each other, which will probably work for some boards, but probably won't work for your board.)

The VDD pin should probably be connected to 3.3 V, not to 5 V.

I'm guessing that connecting nRESET, nSLEEP and VDD to 3.3 V will fix your problem.

I suggest leaving the microstep pins (MS1, MS2, MS3) unconnected until after you've figured your problems out.

Make sure that the Pi is sending pulses to the STEP pin at an appropriate frequency. A frequency of 100 Hz should definitely produce visible motion. If the frequency is too low, then the motor will turn so slowly that it'll look like it's not turning at all. If the frequency is too high, the motor will vibrate instead of spinning.

If you have a multimeter, then one thing you should try is measuring the output voltages with the motor disconnected. There are 4 pins, which means there are 6 pairs of pins that you can put the multimeter on. If you set the multimeter to measure AC, and you measure while the Pi is sending a 100 Hz step signal, then I think you should see 12 V between 1A and 1B, 12 V between 2A and 2B, and 6 V between any other pair.

Another thing to try is setting the multimeter to measure DC and measuring those pins while the Pi is sending a 1 Hz signal. If you measure between 1A and 1B, or between 2A and 2B, you should see 12 V for two seconds and then -12 V for two seconds, in a repeating cycle. If you measure between any other pair of pins, you should see 12 V for one second, 0 V for one second, -12 V for one second, and 0 V for one second again.

Make sure that the motor is disconnected while you take those voltage measurements.

0

I don't know if this has been solved yet, but I noticed everyone seems to be over looking one glaring issue... The vref setting!!!

"First I set the driver voltage to 12v (since Imax = Vref/(8Rs); Vref=1.5A8*0.1 Ohm ; vref=12v)" ...reads very, very wrong. Another clue is things getting very hot and twitchy, but no control. They're frying their controller and motor...

The vref on the A4988 is to set the maximum current allowed to pass through the motor coils, by means of 'chopping' the waveform (AC like voltage) supplied by the output fets (built into the ic package, this is what is cooking). IT IS NOT IN ANY WAY MEANT TO INDICATE THE VOLTAGE SUPPLY!!! It is simply a voltage reference for the current sensing stage that is measured (typically, and most easily) by using an alligator clip on the screwdriver adjusting the trim pot referenced to ground (clip your positive lead of your multimeter to the metal driver shaft, and the negative lead to ground). This voltage should be in the neighborhood of 0.4-0.8Vdc depending on Imax of the motor. How it got 'set to 12v' is beyond me....

Supposing the coils haven't been cooked, and the output stage hasn't fried itself, first look up your stepper motors maximum current per coil (Imax). Then determine the sense resistors on the driver (there are two variants, possibly more, of the A4988 driver). Measure them if you have to, or use a online decoder to get the value. If they are 0.050ohm Vref=8*Imax*0.050, if they are 0.068ohm Vref=8*Imax*0.068 (notice how the motor supply voltage is nowhere in that equation? That is because it is irrelevant). It seems you want to set the Imax to 1.5A, ergo 8*1.5*(0.05 or 0.068) gives us 0.6V or 0.816V (depending on those sense resistors). Power the logic side of the driver. Connect your screwdriver to your positive lead, negative to ground of the logic power. With your multimeter set to Vdc, turn the trim pot until your meter reads between 0.6 and 0.816Vdc. DO NOT PRESS DOWN ON TO THE TRIM POT, THIS WILL SKEW THE READING. CHECK IT AGAIN WITH A MINIMUM AMOUNT OF PRESSURE TO ASSURE A GOOD READING! Your Vref for the current limiting function is now set. This setting will need to be readjusted if the logic supply voltage changes. The number the trim pot needs to be set at will stay the same, but changing the supply voltage will change what that particular setting of the trim pot reads(its a voltage divider, a lower voltage through the same divider means a lower output reading, ie the divider needs adjusting to output the same voltage as the output of the higher supply voltage). On that note, you're using a RPi, use the 3.3v rail to power the logic side of the driver. That way your logic signals of 3.3v won't be fighting the 5Vdc supply.

One last bit of advice, hot to humans, and hot to silicon are two very different kinds of hot. The chips can get to skin frying temperatures and still function just fine. That being said, electronics (and many other materials used along side them) like remaining as cool as possible. Generating excess heat is a waste of energy (not to mention heat can do funny things to modern atoms wide manufacturing processes circuits, not that these chips are made like that, just strange amazing things in the background of modern computing). Having your drivers set properly will ensure the circuit wastes as little energy as possible. Also, I noticed the drivers chosen were the ones that come with heatsinks, very good call! I hacksawed off a little section of a larger heatsink for mine, and stuck em down with arctic silver thermal paste, then I have a small 12Vdc blower fan blowing straight across them. They are much happier than running naked. And they're only doing 0.7A max current! So try to ensure those things get proper ventilation, or better yet forced air cooling (fan), especially if you're pushing over 1A through them!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.