First off, thanks for taking the time to read this.
I bought a cheap frame for a laser cutter from China and I want to repurpose it, to do so I want to gain control over the stepper motors. It was something like this (it might not be the exact one, but very similar): Link to laser engraving thing
The chip controlling it looks very much like this: Link to chip
So the first thing I did was replace the nano controller and start messing around with it. I quickly discovered I can control the y axis (the axis with two motors, and the first two white connector slots) with pin 3, and reverse the direction with pin 6.
I found that for some reason powering pin 8 disables the movement.
And pin 11 powers the laser (which I disabled first).
But what I cannot seem to figure out is how to power the second stepper motor. The controller chip is a4988, so I expected a single pin to be connected to the step pin, but I cannot figure out which one, or how to enable it.
I looks like the second chip has more ms pins connected. In the documentation for the a4988 I found out that that means micro step, but I suspect this only controls the step size and does not actually take steps, I think this is done by the step pin. But please let me know if I'm wrong.
I tested the device by putting the original nano back on, and it still works, so it's not faulty electronics, just my faulty brain that cannot comprehend what is happening here.
I would really really appreciate any help in understanding what's going on and how I can control the second stepper motor.
I will put up some pictures of the chip as well.
Ps. I don't think it matters, but I'm using the cheap Chinese version of the nano, but I installed the driver and it works for the other stepper motor.
Sounds like the stepper board is Grbl compatible. That means that the X step is pin 2, X dir is on 5. Pin 8 goes the enable pins on the stepper drivers and must be set LOW to enable the motors.
Thanks for your reply, I think you are right. When I follow the lines on the circuit board the direction control seems connected to pin 5, and the other to pin 2.
However, when I put power on pin 2 it does not move. I really don't get it. With the other axis I just put:
analogWrite(3,150);
and that worked (digitalWrite(3,HIGH) does not work), but I tried both, analog and digital write on pin 2, and it does not move.
I put the original chip back on and that does still work, and I tried replacing the nano by another one thinking the pin-2 might be damaged or something, but that also didn't work.
I really really don't understand anymore. Do you have any other ideas?
Is there prehaps a way I can listen in on the other chip, to see which pins it activates when the engine does move?
Thanks again for your help.
Ps. I find the quote in your profile ('it is getting really hot so it must be working') very funny.
Stepper drivers need pulses to step the motor. AnalogWrite() works because it is a pulse train. But the frequency is fixed so the speed will be constant and not easily changed. Google to find out how steppers work.
Here is a tutorial to help you understand how steppers and stepper drivers work. Stepper basics.
Thanks for your help, I now have a much better understanding of stepper motors and I managed to get it working, I'll post my code for anyone else working on something similar.
I know the code is a bit messy, but it works. I put in serial commands: left, right, up down, currentx, currenty and moveyyyxxx
const int stepPinX = 2;
const int stepPinY = 3;
const int dirPinX = 5;
const int dirPinY = 6;
const int movementSize = 200;
signed int currentX = 0;
signed int currentY = 0;
int maxX = 237;
int maxY = 196;
String inputString = "";
bool stringComplete = false;
int delayTimeX = 200;
int delayTime2X = 5;
int delayTimeY = 200;
int delayTime2Y = 5;
void setup() {
Serial.begin(9600);
pinMode(stepPinX,OUTPUT);
pinMode(dirPinX,OUTPUT);
pinMode(stepPinY,OUTPUT);
pinMode(dirPinY,OUTPUT);
}
void loop()
{
if (stringComplete)
{
if (inputString.indexOf("eft") > 0)
{
moveX(2);
}
if (inputString.indexOf("ight") > 0)
{
moveX(1);
}
if (inputString.indexOf("p") > 0)
{
moveY(2);
}
if (inputString.indexOf("own") > 0)
{
moveY(1);
}
if (inputString.indexOf("urrentx") > 0)
{
Serial.println(currentX);
}
if (inputString.indexOf("urrenty") > 0)
{
Serial.println(currentY);
}
if (inputString.indexOf("ove") > 0)
{
Serial.println(inputString);
int yPos = inputString.substring(4,7).toInt();
int xPos = inputString.substring(7,10).toInt();
int deltaX = xPos - currentX;
int deltaY = yPos - currentY;
moveXTimes(deltaX);
moveYTimes(deltaY);
}
inputString = "";
stringComplete = false;
}
}
void moveXTimes(int times)
{
int timeDir = 1;
if ( times < 0)
{
timeDir = 2;
}
for (int t = 0 ; t < abs(times); t++)
{
moveX(timeDir);
}
}
void moveX(int dir)
{
if (dir == 1)
{
digitalWrite(dirPinX,HIGH);
currentX++;
}
else
{
digitalWrite(dirPinX,LOW);
currentX--;
}
bool moveMe = true;
if (currentX < 0)
{
currentX = 0;
moveMe = false;
}
if (currentX > maxX)
{
currentX = maxX;
moveMe = false;
}
if (moveMe)
{
for(int x = 0; x < movementSize; x++)
{
digitalWrite(stepPinX,HIGH);
delayMicroseconds(delayTimeX); //was 500
digitalWrite(stepPinX,LOW);
delayMicroseconds(delayTime2X);
}
}
}
void moveYTimes(int times)
{
int timeDir = 1;
if ( times < 0)
{
timeDir = 2;
}
for (int t = 0 ; t < abs(times); t++)
{
moveY(timeDir);
}
}
void moveY(int dir)
{
if (dir == 1)
{
digitalWrite(dirPinY,HIGH);
currentY++;
}
else
{
digitalWrite(dirPinY,LOW);
currentY--;
}
bool moveMe = true;
if (currentY < 0)
{
currentY = 0;
moveMe = false;
}
if (currentY > maxY)
{
currentY = maxY;
moveMe = false;
}
if (moveMe)
{
for(int x = 0; x < movementSize ; x++)
{
digitalWrite(stepPinY,HIGH);
delayMicroseconds(delayTimeY); //was 500
digitalWrite(stepPinY,LOW);
delayMicroseconds(delayTime2Y);
}
}
}
void serialEvent() {
while (Serial.available())
{
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
Active-low logic inputs are very common, it helps to recognize them.
Often they are written with a line across the top (Boolean algebra style), read out-loud as "enable-bar",though this isn't easy to represent in ASCII, so you also see nENABLE (negated enable) or #ENABLE (same thing).
Back in the days of TTL logic chips almost all signals not on the datapath were active low, and this has stuck
even though CMOS is completely symmetric, especially for resets and enables. Oddly you get #SHUTDOWN,
which is really another way to say ENABLE, and #ENABLE which is basically the same as SHUTDOWN...