element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino A-Star Programing
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 18 replies
  • Answers 2 answers
  • Subscribers 393 subscribers
  • Views 2093 views
  • Users 0 members are here
Related

Arduino A-Star Programing

Former Member
Former Member over 11 years ago

analogue into an arduino a-star controlling a robo claw controller in encoder mode hooked up exactly like in page 48 in the orion manual

Attachments:
imageroboclaw_user_manual.pdf
  • Sign in to reply
  • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago

    Dear: Allan

    You said to element 14 that you are not getting how to use a rotary encoder but what are you not getting? You are not very specific.

    From: Noah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to nschreiber0813

    I am trying to write a program for the arduino a-star to accept analog input from a pot with 0 to 5 volt output, go threw the arduino a-star and come out of it with packet serial to the roboclaw in encoder feedback mode like a servo.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago in reply to Former Member

    Dear: Allan

    Apparently in the datasheet they did have something you should know about. Here is the code I modified. Good Luck.

     

     

    //Basic Micro RoboClaw RC Mode. Control RoboClaw

    //with servo pulses from a microcontroller.

    //Mode settings: Mode 2 with Option 4.

    #include <Servo.h>

    Servo myservo1; // create servo object to control a RoboClaw channel

    Servo myservo2; // create servo object to control a RoboClaw channel

    int pos = 0; // variable to store the servo position

    void setup()

    {

    myservo1.attach(5); // attaches the RC signal on pin 5 to the servo object

    myservo2.attach(6); // attaches the RC signal on pin 6 to the servo object

    }

    void loop()

    {

    for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees

      {                                  // in steps of 1 degree

        myservo1.write(pos);              // tell servo to go to position in variable 'pos'

        delay(15);                       // waits 15ms for the servo to reach the position

      }

      for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees

      {                               

        myservo1.write(pos);              // tell servo to go to position in variable 'pos'

        delay(15);         

      }

      delay(1000);

      for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees

      {                                  // in steps of 1 degree

        myservo2.write(pos);              // tell servo to go to position in variable 'pos'

        delay(15);                       // waits 15ms for the servo to reach the position

      }

      for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees

      {                               

        myservo2.write(pos);              // tell servo to go to position in variable 'pos'

        delay(15);         

      }

      delay(1000);

    }

    From: Noah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago in reply to nschreiber0813

    Dear: Allan

    Ignore my last comment. I forgot you asked how to use your encoder not your servos so here is the code I found in your datasheet.

     

    //Basic Micro RoboClaw Packet Serial Mode.

    //Switch settings: SW3=ON, SW4=ON, SW5=ON

    #include “BMSerial.h”

    #include “RoboClaw.h”

    #define address 0x80

    #define Kp 0x00010000

    #define Ki 0x00008000

    #define Kd 0x00004000

    #define qpps 44000

    BMSerial terminal(0,1);

    RoboClaw roboclaw(5,6);

    void setup() {

    terminal.begin(38400); roboclaw.begin(38400);

    roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps); roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);

    }

    void loop() {

    uint8_t status;

    bool valid;

     

    uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);

    if(valid){

    terminal.print(“Encoder1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);

    }

    uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);

    if(valid){

    terminal.print(“Encoder2:”); terminal.print(enc2,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);

    }

    uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);

    if(valid){

    terminal.print(“Speed1:”); terminal.print(speed1,HEX); terminal.print(“ “);

    }

    uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);

    if(valid){

    terminal.print(“Speed2:”); terminal.print(speed2,HEX); terminal.print(“ “);

    }

    terminal.println();

    delay(100);

    }

     

    From: Noahimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to nschreiber0813

    is line 9( RoboClaw roboclaw(5,6);) for PWM input on pins 5 and 6?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to nschreiber0813

    I am getting an error in this line  terminal.print(“Encoder1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);

    And I think the error says,    stray "(" in program

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago in reply to Former Member

    Dear: Allan

    Sorry it took me so long to respond to your post I was running into a problem with my computer. No pins EN1 and EN2 are your pin inputs and outputs to your encoder. EN1 which stands for encoder 1 is your pins for your first encoder. Pins EN2 which stands for encoder two is your second encoder. Good luck.

    From: Noah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago in reply to Former Member

    Look to this for help.

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to nschreiber0813

    is this what you mean    terminal.print(“En1:”); terminal.print(enc1,HEX); terminal.print(“ “); terminal.print(status,HEX); terminal.print(“ “);

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • nschreiber0813
    0 nschreiber0813 over 11 years ago in reply to Former Member

    Give this code a shot I am pretty sure it will workimage

     

     

    //Basic Micro RoboClaw Packet Serial Mode.

    //Switch settings: SW3=ON, SW4=ON, SW5=ON

    #include “BMSerial.h”

    #include “RoboClaw.h”

    #define address 0x80

    #define Kp 0x00010000

    #define Ki 0x00008000

    #define Kd 0x00004000

    #define qpps 44000

    BMSerial terminal(0,1);

    RoboClaw roboclaw(5,6);

    void setup() {

    terminal.begin(38400); roboclaw.begin(38400);

    roboclaw.SetM1Constants(address,Kd,Kp,Ki,qpps); roboclaw.SetM2Constants(address,Kd,Kp,Ki,qpps);

    }

    void loop() {

    uint8_t status;

    bool valid;

    uint32_t enc1= roboclaw.ReadEncM1(address, &status, &valid);

    valid = terminal.print("Encoder1:") && terminal.print(encl,HEX) && terminal.print(" ") && terminal.print(status,HEX) && terminal.print(" ");

    uint32_t enc2 = roboclaw.ReadEncM2(address, &status, &valid);

    valid = terminal.print("Encoder2:") && terminal.print(enc2,HEX) && terminal.print(" ") && terminal.print(status,HEX) && terminal.print(" ");

    uint32_t speed1 = roboclaw.ReadSpeedM1(address, &status, &valid);

    valid = terminal.print("Speed1:") && terminal.print(speed1,HEX) && terminal.print(" ");

    uint32_t speed2 = roboclaw.ReadSpeedM2(address, &status, &valid);

    valid = terminal.print("Speed2:") && terminal.print(speed2,HEX) && terminal.print(" ");

    terminal.println();

    delay(100);

    }

     

     

    From: Noah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube