1. Got a question or need help troubleshooting? Post to the troubleshooting forum or Search the forums!

Arduino related code questions (sketches).

Discussion in 'Off Topic' started by BrooklynBay, Jul 1, 2021.

  1. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    It looks like it connects to the SDA & SCL pins on the Arduino which are the first 2 pins near the reset button.
     
    mark tomlinson likes this.
  2. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    That should not be a problem. Just remember that the display library probably wants the data that is going to be displayed converted to string (or character). That is not a problem on the Arduino, here are examples for integer data, floating point is not wildly different.

    https://stackoverflow.com/questions/7910339/how-to-convert-int-to-string-on-arduino

    https://www.arduino.cc/en/Reference.StringConstructor

    If you had a string called myString then send the string to the display: lcd.print(myString);
     
  3. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    While setting up the mechanical part of the system, I came across something which might need to be addressed either with code, limit switches or another method. The motor section by the wheels moves the encoder from a 12 o'clock to a 1 o'clock position. The steering wheel moves from a 12 o'clock to a 4 o'clock position controlling the motor which doesn't move as much. The encoder in the steering wheel has a large ring gear to cause the encoder to rotate for several rotations. My issue is that one encoder is only turning a few degrees to clockwise & counter clockwise while the second encoder is turning several complete rotations for the same motor control movement. Both motors & encoders have to be synchronized even though their movements are not matching each other. Do I decrease the total amount of steps or increase the time delay of the motor by the wheels which only moves a little? The speed of the motor could be varied in the sketch but this will decrease the strength of the motor so it's not a good option. The 18 volt motor will run at 12 volts most likely, so it already won't be running at full capacity. The motor that I'm using has a gearbox to vary the rotations so I could put it into low gear but I don't know if it will make that much of a difference since the codes controlling it are still telling it to turn when it reaches its limit.
     
    #23 BrooklynBay, Jul 13, 2021
    Last edited: Jul 13, 2021
  4. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    Maybe a picture or diagram would make this easier for me to visualize.
    If the two encoders are mechanically linked then this is complicated. If they are not mechanically linked then just do the adjustments in code (a ratio for them to insure that as one turns the other also turns in the appropriate ratio amount).

    From your description is sounds like the latter -- they are not mechanically linked and you do the calculation in code.

    If you have the case where one can reach a limit the best solution is something to trap and flag that travel is limited (like a limit switch). Usually the motors can handle being mechanically stalled and still driven against the stop at least in short bursts, but it is not really a best case way to build it.

    Feel free to PM me the details if you would rather or post them in this thread.
     
  5. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    Each motor has its own encoder. The motor connected to the steering linkage has fewer degrees of movement compared to the motor which is connected to the steering wheel. I want to have an end stop switch by the steering linkage. I don't think that I'll have an end stop switch at the steering wheel unless it's necessary. I think that would be redundant since there's one at the steering linkage.
     
  6. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    OK, they are effectively geared together so that makes sense. The ratio of turns at one end to turns at the other end should match the gearing. Still, you can account for that in the code. Yes, only one endstop is needed since they are not free spinning, but rather connected to each other.

    If one turns 1/2 turn to get the other one to turn 1/4 turn you can calculate that into the software. No need to have a limit on both ends as long as they are mechanically connected.
     
  7. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    I'm still in the process of gathering parts, and building it so I don't have enough of it assembled at the moment to take pictures. I had to draw several parts, and print them, then test how they fit. Some of them had to be changed a few times to get them right. Most of the parts are printed, and installed but not all of them.

    One thing which I've noticed so far is that this drive by wire steering set up is more responsive compared to mechanical direct linkage steering with a rack & pinion. The steering wheel in a car has to turn multiple times because of the rack & pinion's gear ratio. My set up has a center link with a Pitman arm, so it requires a small movement to go to a complete turn from side to side.
     
    mark tomlinson likes this.
  8. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    The project that I'm working on is similar to the one here: https://electronoobs.com/eng_arduino_tut102.php. The difference is that this project shows only one motor with an analog potentiometer while mine uses two brushed dc motors & 2 encoders so it's digital instead of analog. I ordered an Arduino motor shield which is similar to the L298N. The schematic shows an L989N. I would like to modify this schematic to delete the potentiometer, add a second motor, and 2 encoders. The schematic below shows only one encoder since it shows a potentiometer. A 16 x 2 or a 20 x 4 display might be an option. The code needs to be updated for the changes as well as the ratio for both motors to work in unison. Here's the schematic from the web page:
     

    Attached Files:

    #28 BrooklynBay, Jul 15, 2021
    Last edited: Jul 15, 2021
  9. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    This link has information for rotary encoders: https://lastminuteengineers.com/rotary-encoder-arduino-tutorial/.
    This link has information for the Arduino motor shield: https://www.instructables.com/Arduino-Motor-Shield-Tutorial/.
    This link has information on connecting & displaying step & direction data on a 16 x 2 display: https://circuitdigest.com/microcontroller-projects/interfacing-rotary-encoder-with-arduino. It's for a certain type of display. I wanted to use the Seeed display which uses less pins, and has RGB color background, so some of the information has to be changed to make it compatible.

    On a side note, why don't 3D printers use encoders on the servos to prevent Z wobble or automatically compensate for under or over extrusion? A lot of printers don't even have a simple filament sensor to pause the print if it runs out of filament or if the nozzle clogs.
     
  10. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    3D printers at the consumer level don't use them :)
    Stratsys and others for commercial use do.
    The professional printers track the head in all axis.

    This is how they sell printers that cost less than 100k ... it is like comparing a Honda Civic to a Formula 1 car. One costs a bit more ...


    There are some manufacturers who do use better motion systems that are not as expensive, but they are still more than 2k.

    You see this same thing in the CNC world, the cheaper ones make trade-offs that affect performance and capability for price. The commercial ones don't.

    This is why a lot of folks build their own at some point so that they can incorporate the features they want. It is not too difficult to build your own and you learn a lot too.
     
  11. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    Since encoders are around $3 a piece plus another few dollars for the wiring harness, it seems like a good investment for manufacturers to look into for improving upon the print quality & reliability of their machines. I don't see how an average RAMPS shield would be able to handle an extra 5 encoder inputs. The firmware would need to be updated too. Would an extra add on card or another type of shield be capable of handling all of these extra inputs? I know that you could have two Arduinos connected together to share functions, so maybe a primary & secondary Arduino with two RAMPS shields would work or possibly adding a Raspberry Pi?
     
  12. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    The professional printers don't use commodity hardware like Arduino/RAMPS and some of the more expensive consumer models use their own 32-bit hardware. You can look over here for examples: https://all3dp.com/2/3d-printer-controller-boards/

    The Arduino would not be able to consume all those inputs and react, with multiple Arduinos you would need thee firmware to be able to control and distribute data/code among them ... difficult at beast. You would use a more powerful board like a Due.
     
  13. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    Is it possible to use a full size or mini 12864 LCD with an Uno or Leonardo board without a RAMPS? If so, then the pin definitions might need to be changed since they are different than the MEGA 2560.
     
    #33 BrooklynBay, Jul 19, 2021
    Last edited: Jul 19, 2021
  14. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
  15. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    I have a question about the spdt end stop switch in post number 28. My set up has the end stop floating without a direct connection unlike a switch which is always touching one contact or another contact. Is the trigger in that schematic designed to activate when it touches the positive or the negative terminals (or both)? If it only triggers with a negative pulse, then I would have to use a pull up resistor on the positive, and use 2 inputs on the Arduino for left & right triggers.
     
  16. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    This talks about the pull up and digital I/O here:

    https://www.arduino.cc/reference/en/language/variables/constants/constants/

    The trigger on the Arduino side is discussed there in terms of what reads HIGH and what reads LOW. Obviously you need to pull it one way or the other before you depend on it -- floating digital pins can drive you nuts. Don't eve let that happen if you need reliable data on a switch. How the code reacts will depend on how you write it. You can have your code react to a HIGH or LOW, but if it is floating it may be neither.
     
  17. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    The link said that 10k external resistors could be used or there's a way to set the internal 20k resistors in code so the limit switches aren't floating. I wanted to have a limit switch set up so when the steering goes to the extreme left or right it will deactivate the dc motor. Could a single digital input be used with a (-) pulse to stop the motor (two limit switches wired in parallel) or do I need to configure two separate limit switches on two digital inputs with its own (-) pulse to stop the motor?
     
  18. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,478
    Likes Received:
    7,303
    No reason two in parallel won't work as long as both are OPEN for normal operation and CLOSED means stop in both cases.
    It might be more convenient to have two if you logic/code needed to behave differently.
     
  19. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    Here's the first part of the project. I want to make some minor changes on it. The photo includes a brief description of the limit switch set up since it's not an actual switch. The bolts on the linkage come into contact with a bar when the maximum angle of travel is reached.
     

    Attached Files:

    mark tomlinson likes this.
  20. BrooklynBay

    BrooklynBay Active Member

    Joined:
    Apr 7, 2018
    Messages:
    414
    Likes Received:
    49
    I forgot to indicate where the encoder is in the photo. It's between the front of the drill & the bar where the 2 bolts are going through the middle.
     

Share This Page