-1

So I work for a department that uses arduino to move a stepper motor for a wave machine and I am encountering a issue. They gave me the code that they used to use but it doesn't move the motor and just makes this intermittent beeping noise.

My code is as follows:

int pulse_delay = 20;
int wave_period = 1000;

void setup() {
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}

void loop() {
digitalWrite(9,HIGH);
delay(10000);
for (int i=0;i<wave_period;i++)
{
  digitalWrite(8,HIGH);
  delayMicroseconds(pulse_delay);
  digitalWrite(8,LOW);
  delayMicroseconds(pulse_delay);
}
digitalWrite(9,LOW);
for (int i=0;i<wave_period;i++)
{
  digitalWrite(8,HIGH);
  delayMicroseconds(pulse_delay);
  digitalWrite(8,LOW);
  delayMicroseconds(pulse_delay);
  }
}

I do not receive any error messages and the IDE just says upload complete. We use a Arduino Mega board. I am pretty new to Arduino.

Edit: Someone asked for pictures about how it was connected. Sorry for the late response, had a family emergency.

The cable coming in from the bottom is the stepper motor cable

picture of whole board

The cable coming in from the bottom of first picture is from the stepper motor, as is the cable I'm holding but that is what I was told isn't necessary.

8
  • I guess I am asking if there is something missing from the code or if there is something I can add to it to see where the code stops. – thango Jan 28 '20 at 15:20
  • motors need quite a bit of current (more than the GPIO pins can handle), can you describe how you connected the stepper? – ratchet freak Jan 28 '20 at 15:26
  • It has 2. One is I believe a HX2.54 5 pin cable. The other I have no idea, it has a black base and 4 long prongs that stick out but I have been told they didn't need to use those. I will try and ask my supervisor when they come back from teaching. – thango Jan 28 '20 at 15:41
  • We also plug that cable into the arduino board and the board is what is plugged into an outlet. – thango Jan 28 '20 at 16:05
  • Between the Arduino and the stepper motor there has to be a driver circuit. It controls the phases of the motor according to the pulses and the direction pin and provides the motor with the needed power. Please show an image of the circuit, where we can see how everything is connected – chrisl Jan 28 '20 at 18:37
1

Here you can find the manual of your stepper driver.

Look at page in the section "CN3 (I/O signals)". Beside the pulse and directions, that you already set in your code, there are 2 more input signals defined: AWO will turn off the motor completely, if you provide a signal, CS changes the source of the step angle setting. As you don't configure any pins, other than pulse and direction, the other pins on the Arduino are set as input/high impedance. The state of these pins can float wildly depending on what noise is comming by. I don't know, if this really matters for this driver, but you should try to provide a valid state on all the input pins of the driver. For example a floating AWO pin might randomly disable and enable your motor very fast (which would at least fit with the described behavior). Set the corresponding pin on the Arduino as output (via pinMode()) and give them the state, that you want via digitalWrite() (I suggest LOW for AWO to enable the motors and HIGH for CS to get the basic step angle).

I cannot see on your images, if everything is connected to the driver, as it should (here a wiring diagram or a schematic would help). For now I assume, that the signal pins on the Arduino side are connected correctly.

The input signals of the driver are meant to be provided by a pair of twisted wires. This is done to minimize noise on the line. Thus all input signals have 2 pins: "+" and "-". Connect all "-" pins to ground and the "+" pins to the appropriate digital output pin on the Arduino.

If a have a oscilloscope or a logic analyzer, you can also monitor the ALM and TIM outputs of the driver. Maybe they are showing, what is going wrong.

Let us know, if this helps.

0

What are 8 and 9 plugged into on your stepper? also define your baud rate based on the motor requirements.


void setup() {
pinMode(8,OUTPUT); < should be PUL
pinMode(9,OUTPUT); < should be ENA(maybe dir)
digitalWrite(8,LOW);
digitalWrite(9,LOW);
Serial.begin(115200);
}

void loop() {
digitalWrite(9,HIGH);
delay(10000);
for (int i=0;i<1000;i++)
{
  digitalWrite(8,HIGH);
  delayMicroseconds(20);
  digitalWrite(8,LOW);
  delayMicroseconds(20);
}
digitalWrite(9,LOW);
for (int i=0;i<1000;i++)
{
  digitalWrite(8,HIGH);
  delayMicroseconds(20);
  digitalWrite(8,LOW);
  delayMicroseconds(20);
  }
}
6
  • How does this answer the question? What has Serial and it's baudrate to do with the stepper motors? And the function Serial.begin() is with a lower case b. – chrisl Jan 28 '20 at 22:17
  • You.. I tested this code (corrected the SMALLL typo) on a servo I have here and it worked... So? Did you do anything to try and help this person? – chas stevens Jan 29 '20 at 13:49
  • In the 9, LOW for loop I get a wave_period not declared error. – thango Jan 29 '20 at 14:00
  • once again not adding value. – chas stevens Jan 29 '20 at 14:03
  • OK, then I guess I don't know what you want. I posted pictures of what is plugged in and I tried your code. Thanks for your help anyways. – thango Jan 29 '20 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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