Interrupt Driven Rotary Table controller

Discussion in 'Software and Programming' started by rodw, Nov 30, 2015.

Help Support HMEM by donating using the link above.
  1. Jul 27, 2018 #61

    Anatol

    Anatol

    Anatol

    Well-Known Member

    Joined:
    Jan 22, 2018
    Messages:
    195
    Likes Received:
    30
    Gender:
    Male
    Location:
    Los Angeles
    Hi All,
    Rod - congratulations on a great project. I'm not making it currently, but I have decades of experience in mechatronics.
    I see many this thread are baffled or asking questions which reflect a lack of experience, and responders are reacting with patience (mostly) and cannot be blamed if readers don't read all the posts or follow instructions. As noted, electronics is not simple, even though those who stayed to profit from selling you stuff try to tell you it is. So I'd like to offer a couple of suggestions to electronics 'newbies'.

    In Rod's OP he said - " Power supply (minimum 24 volt in my experience, around 80% of what you stepper driver is rated for - I use a 48 volt power supply)." I would always provide a motor - or any inductive load - with the rated voltage. As voltage drops, current increases, and this results in heat - bad for coils. Make sure the power supply can provide double the rated max current demand of the motor (pay attention to 'peak' ratings). If the motor stalls (in some way that does not trigger an emergency shutdown), you will release the 'magic smoke' from the power supply. And don't forget your flyback diodes!

    Breadboards (or protoboards, as in the pics) can be great for prototyping, but are prone to bent contacts inside and so can be a source of frustrating intermittent faults. Don't jam big wires in, and don't carry them around unprotected. I would transfer all circuitry to a soldered perfboard as soon as the circuit is tested and working. Knowing how to make a reliable solder joint is fundamental. Sheilds, (blank boards that plug into the sockets of the Arduino) are a great way to avoid extra straggly wires. And on the subject of wires - only use solid wire for on-board connections. Use stranded wire for wires that will move/bend/vibrate - or your project will not last. If you get really ambitious, you can use a CAD program to lay out a PCB (printed circuit board) - but don't do this before you'r absolutely sure of your circuit.

    More generally, an Arduino is a microcontroller, it deals in digital data (ones and zeros or ons and offs), which is a specialised form of electronics in which most of the information in the signal is thrown away. Newbies to electronics imagine voltage is the only number that matter. This is an oversimplification. Current flow seems a much more obscure concept for people to grasp. But it is fundamental.

    Analog signal electronics and power electronics are very different realms from the digital. An analog circuit does not transfer data, it sings. I mean this in all seriousness - in analog electronics there is no input and output or on and off, there are resonances which are perturbed. Most of the stuff hanging on the outside of Arduino is like this to some extent.

    For those in USA, I suggest Allelectronics, an electronics surplus house with good prices. I think they're currently offering UNOs for a few bucks. I've bought from them for years.
     
    Shehan Perera likes this.
  2. Jul 27, 2018 #62

    Anatol

    Anatol

    Anatol

    Well-Known Member

    Joined:
    Jan 22, 2018
    Messages:
    195
    Likes Received:
    30
    Gender:
    Male
    Location:
    Los Angeles
    and another thing ! :)
    Very important

    while your Arduino is connected to both the stepper controller and its power supply, and also your computer, you have two power supplies. You MUST MUST MUST make sure all the ground lines in your circuit - power and signal - are tied together, or you may FRY parts of your computer. UNLESS your power circuit is totally electrically isolated from the signal/data side via optoisolators (or electromechanical relays).

    The theoretical reason for this is as follows: Voltage is potential DIFFERENCE wrt an arbitrary refernence, which is what 'ground' is. DC circuits are closed worlds. When signal wires between two circuits with separate grounds are connected, havoc can ensue.

    Think of it this way - each circuit is a bubble with its own atmospheric pressure, say one is at 1 atmosphere and the other is at 10. When two bubbles join, there will be a huge flow from the higher pressure to the lower pressure bubble.

    At some point you will disconnect your Arduino from your computer, at which point you will require a smoothed 5v external power supply (or 7-10 v supply, depending on the input you choose), in addition to your stepper motor power supply.
     
    Shehan Perera likes this.
  3. Aug 6, 2018 #63

    Shehan Perera

    Shehan Perera

    Shehan Perera

    Member

    Joined:
    Jul 17, 2018
    Messages:
    6
    Likes Received:
    0
    Gender:
    Male
    Location:
    Sri Lanka
    Uploaded code.
    But buttons not working?
    Used generic LCD key pad shield
     
  4. Sep 1, 2018 #64

    rodw

    rodw

    rodw

    Well-Known Member

    Joined:
    Dec 3, 2012
    Messages:
    1,066
    Likes Received:
    315
    Sorry, its been quite a while since I've been on this forum and missed the last couple of posts. Anatol, thank you very much for your compliment and additional descriptions.

    For others like Shehan Perra, I don't know how many times I have said that the Arduino is not Plug and Play, The required hardware is listed. If you choose to use some other hardware, then you are on your own. Don't ask me for help.

    If you don't know how to modify the code (and the answer is on this forum), then buy the required hardware or find another simpler script. This script uses advanced high performance code that works. Its well written and documented in the source. Its not really a beginner Arduino project as it pushes the limits of the Arduino.
     
  5. Sep 9, 2018 #65

    haiduongoy

    haiduongoy

    haiduongoy

    New Member

    Joined:
    Sep 9, 2018
    Messages:
    1
    Likes Received:
    0
    Gender:
    Male
    Location:
    California
    thank to you
     
  6. Sep 12, 2018 #66

    stragenmitsuko

    stragenmitsuko

    stragenmitsuko

    Well-Known Member

    Joined:
    Jan 19, 2016
    Messages:
    139
    Likes Received:
    57
    I printed the first post in this thread , and followed the instructions to the letter .
    It all works like a charm and I had it going in abt 10 minutes .
    That includes installing the IDE and arduino clone driver .

    BIG thumbs up for RodW .

    Do I need to cut n paste the bug fix in the code , or has the rotary10.zip file been updated and can it be used as is ?

    Pat
     
    Last edited: Sep 12, 2018
  7. Sep 12, 2018 #67

    stragenmitsuko

    stragenmitsuko

    stragenmitsuko

    Well-Known Member

    Joined:
    Jan 19, 2016
    Messages:
    139
    Likes Received:
    57
    I think my previous post was a bit to optimistic .

    I have what looks to be a sainsmart clone lcd shield .
    duino2.jpg
    I tried it with a "button test " sketch , and they all work as intended .
    Left returns a left , select returns a select etc .

    But with the rotary table sketch , the "left" button is not functional , and the "select" button seems to act as a left . It's a hardware/software incompatible issue I'm sure .

    And I know I'm on my own :) .
    I'll try to figure it out and report back if I can find it .
    I'll probably start by checking resistor values .

    Anyone else had this behaviour ... feel free to give me hint .
    I did modify the backlight pins as suggested , and that makes the backlight turn off when the screensaver kicks in .
    But offcourse , it doen nothing to the button problem .

    I wouldn't mind buying the freetronics display shield , but the shipping cost is outrageous .
    It cost more for shipping it then the actual price .

    Pat
     
  8. Sep 12, 2018 #68

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    218
    Likes Received:
    71
    Location:
    Medina, Ohio USA
    Hi Pat
    do you mean you changed the backlight pin assignment from 3 to 10 as explained here ?
    That was all I needed to do to get the Sainsmart shield to work. I also tried a DFRobot shield and could not get it to work. It was awhile ago but I think I remember googleing the difference between the two and think it is fixable. I think.
    The Sainsmarts do work.

    Scott
     
  9. Sep 12, 2018 #69

    stragenmitsuko

    stragenmitsuko

    stragenmitsuko

    Well-Known Member

    Joined:
    Jan 19, 2016
    Messages:
    139
    Likes Received:
    57
    Yes , the backlight pin from 3 to 10 does what it should .

    As for the shield itself , looking at the schematics , both sainsmart and freetronics
    use thesame resistor values for the buttons . 2K ; 330E ; 620E ; 1K ; and 3K3 .
    But the dfRobot uses a 2K2 resistor instead of a 2K . That is the cause of the problem .
    For now I soldered a 22K in parallel to the 2K2 , wich results in a value of 2K .

    That makes my "left" and "select" buttons operational .
    Most lilely it's all it takes .
    I'm sure it can also be solved in software , but I'm not good with software .

    Trying to figure out the menu structure now , and wich button does what .

    I'll post a picture and "schematic" when I'm sure it works .

    Pat
     
  10. Sep 12, 2018 #70

    Scott_M

    Scott_M

    Scott_M

    Well-Known Member

    Joined:
    Apr 13, 2013
    Messages:
    218
    Likes Received:
    71
    Location:
    Medina, Ohio USA
    Sounds like you have a handle on it. Good luck and have fun.

    Scott
     
  11. Sep 18, 2018 at 9:30 PM #71

    stragenmitsuko

    stragenmitsuko

    stragenmitsuko

    Well-Known Member

    Joined:
    Jan 19, 2016
    Messages:
    139
    Likes Received:
    57
    As promised I report back here with my findings .
    I had to make a small modification to the df Robot shield to make it freetronics/sainsmart compatible .

    Basicly what happend is that the designers of the freetronics display shield used a non common resistor .
    2K . No that uncommon , but the std value is 2K2 .
    IMG-20060402-00190.jpg
    The df robot shield designers decided probably to save a few pennies and used a std 2K2 resistor instead .
    Remember , this is a 3$ shield , s&h included . I'll never understand how they are able to build it
    at that price .
    No problem really , it still works , and various test sketches read the buttons correctly .
    However the different resistor throws the two lower voltages off just enough for Rod's sketch not to recognise them .
    I fixed it by adding a 22K resistor in parallel to the 2K2 resistor wich results in a 2K value .
    This makes all the buttons function as they should .
    The resistors are hidden inder the lcd , you can't see them in t he picture .
    Just above the RST button , you can see the 22K I added .


    This also can be solved in software . At least it should be .
    I can calculate the voltages for each button , and even the expected ADC counts both with a 2K or with a 2K2 resistor .
    And then it should be just a couple of numers somewhere need to be changed .

    I think it's the piece of code copied below that reads and maps the buttons .
    Copied it from the lcd.cpp wich is in the library .
    But I just can't understand how it works . Maybe someone who does could explain it to me .

    It's academic , I'll most likely build a custom display shield with a much larger lcd , and offcourse I'll use the correct
    resistors there . But still , I like to learn things and understand what I'm doing .


    Pat



    // Button mapping table generated by genlookup.c
    static unsigned char const buttonMappings[] PROGMEM = {
    2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
    1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
    };
    #define mapButton(value) (pgm_read_byte(&(buttonMappings[(value) >> 5])))

    /**
    * \brief Gets the next button press, release, or idle event.
    *
    * If no buttons are pressed, this function will return LCD_BUTTON_NONE.
    *
    * When a button is pressed, this function will return one of
    * LCD_BUTTON_LEFT, LCD_BUTTON_RIGHT, LCD_BUTTON_UP, LCD_BUTTON_DOWN,
    * or LCD_BUTTON_SELECT. While the button is pressed, this function
    * will return LCD_BUTTON_NONE until the button is released. When the
    * button is released, this function will return one of
    * LCD_BUTTON_LEFT_RELEASED, LCD_BUTTON_RIGHT_RELEASED,
    * LCD_BUTTON_UP_RELEAED, LCD_BUTTON_DOWN_RELEASED,
    * or LCD_BUTTON_SELECT_RELEASED.
     

Share This Page