Go Down

Topic: Help with coding  (Read 180 times) previous topic - next topic

SewTech

Hello all,
            I have created a 2 axis machine. For simplicity think standard Y axis and a Z axis. Now I need assistance with the code. Preferably no Grbl or connected computer.

Hardware used:

2 - TB6600 stepper motor drivers
1 24V power supply
4 limit switches
1 momentary button
2 Nema 17 4 wire steppers

What I need is for when power up, Y axis and Z axis should find home switch and hold. Upon press of momentary button, Y axis moves to second limit switch and stops and the same switch should engage Z axis, until Z limit bottom switch engage. I need also to be able to adjust the dwell time here, then the Z axis retracts until home switch is engaged whereupon the Z holds and the Y retracts to home. A press of the momentary switch would start the entire sequence again.
  Basically a pick and place but not quite.

Delta_G

Generally how it works in this section of the forum is you write the code and people help out with it.  IF you have specific questions then those get answers.  If you want someone to write code for you there is another section but most of those folks want to be paid. 

Give it a try and if it doesn't work post the code and describe the symptoms and we will see if we can help you spot the problem. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

DVDdoug

The problem with someone "helping you" is that they can't test the code without your exact hardware setup.  If you write some code and it doesn't work as you expect, then maybe someone can spot the error or give you some debugging/troubleshooting suggestions.

As always, I recommend you take it one step at a time.   

And when you write your code start with the simplest possible program.  Maybe in your case start with the Digital Read Serial Example, and read your pushbutton or one limit switch.   And then add one or two lines of code at a time, test-compiling and test-running as you go-along. 

And it's always helpful  to throw-in Serial.print() statements to "print out" variable values or little messages, like "Running motor 1 clockwise", or "Limit sensed", etc.  Anything to let you know what the program is doing and to make sure it's doing what you think its doing.

You can either work on the input or output first.   Sometimes you need one part working before you can test another part, etc.  Or, you can choose the easy part or the hard part.  If you are unsure about how stepper motors work you might want to play-around with getting a stepper motor to run both directions, etc.

It's not unusual to write some special test-code just to test the hardware.   And sometimes test code is written just to test different parts of the software (especially with larger programs).   And, you're kind-of doing that with those Serial.print statements.

The two most important concepts in programming are conditional execution (if statements, etc.)  and loops  (doing something over-and-over, usually until some condition is reached).   In addition to the Arduino main loop, there are 3 kinds of loops - Do-while loops, while() loops, and for-loops.      Once you understand those concepts you can begin to develop programs.     You can use an if-statement, or maybe an interrupt (both conditional execution) to "do something different" when you hit the limit switch.    And, you could use a for-loop to make your motor step 1000 times.   (Although, some of those details are handled for you by the stepper library.)



Do you have any experience with electronics, and do you have a multimeter?



 

Robin2

#3
Jun 16, 2018, 09:02 am Last Edit: Jun 16, 2018, 09:03 am by Robin2
These links may help you get started

Stepper Motor Basics
Simple Stepper Code

also look up the AccelStepper library or its MultiStepper sibling.

and it is not difficult to write your own acceleration code.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

SewTech

Thank you all for your replies. I do have a multi-meter and a rudimentary knowledge of electronics. I've always been more on the mechanical side of skill sets. I will continue to play around with the coding and post some results. What's the worst thing that can happen, right? I've already let the magic smoke out of one mega!! LOL

Go Up