building a self balancing segway clone

Discussion in 'The Projects Forum' started by joseman300, Apr 15, 2018.

  1. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    currently building a segway clone using the hartway digital arduino code on an arduino mega 2560 with a sabertooth 2x32 motor controller. My first project ever. Very interesting and fun but also frustrating! can anyone help put things in order for me? the mega doesn't seem to want to control the motors at all. I have gear motors with 2 12v batteries. Following directions is my strong suit so if anyone can steer me in the right direction it would be greatly appreciated.

    Joe
     
  2. Sensacell

    Moderator

    Jun 19, 2012
    2,424
    802
    Post a diagram of your system.
     
  3. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
  4. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    I am using an arduino mega so the analog pins are in 21 and 20..
     
  5. ebeowulf17

    AAC Fanatic!

    Aug 12, 2014
    2,933
    641
    Totally grasping at straws, just brainstorming:

    I see there are dip switches for 9600 baud selection. Do you have them set properly? Since the pin being used for communication isn't one of the serial pins, I assume the Arduino is bit-banging, so I'm not sure where you'd check communication speed in the code/IDE, but it might be worth looking in there too.

    Have you seen examples of others using the Mega instead of the Uno for this project? There may be a risk that the code is written specifically for the Uno architecture and would require tweaking on the Mega.

    Have you measured voltage of motor outputs when you expect them to be running?

    Is there any provision for debugging in the code? Does it send messages to the serial output so that you can see what it thinks it's doing via the IDE terminal in real time? Without knowing what the Arduino thinks is happening, it's hard to troubleshoot. Maybe it's failing to read the dead man switch, so it never tries to turn the motors on. Maybe it never successfully initializes gyro sensor, and for safety reasons won't start the motors without a working gyro. Maybe it wants to spin motors, but communication with the motor controller is failing. Who knows?!

    You need to take some steps to narrow things down. Let us know what you find.
     
  6. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    Obviously I'm a newbie to this. But the challenge is enjoyable! I have tried many different dip switch settings and I get one or both of the motors to run depending on the settings. I feel they are just being powered by the motor controller and not receiving any data from the mega The serial monitor shows the changes in the gyro but does not reflect at in the motors. I did try to alter the code to reflect the mega but again I'm a newbie. Depending on dip switches the motor / motors either run as soon as the off/on goes to on or they don't run at all. I am having trouble finding a code that matches the stuff I have. If you know of any other codes for a self balancing Segway clone type please let me know

    Thanks again for your patience!

    Joe Manor
     
  7. ebeowulf17

    AAC Fanatic!

    Aug 12, 2014
    2,933
    641
    That's a good start. Does the serial monitor tell you when/if it's trying to run the motors, or just what the gyro and other inputs are reading. In other words, does it tell you any output status(es) or only inputs?

    Also, double check your wiring vs. your code and make absolutely sure that you're using the right output pin for the motor communication.
     
  8. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    The serial just shows inputs
     
  9. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    using the hartway_digital code
     
  10. ebeowulf17

    AAC Fanatic!

    Aug 12, 2014
    2,933
    641
    How good have you gotten at reading code? Can you find the section where it's outputting data to motor controller and add some serial data there for the serial monitor? Might make debugging easier.

    It sounds like you've got a motor driver that's capable of driving motors, and an Arduino that's reading sensors. The question now is whether the Arduino is deciding not to run the motors for some reason, or if it's trying to tell the motor controller to run them, and that communication is failing.

    The other thing you might try is changing which pin you use for motor communication. Different pins have different capabilities depending on which Arduino model you've got. Maybe the pin you're using is incompatible for some reason. I wouldn't expect that to be the case, but if no other explanation comes along, it might be worth a shot.
     
  11. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,897
    394
  12. joseman300

    Thread Starter New Member

    Apr 15, 2018
    7
    0
    that is the code I'm trying to use
     
  13. dendad

    Distinguished Member

    Feb 20, 2016
    2,921
    810

    This is the first video of a self balancing robot using an Arduino.
    On his web site, Joop Brokking has the code and explains it well.
    It may be worth a look.
     
  14. dendad

    Distinguished Member

    Feb 20, 2016
    2,921
    810
    Joop is using steppers but his explanation of the setting up may help.
    Have you tried just writing a program to run the motors up and down, nothing else.
    It is confusing to me,
    You show a Uno but say you are using a Mega?
    Can you post the correct diagram and code?
    And I too wonder why you are using that particular pin for talking to the motor driver.
    Maybe use pin 2 or 3? But it may be the real digram with a Mega will show it.
     
Loading...