Author Topic: Serial Interfacing with DC Motor  (Read 3042 times)

0 Members and 1 Guest are viewing this topic.

Offline shyam4uallTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Serial Interfacing with DC Motor
« on: January 07, 2009, 12:40:57 PM »
I want to drive 2 DC motors through PC serial port via microcontroller(Atmega 8).

I am struck with the programming part(WinAVR).Please help me.

What i want is that when I send "1" the two motors should rotate clockwise(forward) and when "2" one should rotate clockwise another anti clockwise (left/right) and same for backward movement.

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 637
  • Helpful? 0
  • It's called the future ... We like it here
    • orgcrime.net
Re: Serial Interfacing with DC Motor
« Reply #1 on: January 07, 2009, 12:55:31 PM »
Where are you "struck"? what code do you have? or do you have nothing?

btw you're going to need a motor driver to.
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline shyam4uallTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: Serial Interfacing with DC Motor
« Reply #2 on: January 08, 2009, 12:54:54 AM »
Well i have nothing.I have seen some examples where a character is send from PC like "C" and "[C]" is send back to PC.I have to modify those codes.

Yeah i have to use a MAX232 and motor driver.I am confused that after sending a command for forward movement for example let it be "1" and storing it in a variable,now after this how do i send the data to the output pins.

can it be like this :

if(temp=="1")
PORTD=temp;

also how to handle those buffers ?
 

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Serial Interfacing with DC Motor
« Reply #3 on: January 09, 2009, 08:50:22 PM »
which microcontroller?

which motor driver?

Offline shyam4uallTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: Serial Interfacing with DC Motor
« Reply #4 on: January 10, 2009, 06:52:06 AM »
I am using Atmega8 and L293D.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Serial Interfacing with DC Motor
« Reply #5 on: January 10, 2009, 08:25:51 AM »
Ok I recommend following the UART tutorial for the $50 Robot.

This will give you serial control.

To wire up the motor driver just follow the motor driver datasheet. It might be really confusing at first, but do your best and show us what you got if you aren't sure.

It'll make sense if you break it into mini projects: wire up mcu, wire up motor driver, just get UART working, just get motor driver working

then the final part, get it all working together

Offline shyam4uallTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: Serial Interfacing with DC Motor
« Reply #6 on: January 10, 2009, 12:00:00 PM »
ok...let me try out those things first and then i will be back with the outcome.

Offline shyam4uallTopic starter

  • Jr. Member
  • **
  • Posts: 23
  • Helpful? 0
Re: Serial Interfacing with DC Motor
« Reply #7 on: January 18, 2009, 08:36:10 AM »
I want this logic to run a motor.

PC0 PC1 PC2 PC3
1      0     1    0     FORWARD (Keyboard W)
0      1     0    1     BACKWARD (Keyboard S)
1      0     0    1     LEFT (Keyboard A)
0      1     1    0     RIGHT (Keyboard D)

Quote
#define FORWARD (1<<0)|(1<<2) //FORWARD = 1010
#define BACKWARD (1<<1)|(1<<3) //BACKWARD = 0101
#define LEFT (1<<0)|(1<<3) //LEFT = 1001
#define RIGHT (1<<1)|(1<<2) //RIGHT = 0110
void main()
{
char data;

DDRC |=(1<<0)|(1<<1)|(1<<2)|(1<<3);

while(1)
{

data=USARTReadChar();

if(data=="W")
{
PORTC |= FORWARD;
}

if(data=="D")
{
PORTC |= RIGHT;
}

if(data=="S")
{
PORTC |= BACKWARD;
}

if(data=="A")
{
PORTC |= LEFT
}


I have this code (WinAVR) for Atmega8.Is the program correct ??

There are other functions as well but i m concerned with the main part.

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Serial Interfacing with DC Motor
« Reply #8 on: February 02, 2009, 09:15:19 AM »
To be honest, all that or'ing and << is highly non-intuitive.

You should just use my $50 Robot code (that uses the ATmega8), and call the port_on and port_off functions. Maybe not as elegant, but is much easier to debug and understand.

 


data_list