element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum Stepper Motor Behavior
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 277 subscribers
  • Views 356 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

Stepper Motor Behavior

Former Member
Former Member over 12 years ago

I have an Arduino Duo interfaced to a Mercury Stepper Motor via an EasyStepper card.

 

My program is simple. It has the motor exercising from 0 steps to 4668 steps, back to 0 and then to -4668 steps. It seems to work fine, except that the motor always seems to do a 2334 step move before starting the move.

 

I am new to the site, and have the sketch for post, but wondered if anyone has any advice.

 

 

  • Sign in to reply
  • Cancel
  • shabaz
    0 shabaz over 12 years ago

    Hi Stephen,

     

    I'm not sure I understand the issue 100%. Also, how quickly are you stepping? Any delays in your code?

    You'd probably need to post the code.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to shabaz

    Here is the code:

     

    This is an exercise routing to basically move the device back and forth over a 270 degree movement. The stepper motor I am using needs 200 steps for a complete rotation (1.8 degrees per step). Through gear reduction, this amounts to 9336 steps per rotation of the device being stepped.

     

    My goal is to be able to start from a known point, and move the device to preselected locations with input through other arduino pins. It seems to do a +2334 step move before starting the loop. I wrote this exercise routine as a starting point, but am perplexed at this unrequested move from the start.

     

     

    #include <AccelStepper.h>

    // Define a stepper and the pins it will use

     

    AccelStepper stepper(1, 3, 2);

     

    int pos = 7002;

     

    void setup()

    {

     

        stepper.setMaxSpeed(500);

        stepper.setAcceleration(200);

        Serial.begin(9600);

        Serial.println("Ready");

         Serial.println("Currently at ");

         Serial.println(stepper.currentPosition());

     

    }

     

    void loop()

    {

      if (stepper.distanceToGo() == 0)

      

       {

         Serial.println("Currently at ");

         Serial.println(stepper.currentPosition());

         delay(500);

         pos = -pos;

         Serial.println("Moving to ");

         Serial.println(pos);

       }

     

      stepper.runToNewPosition(pos);

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • shabaz
    0 shabaz over 12 years ago in reply to Former Member

    Hi Stephen,

     

    I'm afraid I can't see what could be the issue. What happens if you comment out all the content in loop()?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to shabaz

    Commenting out the loop was a good suggestion. When gone, nothing at all moved - as expected - but it caused me to rethink and simplify the sketch. I simpled it down and now everthing works as directed by the sketch. I really don't see a lot of difference in the exectuable statements, but it works now. I'll research the cause later.

     

    Thanks for the idea.

     

    Steve

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube