Go Down

### Topic: stepper motor code +cnc plotter code (Read 11982 times)previous topic - next topic

##### Jun 06, 2011, 07:41 pm
hi, i recently got 2 old scanners ,im planning to use there moving axis to make a pencil plotter like here:http://www.instructables.com/id/Low-Cost-Hobby-Servo-XY-Table/. ive made everything but how should i write an arduino code to control the stepper telling it to move at a certain point on its axis,im using an uln2003a for control.for example to move 10cm or 20cm etc.the stepper is unipolar 5wire,7.5degree per pulse

#1
##### Jun 07, 2011, 09:12 amLast Edit: Jun 07, 2011, 09:14 am by adilmalik Reason: 1
thanks for the reply, i ve seen that tutorial and i have used it to control the stepper motor ,but its just randomly moving i ,want to write the code to tell the stepper to move the stepper head to the furthermost point of its axis,to the middle point etc.should i calculate the number of pulses it requires to move to the furthermost point ??

#2
##### Jun 07, 2011, 10:52 am
thanks again for your reply, im sorry i didnt say it clearly ,by randomly i meant that its moving on the axis but i cant control it with my current code ie move 10cm 20cm etc.But the second part of your answer is very helpful . can u please elaborate ,i have two micro switches which i can put on both sides, but how should i make the code now,should i send a loop of pulses which should stop when the switch gets pressed? and then count how many pulses ,then this would serve as the maximum point and the rest can be calculated???

#### Grumpy_Mike

#3
##### Jun 07, 2011, 01:36 pm
You need to think how you are going to send commands to make it draw. A popular code for CNC machines is Gcode but plotters use HPGL, you need to write an interpreter for the language you want to use.
s to how to get a motor to plot a straight diagonal line, one way is with Bresenham line algorithm http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

An example of my Gcode project is here:-
http://www.thebox.myzen.co.uk/Hardware/CNC_Conversion.html

and there is an open source Gcode interpreter for the Arduino at:-
http://dank.bengler.no/-/page/show/5470_grbl?ref=mst

#4
##### Jun 07, 2011, 02:36 pm
this sounds very difficult . cant i just calculate e.g. that if 200 steps move 50cm, 100 steps move 25cm ,then write a big code to draw smthing??

#### Grumpy_Mike

#5
##### Jun 07, 2011, 04:58 pm
Quote
then write a big code to draw smthing??

Doing this you will always have to write code to draw anything. Most likely you will want to draw something you want, not just random lines. This means the code is even more involved with lots of things to go wrong. Also one downloaded sketch will draw one thing, an making changes to that code to draw just a little bit will be almost impossible.
You want to swap short term gain for long term pain. That's not smart.

#6
##### Jun 07, 2011, 05:44 pm
oh! thanks, now i understand, i was experimenting with a normal arduino program on a single axis and i see ur point now,straight horizontal and vertical lines will be easy ,but drawing cirlces and other complex things will be very difficult and time consuming, so please can you elaborate a bit, so i would have to download a Gcode interpreter then design a code.
thanks!!!

#### Grumpy_Mike

#7
##### Jun 07, 2011, 06:03 pm
Quote
so i would have to download a Gcode interpreter then design a code.

Yes that is probably the easiest route to go.

#8
##### Jun 07, 2011, 07:16 pmLast Edit: Jun 07, 2011, 07:35 pm by adilmalik Reason: 1
thankyou Grumpy mike you have been very helpful
please tell me ,is g code easy to use with the arduino ,to u know of any tutorial that might help me to get started. and can i use gcode with uln2003a???

#### Grumpy_Mike

#9
##### Jun 07, 2011, 07:37 pm
Well you don't use it with the arduino, you use a text editor to create a Gcode file and then some program to sent it to the arduino.
There are programs like inkscape that will allow you to draw stuff on the screen and output a Gcode file ready for your system. So you don't have to actually touch the Gcode.
However you can google for Gcode tutorials if you want.

#10

#### Grumpy_Mike

#11

#12
##### Jun 07, 2011, 07:55 pmLast Edit: Jun 07, 2011, 08:12 pm by adilmalik Reason: 1
thanks but this is for the future . i first have to understand how to use gcode with the arduino , and can i use it with uln2003a
also does grbl have its own hardware?

#### Grumpy_Mike

#13

#14
##### Jun 07, 2011, 09:22 pm
to use gcode to i need to buy its own hardware or can i use uln2003a IC's??

Go Up

Please enter a valid email to subscribe