Author Topic: Help Me mega 2560 arduino (student)  (Read 6044 times)

0 Members and 1 Guest are viewing this topic.

Offline wise318Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Help Me mega 2560 arduino (student)
« on: October 27, 2011, 11:02:29 AM »
Hi i am curious and desperate to get an answer my oost has not been replied regarding te connection of mega 2560 to motor driver


Has anyone used mega 2560 to control your robot movement. Can please share your wiring connection to motor driver

Offline newInRobotics

  • Supreme Robot
  • *****
  • Posts: 1,015
  • Helpful? 48
  • N.I.R.
Re: Help Me mega 2560 arduino (student)
« Reply #1 on: October 27, 2011, 11:13:38 AM »
In Your previous post I have noticed that Sabertooth motor driver is being used. If so, analog voltage has to be fed into it to controll direction and speed of a motor. So, You can either use DAC from Your uC board (if it has one), or You can use PWM with low pass filter.
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian W

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Help Me mega 2560 Arduino (student)
« Reply #2 on: October 27, 2011, 11:36:13 AM »
Took me awhile to jump through your recent posts, to find out which motor controller you had.  I believe it is a sabertooth 2x25, which you can hook up several different ways.

The Sabertooth you are using can be controlled 4 different ways (Analog, RC, simple Serial, and Packet serial).  Personally I would go with Packet Serial with the Arduino 2560.  I would connect it up to one of the 4 hardware serial ports (Not 0 as this is your USB).  You need to run a wire from the TX of the USART to I believe S1 on the controller and RX to S2 and run a ground wire between the two boards.

I have not done this with your setup, but have done similar with Arduino to a Basic Micro Roboclaw controller.  (I did this with a non mega Arduino board using software serial to talk to the roboclaw), but it would be even simpler with the MEGA.

Kurt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Help Me mega 2560 arduino (student)
« Reply #3 on: October 27, 2011, 01:09:35 PM »
WebbotLib can do it - ie support motor driver
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline wise318Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Help Me mega 2560 Arduino (student)
« Reply #4 on: October 28, 2011, 04:47:30 AM »
Thx this my post i m better link it here . Sorry i am bot specificly mentioned . Yes i am going to use packetized mode meaning using arduino to execute commamd to sabertooth. So i need tx And Rx from arduino to s1 and s2 on sabertooth.


Do i Need to connect 0v on sabertooth ? And if i am not erong to power arduino i need 5v from sabertooth connecting to 5v arduino am i right.


Next what are programming and library i could use any simple program that i can write like go straingh 10 m and turn left 5 m. Somekinds of simple program for arduino

Thanks a lot for the reply



Hi , anyone  used sabertooth to control 2 motor with arduino 2560, I wonder how is the connection,

Am i right

This the photo attached , I have not done the wiring and checking with the society here :)


Power: 5v mega to 5 v sabertooth
Mega's Tx2 pin connects to the S1 of Sabertooth
Mega's RX2 pin connects to the S2 of Sabertooth
Mega's GND pin connects to the 0V of Sabertooth


 I intend to use position and speed control of 2 motors, I am not sure if it is possible with sabertooth, Is there possible to upload program to arduino and by pressing any switch the arduino send the progams to run the motor according to the program, Like autonomous. Please enlighten me and correct me if I am wrong.

This the datasheet provided but has no connection show on arduino
http://www.dimensionengineering.com/datasheets/Sabertooth2x25.pdf



Q2 do i need this breadboard, i had no idea the purpose for this,

Took me awhile to jump through your recent posts, to find out which motor controller you had.  I believe it is a sabertooth 2x25, which you can hook up several different ways.

The Sabertooth you are using can be controlled 4 different ways (Analog, RC, simple Serial, and Packet serial).  Personally I would go with Packet Serial with the Arduino 2560.  I would connect it up to one of the 4 hardware serial ports (Not 0 as this is your USB).  You need to run a wire from the TX of the USART to I believe S1 on the controller and RX to S2 and run a ground wire between the two boards.

I have not done this with your setup, but have done similar with Arduino to a Basic Micro Roboclaw controller.  (I did this with a non mega Arduino board using software serial to talk to the roboclaw), but it would be even simpler with the MEGA.

Kurt
« Last Edit: October 28, 2011, 04:59:25 AM by wise318 »

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Help Me mega 2560 Arduino (student)
« Reply #5 on: October 28, 2011, 09:36:02 AM »
In my hookups, I don't use the output 5V from the Sabertooth to power my processor board, I use a separate hookup. I do for a few reasons. The first is that if you are connecting to the main power input for the Arduino board, this will go through a voltage regulator, which the spec for the board says that you can connect it to voltages between 7-20 volts.  The other reason is that I don't use the BEC of the the sabertooth, is I also hooked up a few servos to my Arduino for a Pan/Tilt hookup...

The Sabertooth does not have any support in it for telling it to go for some distance, like 5m.  Instead you simply tell it to drive one or both motors at some speed.  To go a specific distance you will most likely need something like encoders on the wheels, that tell you how far you have gone. You can hook up encoders to the Arduino, but they can eat up a lot of your processing power.  Alternatively there are motor controllers that do have encoder support built in, such as the Roboclaw from Basic Micro (http://www.basicmicro.com/RoboClaw-2x30A_p_46.html).  They do have commands that you can output by packet serial, that says things like, go this far at this speed.  But even this is somewhat tricky as if you say go for 5m, it will go for 5m and then start the stop process, so you may end up going 5.1m... So then you end up adding code to calculate how fast it will stop and when you wish to go 5m, you tell it 4.9...

Good Luck
Kurt

Offline wise318Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Help Me mega 2560 arduino (student)
« Reply #6 on: November 04, 2011, 06:33:45 AM »
Hi Kurt Update my Testing, after sometime, i managed to try the connection in the lab with a power supply I begin trying with the code available in the internet as followed,

 I Change the original program of pin 13 with l communication  TX 1 and RX 1 on (Arduino) connect to S1 and S2 sabertooth respectively, I power the sabertooth with power supply 6 V and has 2 of 6 V dc motor, However, after uploading the program and seemed that nothing happened on the sabertooth, However after i switch off the power supply, the motor seemed to have jerking effect.

I Selected Simplified Serial As seen from sites



1
#include <SoftwareSerial.h>

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN               1

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN              1

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE             9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD  127
#define SABER_MOTOR1_FULL_REVERSE  1

#define SABER_MOTOR2_FULL_FORWARD  255
#define SABER_MOTOR2_FULL_REVERSE  128

// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP             0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN,
                                             SABER_TX_PIN );

void initSabertooth( void )
{
  // Init software UART to communicate
  // with the Sabertooth 2x5
  pinMode( SABER_TX_PIN, OUTPUT );

  SaberSerial.begin( SABER_BAUDRATE );     

  // 2 second time delay for the Sabertooth to init
  delay( 2000 );

  // Send full stop command
  setEngineSpeed( SABER_ALL_STOP );
}

/*****************************************************
 * setEngineSpeed
 *
 * Inputs - cSpeed_Motor1 - Input a percentage of full
 *                          speed, from -100 to +100
 *
 *****************************************************/
void setEngineSpeed( signed char cNewMotorSpeed )
{
  unsigned char cSpeedVal_Motor1 = 0;

  unsigned char cSpeedVal_Motor2 = 0;
 
  // Check for full stop command
  if( cNewMotorSpeed == 0 )
  {
    // Send full stop command for both motors
    SaberSerial.print( 0, BYTE );

    return;
  } 
 
  // Calculate the speed value for motor 1
  if( cNewMotorSpeed >= 100 )
  {
    cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

    cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
  }
  else if( cNewMotorSpeed <= -100 )
  {
    cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

    cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
  }
  else
  {
    // Calc motor 1 speed (Final value ranges from 1 to 127)
    cSpeedVal_Motor1 = map( cNewMotorSpeed,
                           -100,
                            100,
                            SABER_MOTOR1_FULL_REVERSE,
                            SABER_MOTOR1_FULL_FORWARD );

    // Calc motor 2 speed (Final value ranges from 128 to 255)
    cSpeedVal_Motor2 = map( cNewMotorSpeed,
                           -100,
                            100,
                            SABER_MOTOR2_FULL_REVERSE,
                            SABER_MOTOR2_FULL_FORWARD );
  }

  // Fire the values off to the Sabertooth motor controller
  SaberSerial.print( cSpeedVal_Motor1, BYTE );

  SaberSerial.print( cSpeedVal_Motor2, BYTE );
}


void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
 
  initSabertooth( );
}

void loop() {
  setEngineSpeed(0);     // Zero is full stop
  setEngineSpeed(20);    // The minimum is twenty.
  setEngineSpeed(100);   // One hundred is the maximum.
}

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Help Me mega 2560 arduino (student)
« Reply #7 on: November 04, 2011, 08:04:47 AM »
Hi Again got your message, better to answer here, so that others can make use as well.

Since you are using a hardware serial port, you don't need to use the software serial to talk to the Arduino.

You should change the start of the program to look more like:

Quote

// Labels for use with the Sabertooth 2x5 motor controller

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE             9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD  127
#define SABER_MOTOR1_FULL_REVERSE  1

#define SABER_MOTOR2_FULL_FORWARD  255
#define SABER_MOTOR2_FULL_REVERSE  128

// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP             0

#define SaberSerial Serial1

void initSabertooth( void )
{
  SaberSerial.begin( SABER_BAUDRATE );     

  // 2 second time delay for the Sabertooth to init
  delay( 2000 );

  // Send full stop command
  setEngineSpeed( SABER_ALL_STOP );
}

The rest of the code should not have to change to use the hardware serial.  Also make sure the dip switches on your Sabertooth are properly set for packet serial mode at 9600 baud.

Kurt

Offline wise318Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Help Me mega 2560 arduino (student)
« Reply #8 on: November 04, 2011, 11:44:26 PM »
Hi Kurt, thx .You mean i should change the starting of the program with this, and set to packetized mode, Ini this program how the robot should behave. Is my connection correct using serial communicate   RX 1 and TX 1 to S1 and S2 of sabertooth.  Seem i executes the following program in simplified mode, the motor just run in one direction continuosly without stopping.

This is the first time i am using arduino and I am not too sure once i execute the program , and compiled, will it be executed on the sabertooth right away, or i need to create a trigger button. Seemed from the experiment, it run forever and even i rest my arduino. motor keep running .

what kind of movements were you created in your sabertooth project in the past, Care to share ? :) thanks a lot



Hi Again got your message, better to answer here, so that others can make use as well.

Since you are using a hardware serial port, you don't need to use the software serial to talk to the Arduino.

You should change the start of the program to look more like:

Quote

// Labels for use with the Sabertooth 2x5 motor controller

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE             9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD  127
#define SABER_MOTOR1_FULL_REVERSE  1

#define SABER_MOTOR2_FULL_FORWARD  255
#define SABER_MOTOR2_FULL_REVERSE  128

// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP             0

#define SaberSerial Serial1

void initSabertooth( void )
{
  SaberSerial.begin( SABER_BAUDRATE );    

  // 2 second time delay for the Sabertooth to init
  delay( 2000 );

  // Send full stop command
  setEngineSpeed( SABER_ALL_STOP );
}

The rest of the code should not have to change to use the hardware serial.  Also make sure the dip switches on your Sabertooth are properly set for packet serial mode at 9600 baud.

Kurt

« Last Edit: November 05, 2011, 05:50:39 AM by wise318 »

Offline KurtEck

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 12
Re: Help Me mega 2560 arduino (student)
« Reply #9 on: November 05, 2011, 08:25:07 AM »
Yes, you should change the start of your program to what I mentioned.

Yes the wiring you mentioned sounds correct, but in addition you need a ground wire between the two boards, as signals (electricity) can not flow if it does not have a return path to make the circuit.

The dip switches on the Sabertooth needs to be set correctly.  Dimension Engineering documents show what each switch does, or you can try their wizard: http://www.dimensionengineering.com/datasheets/Sabertoothdipwizard/start.htm

Note: looking closer at your program, it looks like it is using the simplified serial communications.  For 9600 baud I think it would be something like: 101011  But I am guessing as I depends on what type of battery you wish to init for...

On Arduino, you use the upload command to download your compiled program to your board. Don't remember which board you are using, but you need to configure the IDE to your board type.

Sometime soon, I will  upload my rover code.  It will probably be put up on the Lynxmotion forums, once their new Arduino board is ready to ship.

Kurt


Offline wise318Topic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: Help Me mega 2560 arduino (student)
« Reply #10 on: November 05, 2011, 11:31:59 AM »
Yes, you should change the start of your program to what I mentioned.

Yes the wiring you mentioned sounds correct, but in addition you need a ground wire between the two boards, as signals (electricity) can not flow if it does not have a return path to make the circuit.

The dip switches on the Sabertooth needs to be set correctly.  Dimension Engineering documents show what each switch does, or you can try their wizard: http://www.dimensionengineering.com/datasheets/Sabertoothdipwizard/start.htm

Note: looking closer at your program, it looks like it is using the simplified serial communications.  For 9600 baud I think it would be something like: 101011  But I am guessing as I depends on what type of battery you wish to init for...

On Arduino, you use the upload command to download your compiled program to your board. Don't remember which board you are using, but you need to configure the IDE to your board type.

Sometime soon, I will  upload my rover code.  It will probably be put up on the Lynxmotion forums, once their new Arduino board is ready to ship.

Kurt


Hi kurt, I am using 4 AA batery Alkaline and using DIP Swithc 9600, What is the IDE configuration for?, I am using Mega 2560, After connecting the ground, the motor does not seem to run. I hope my ground is correct, i connect the ground on the header pin on my arduino.

I will update again kurt, hope i can sort out the problem :)




 


Get Your Ad Here