Electronic Circuits and Projects Forum



Ask

  1. #1
    zakuragi zakuragi is offline

    Ask

    1. i following this code for surely direction control motor DC trough serial port communication w/ linksys AP device

    Code :
    if ((PORTB_val & (left + right)) == (left + right))
      {    
        PORTB_val = PORTB_val - right;    
      }
     
      if ((PORTB_val & (forward + backward)) == (forward + backward))
      {
        PORTB_val = PORTB_val - backward; 
      }

    but finally i just have control 2 command : right & backward w/ the same time then left & forward same too
    anybody solve this problem


    Code :
    #define DEBUG 0
    #define WAIT_FOR_START 1
     
    unsigned char incomingByte = 0;
    unsigned long loop_count = 0;
    unsigned char horn = 32;
    unsigned char redLED = 64;
    unsigned char greenLED = 128;
     
    unsigned char forward = 1;
    unsigned char backward = 2;
    unsigned char left = 4;
    unsigned char right = 8;
     
    unsigned char PORTB_val;
     
     
    unsigned char in_char = 0;
     
    void setup() 
    {
     
    //PORTB = digital IO 8 - 13  
    //right, left, backwards, forward
     
      pinMode(8, OUTPUT);      // sets the digital pin as output
      pinMode(9, OUTPUT);      // sets the digital pin as output
      pinMode(10, OUTPUT);     // sets the digital pin as output
      pinMode(11, OUTPUT);     // sets the digital pin as output
     
      Serial.begin(9600);      // set up Serial library at 9600 bps
     
     }
     
    char get_char()
    {
    //Function that waits for a character from the serial port
    //If none are received, it returns 0.
    //The timeout is so that if the router stops sending data to the microcontroller,
    //the micrcontroller will stop driving the car, rather than just going forever with
    //the last command.  Timeout is around 250mS.
     
      while (loop_count < 30000)
      {
        loop_count++;
     
        if (Serial.available() > 0)
        {
          incomingByte = Serial.read();
          loop_count = 0;
          return incomingByte; 
        }
      }  
     
      loop_count = 0;
     
      #if DEBUG
            Serial.print('X', BYTE);
      #endif
     
      return 0; 
    }
     
    unsigned char wait_for_start()
    {
    //Waits for startup message from router serial port
    #if WAIT_FOR_START
     
      #if DEBUG
        Serial.println("Waiting...");
      #endif
     
      while(1)
      {
        if (get_char() == 'j' && get_char() == 'b' && get_char() == 'p' && get_char() == 'r' && get_char() == 'o') 
      { 
     
      #if DEBUG
          Serial.print("Passcode Accepted");
      #endif
     
          return 0; 
        }
      }
    #endif
    }
     
    void loop()                       
    {  
    //Function that processes input from serial port and drives the car based
    //on that input.
     
      in_char = get_char();
     
      //Split byte received in to upper and lower halves.
      PORTB_val = in_char & 0x0F;
     
     
      //Make sure the greenLED is turned on now.
     
      //The following IF statements are sanity checks to make sure that FORWARD and BACKWARD cannot be on at the same time
      //and that LEFT and RIGHT can't be on at the same time.
      if ((PORTB_val & (left + right)) == (left + right))
      {    
        PORTB_val = PORTB_val - right;    
      }
     
      if ((PORTB_val & (forward + backward)) == (forward + backward))
      {
        PORTB_val = PORTB_val - backward; 
      }
     
      //Write the processed values to the ports.
     
      PORTB = PORTB_val;
     
      #if DEBUG
        Serial.print(PORTB, HEX);
      #endif
     
    }
    my project control robot wifi with android device using wirelles linksys
    communication data using socket programming

    2. data from the client socket in the form of a byte and then through a serial port its happen analog voltage convert to digital voltage trought IC max 232. is it true? little be confused for procces data delivery in the form byte to data that understanding microcontroler to motor DC ?
    any idea

  2. Thread Starter #2
    zakuragi zakuragi is offline
    up
    0

  3. #3
    be80be be80be is offline
    The max232 is digital just higher levels to send a stronger signal post how you have the motors hooked up would help to figure this better.
    0
    Last edited by be80be; 27th April 2012 at 02:15 AM.
    Burt
    be80be
    “No beard, no belly, no guru…”

Tags
Similar Threads
Thread Starter Forum Replies Last Post
Ask for help Never01 Electronic Projects Design/Ideas/Reviews 1 17th February 2004, 10:40 AM
ASK or DTMF TransReciever.... johnmmbae Electronic Projects Design/Ideas/Reviews 0 17th November 2003, 04:23 AM
Transmitter circuits for QAM, BPSK and ASK Zippee General Electronics Chat 0 11th November 2003, 10:09 AM
Ask about low cost stereo DAC IC(UDA1330ATS) mikemikemike Electronic Projects Design/Ideas/Reviews 0 8th October 2003, 03:02 PM
Ask for the principle of error amplifier in PWM swear_swear Electronic Projects Design/Ideas/Reviews 2 29th July 2003, 01:07 AM
Electronic Circuits  |  Learning Electronics

Join our community with over 100,000 Members! It's free, easy and when you're logged in you have many more features! Click to register.
Page Time: 0.05782 seconds      Memory: 7,280 KB      Queries: 17      Templates: 0