Electronic Dividing Head using the Arduino

Discussion in 'Software and Programming' started by cfellows, May 21, 2012.

Help Support HMEM by donating:

  1. Jul 28, 2013 #81

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    The LCD program, which I wrote, requires a stepper controller. A stepper controller provides all the logic necessary to energize the motor coils in the proper sequence and polarity to make it turn in the desired direction. Most stepper controllers also provide current limiting so you don't need to use a specific voltage to get the proper current through the stepper. All the LCD program does is tell the stepper controller when to turn the motor 1 step and in what direction.

    Example:

    1. Set direction to Forward.
    2. Step

    The H-Bridger driver is a much lower level device and requires the arduino sketch to provide the stepping logic to the individual coils in the proper sequence to make the motor turn. All the H-Bridge does is amplify the voltage/current and set the voltage polarity. The arduino has to individually tell the H-Bridge which coil(s) to energize and in what polarity.

    Example:
    1. Energize Coil A, forward.
    2. Energize Coil B, Forward,
    3. Energize Coil A, Reverse.
    4. Energize Coil B, Reverse.
    5. Etc...

    This is just an example and is not necessarily the right sequence. A different sequence is required to make the motor turn the other direction. You would have to modify the LCD program to incorporate the forward and reverse logic from the "stepper_onestepatatime" sketch to make it work.

    Chuck
     
  2. Jul 29, 2013 #82

    vidio1

    vidio1

    vidio1

    Active Member

    Joined:
    Aug 9, 2011
    Messages:
    26
    Likes Received:
    2
    Well that would certainly make sense. I guess I should have said first time Arduino and stepper user, but that was probably evident. Looks like I need to learn some C. Thanks again for the reply and sharing your sketch.
     
  3. Jul 29, 2013 #83

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    If you are truly interested in learning C, in figuring out how to make steppers work at a low level, and expanding your knowledge of steppers and electronics in general, modifying the LCD program and getting it to work would surely be the way to go.

    On the other hand, if your main goal is to build an Arduino controlled dividing head, it would be far easier to simply buy the Pololu (or equivalent) stepper controller for under $12 + shipping and hook it up. That is, assuming your stepper motor will run on about 1.5 amps...

    http://www.pololu.com/catalog/product/2128

    No changes to the LCD program would be necessary, although I do have a newer version that is a little more user friendly.
     
    vidio1 likes this.
  4. Jul 29, 2013 #84

    vidio1

    vidio1

    vidio1

    Active Member

    Joined:
    Aug 9, 2011
    Messages:
    26
    Likes Received:
    2
    I thought about getting the correct driver just to have it working, and probably will. About 8 or 9 years ago I started with an Oopic microcontroller, not sure if you've heard of them or not.

    Anyway I was just getting started with it when I was deployed to Iraq. Long story short, by the time I came back from Iraq support had fallen off to next to nothing. There were some internal issues with the company and it dissolved. It made trying to learn from scratch all but impossible. I tossed it and all the sensors, breakout boards, motors, etc. in a small tote in stuck it on a shelf in the garage.

    I've been looking for an excuse to get back into microcontrollers and have been looking at the Arduino for about a year or so, just to make sure this one doesn't fall by the wayside. Your project was the scapegoat I suppose.

    It's easy enough to copy a sketch someone has made, but I still don't know enough about the nuts & bolts of why it works like it does. I need to learn at least some C if I'm ever going to.

    I've been watching a video series on C++ that's about as Noob friendly as it gets, so I'll pursue that until I know enough to be able to ask an intellegent question.........

    Thank again.
     
  5. Jul 29, 2013 #85

    RonGinger

    RonGinger

    RonGinger

    Well-Known Member

    Joined:
    Nov 12, 2008
    Messages:
    893
    Likes Received:
    118
    Gender:
    Male
    Occupation:
    Retired
    Location:
    Boothbay Maine
    All of your Oopic sensors and such should be useable with Arduino.

    Learning C++ is a worthy goal, but thats a big jump to start. I would start by learning more about Arduino and its programming. There is a HUGE amount of good material on the net for free. The Arduino is programmed in something that is very close to C, but with all the tedious stuff removed

    I think one of the best ways to learn is to pick some existing program that you have an interest in, and the dividing head wold be a good one, and read it and study it until its clear. Then try to add some improvements to it. Its lots better to start with a working example than a blank sheet.
     
    malcolmt likes this.
  6. Jul 30, 2013 #86

    starnovice

    starnovice

    starnovice

    Member

    Joined:
    Nov 21, 2010
    Messages:
    194
    Likes Received:
    23
    Being a professional software engineer I have learned more programming languages then I can count, several of them not even in use anymore. Almost all of them I learned through self-study. I agree with Ron the quickest way to start is to read other people's code and figure out what they did while at the same time having a basic reference book on the language near by,
     
  7. Jul 30, 2013 #87

    vidio1

    vidio1

    vidio1

    Active Member

    Joined:
    Aug 9, 2011
    Messages:
    26
    Likes Received:
    2
    cfellows sorry for the thread hi-jack. I'll leave it with this;

    I chose the Arduino because it has a ton of support. There are shields and sketches everywhere I look. That's probably the single most important thing to have for someone getting started, short of a mentor standing over your shoulder.

    Almost all microcontrollers can use a version of C for programming. If I can learn enough to be usefull it will make it easier to program almost anything I might pickup in the future. I have some lofty future goals that include an Autonomous rover with multiple controllers talking to a main controller to get things done. There seems to be more free learning resources for C++ than most others worth learning. These are the reasons for my choice of C++.

    I've actually been looking over sketches, changing bits here and there to see how and what it changes. That's helped get my toes wet. I believe I'm going to buy a programming Arduino book written by Simon Monk. After looking at a few Arduino books I think his might be a decent starting point.

    There are a few projects out there using the Arduino that might make a contribution to this site if there were a sub-forum available. I've seen digital scale readers, a DRO, electronic lead screw, and of course this dividing head. Just an idea.
     
  8. Jul 30, 2013 #88

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,132
    Likes Received:
    334
    C is just another language, C++ just extends it by adding Object Oriented Programming (methods, classes etc). If I mention C below it includes C++.

    I think the main thing to understand with learning a new programming language is to get your head around the normal programming constructs (if, do..while, while, switch, if/else, how functions and procedures work.

    The next most critical part of learning C is to get your head around pointers and also pointers to pointers. The most useful tip I have read is to think of an * as being a star and when you see it it means the variable starred (stored) at that memory location. Once you get this and how it works with pointers to structures you will set the world on fire. Once you grasp these basics, you can move on to the more advanced concepts of C++ and define classes and their methods. Pull down some open source code like Ghostrscript and work your way through some of the code until you understand what is going on.
     
  9. Nov 16, 2013 #89

    _Paul_

    _Paul_

    _Paul_

    New Member

    Joined:
    Jan 18, 2013
    Messages:
    2
    Likes Received:
    0
    Chuck,

    Very nice work, but I have a question if I may, if I wanted to modify your program to use with a 40:1 dividing head and a 90:1 rotary table which variable/s would I need to alter?
    is this change correct:

    #define stepperDiv 8000.0 // Stepper Resolution
    #define rotaryDiv 18000.0


    Regards

    Paul
     
  10. Nov 16, 2013 #90

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    Yes, assuming your stepper motor has 200 steps per revolution. Unfortunately, my program doesn't use ramped acceleration and deceleration so you can probably grow a beard while waiting for that rotary table to reach the next stop... ;D.
     
  11. Nov 16, 2013 #91

    _Paul_

    _Paul_

    _Paul_

    New Member

    Joined:
    Jan 18, 2013
    Messages:
    2
    Likes Received:
    0
    Thanks Chuck,

    Perhaps for the dividing head only then!

    Many Thanks

    Paul
     
  12. Dec 21, 2013 #92

    Swarfing

    Swarfing

    Swarfing

    Member

    Joined:
    Dec 21, 2013
    Messages:
    7
    Likes Received:
    0
    Hi Chuck, i think i have missed something from the thread. Do you have a wiring diagram for the driver to the Arduino Uno. I have the sainsmart setup and single axis tb6560 driver.

    Thanks

    Paul
     
  13. Dec 21, 2013 #93

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    Here's the wiring diagram...

    [​IMG]

    Hope this helps...

    Chuck
     
    larry1 and malcolmt like this.
  14. Dec 21, 2013 #94

    Swarfing

    Swarfing

    Swarfing

    Member

    Joined:
    Dec 21, 2013
    Messages:
    7
    Likes Received:
    0
    Thanks Chuck that helps me out a lot. The Reset/ Sleep connection is that just specific to pololulu driver? i.e i don't need to worry about that with my TB driver?

    Thanks

    Paul
     
  15. Dec 24, 2013 #95

    Twizseven

    Twizseven

    Twizseven

    Junior Member

    Joined:
    Jul 9, 2012
    Messages:
    33
    Likes Received:
    6
    Chuck,

    I have been following your various builds with interest over the last 6 months or so. I am interested in making CNC stepper setup for my rotary table. You mentioned in one of your earlier posts on this topic about posting up a list of components used and plans. I know your busy but did you ever manage to do this and if so where would I find them.
    Many Thanks,

    Colin
     
  16. Dec 24, 2013 #96

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    Yeah, those connections are specific to the A4988.

    Chuck
     
  17. Dec 26, 2013 #97

    Swarfing

    Swarfing

    Swarfing

    Member

    Joined:
    Dec 21, 2013
    Messages:
    7
    Likes Received:
    0
    Thanks Chuck, code now loaded wires connected to test. Just need to decide whether to mangle up the rotoary table or build something from scratch, the later probably being the bet for now. Thm:
     
  18. Dec 27, 2013 #98

    cfellows

    cfellows

    cfellows

    Well-Known Member Project of the Month Winner

    Joined:
    Aug 26, 2007
    Messages:
    3,891
    Likes Received:
    704
    Yeah, if you are planning on using it just for dividing operations like drilling holes or cutting gears, etc., a rotary table really has too high a gear ratio. My dividing head has ratio of 1:5 from motor to spindle. My Arduino program doesn't have stepper acceleration and deceleration, so it's kind of slow, just to make sure it doesn't skip any steps.

    Chuck
     
    Swarfing and malcolmt like this.
  19. Dec 27, 2013 #99

    Swarfing

    Swarfing

    Swarfing

    Member

    Joined:
    Dec 21, 2013
    Messages:
    7
    Likes Received:
    0
    Chuck my rotab has a 90:1 wormdrive which would work out well for this. Chances are i would go with a worm drive on a scratch build as well. With the driver at 3.5amps and use full volts, run bipolar on the windings and keep micro steps down to a minimum then the holding torque should be sufficient for my needs. Not planning to do any fast turning with mine.
     
  20. Dec 30, 2013 #100

    Twizseven

    Twizseven

    Twizseven

    Junior Member

    Joined:
    Jul 9, 2012
    Messages:
    33
    Likes Received:
    6
    First of all thanks to Chuck for his arduino stepper motor code in download section. This runs happily on my arduino uno with Sainsmart 1602 LCD. I am waiting for delivery of Pololu DRV8825 and a stepper motor but in meantime am looking to see what spare pins there are available on LCD module. I would like to use the stepper in microstep mode. I think that D11, 12 and 13 are free. On the DRV8825 schematic they are marked as D11/MOSI, D12/MISO and D13/SCK. Does anyone know what they mnemonic mean. The DRV8825 docs say that to get particular microstep values MS1, MS2 and MS3 need to be set HIGH as appropriate. Can this be done by linking them together (as nec) and providing an input from one of the (hopefully) spare digital pins to set them HIGH.

    Hope this makes sense.

    Many Thanks,

    Colin
     

Share This Page