Author Topic: need help with wifi-bluetooth  (Read 1649 times)

0 Members and 1 Guest are viewing this topic.

Offline monsieurpoTopic starter

  • Full Member
  • ***
  • Posts: 51
  • Helpful? 0
need help with wifi-bluetooth
« on: May 07, 2010, 02:39:53 PM »
hi every body i need a small turorial on the wifi or bluetooth control like how to program servo

exemple:

i press w button and the robot leg will move


i really need to understand because now im confuse


thanks
« Last Edit: May 08, 2010, 08:32:27 AM by monsieurpo »

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots

Offline monsieurpoTopic starter

  • Full Member
  • ***
  • Posts: 51
  • Helpful? 0
Re: need help with wifi-bluetooth
« Reply #2 on: May 12, 2010, 01:57:14 PM »
http://www.societyofrobots.com/electronics_bluetooth_robot.shtml

thanks it really help me but i want to make a robot that i can control via my computer so did you have another page like that can show me how to program a microcontroler for a bluetooth control

(like your erp but just wheels)

Offline richiereynolds

  • Full Member
  • ***
  • Posts: 112
  • Helpful? 3
Re: need help with wifi-bluetooth
« Reply #3 on: May 12, 2010, 04:00:24 PM »
We'd need a lot more information to give you specifics, what exactly are you trying to do with the servos? What mcu are you using? What language are you programming in?

I've done some basic bluetooth using avr chips and webbotlib in c - my header is below, obviously yours will need to be different depending on what you're doing, note that mine calls functions to do the things I need, yours will be calling your own functions to move a leg or whatever.

I'd call initBluetooth in my main code and then process what the user types in receiveUserByte.
In my case that's move the vehicle if it's an arrow key, maybe print to an lcd, allow the user to choose a new algorithm for the vehicle and ignore certain control characters etc. It's really me just messing about trying stuff out to be honest.

If you can give us some more detail we can maybe give you something more relevant.


Code: [Select]
#ifndef bluetooth_h
#define bluetooth_h

#include "algorithms.h"
#include "printExtensions.h"

#define BLUETOOTH_UART UART0
#define BLUETOOTH_BUF_SIZE 33

// buffer to hold bluetooth input
char bluetoothBuf[BLUETOOTH_BUF_SIZE];

/****************  functions ****************/
void printAlgorithmMenu()
{
    rprintf("\nChoose a new algorithm\n");

    rprintf("a = Avoid Obstacles\n");
    rprintf("f = Follow Object\n");
    rprintf("r = Remote Control\n");
}

void receiveUserByte(unsigned char cByte)
{
    static int byteNum = 0;
    static boolean waitingForAlgorithmChoice = false;

    if(waitingForAlgorithmChoice)
    {
        waitingForAlgorithmChoice = false;
        switch(cByte)
        {
            case 'a': algorithm = avoidObstacles; rprintf("avoidObstacles!");             break;
            case 'f': algorithm = followObject;   rprintf("followObject!");               break;
            case 'r': algorithm = remoteControl;  rprintf("remoteControl!"); goNowhere(); break;
            default : waitingForAlgorithmChoice = true; printAlgorithmMenu();             break;
        }
    }
    else
    {
        boolean processed = true;

if(algorithm == remoteControl)
{
    switch(cByte)
    {
        case 68 : goLeft();     rprintf("left!\n");    break;
case 67 : goRight();    rprintf("right!\n");   break;
case 66 : goBackward(); rprintf("reverse!\n"); break;
case 65 : goForward();  rprintf("go!\n");      break;
        case '/': goNowhere();  rprintf("stop!\n");    break;
case '[':                                      break;
        default : processed = false;
            }
}
if(algorithm != remoteControl || !processed)
        {
            if(cByte == 13 || byteNum == BLUETOOTH_BUF_SIZE - 2)
            {
                if(cByte != 13)
                {
                    bluetoothBuf[byteNum++] = cByte;
                }
                bluetoothBuf[byteNum] = '\0';
                displayClear(&lcd);
                rrprintf(displayGetWriter(&lcd), "%s", bluetoothBuf);
                byteNum = 0;
            }
            else if(cByte == '#')
            {
                printAlgorithmMenu();
                waitingForAlgorithmChoice = true;
                byteNum = 0;
            }
            else
            {
                if(isprint(cByte))
                {
                    bluetoothBuf[byteNum++] = cByte;
                }
            }
        }
    }
}

void initBluetooth()
{   
    uartInit(BLUETOOTH_UART, 115200);
    uartAttach(BLUETOOTH_UART, &receiveUserByte);
}

#endif // bluetooth_h


Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: need help with wifi-bluetooth
« Reply #4 on: May 12, 2010, 09:26:00 PM »
If you use the Axon, you just download the source code and upload it to your robot . . . finished.

How to Make a Robot with Axon II MCU

Offline monsieurpoTopic starter

  • Full Member
  • ***
  • Posts: 51
  • Helpful? 0
Re: need help with wifi-bluetooth
« Reply #5 on: May 14, 2010, 05:13:08 PM »
We'd need a lot more information to give you specifics, what exactly are you trying to do with the servos? What mcu are you using? What language are you programming in?

I've done some basic bluetooth using avr chips and webbotlib in c - my header is below, obviously yours will need to be different depending on what you're doing, note that mine calls functions to do the things I need, yours will be calling your own functions to move a leg or whatever.

I'd call initBluetooth in my main code and then process what the user types in receiveUserByte.
In my case that's move the vehicle if it's an arrow key, maybe print to an lcd, allow the user to choose a new algorithm for the vehicle and ignore certain control characters etc. It's really me just messing about trying stuff out to be honest.

If you can give us some more detail we can maybe give you something more relevant.


Code: [Select]
#ifndef bluetooth_h
#define bluetooth_h

#include "algorithms.h"
#include "printExtensions.h"

#define BLUETOOTH_UART UART0
#define BLUETOOTH_BUF_SIZE 33

// buffer to hold bluetooth input
char bluetoothBuf[BLUETOOTH_BUF_SIZE];

/****************  functions ****************/
void printAlgorithmMenu()
{
    rprintf("\nChoose a new algorithm\n");

    rprintf("a = Avoid Obstacles\n");
    rprintf("f = Follow Object\n");
    rprintf("r = Remote Control\n");
}

void receiveUserByte(unsigned char cByte)
{
    static int byteNum = 0;
    static boolean waitingForAlgorithmChoice = false;

    if(waitingForAlgorithmChoice)
    {
        waitingForAlgorithmChoice = false;
        switch(cByte)
        {
            case 'a': algorithm = avoidObstacles; rprintf("avoidObstacles!");             break;
            case 'f': algorithm = followObject;   rprintf("followObject!");               break;
            case 'r': algorithm = remoteControl;  rprintf("remoteControl!"); goNowhere(); break;
            default : waitingForAlgorithmChoice = true; printAlgorithmMenu();             break;
        }
    }
    else
    {
        boolean processed = true;

if(algorithm == remoteControl)
{
    switch(cByte)
    {
        case 68 : goLeft();     rprintf("left!\n");    break;
case 67 : goRight();    rprintf("right!\n");   break;
case 66 : goBackward(); rprintf("reverse!\n"); break;
case 65 : goForward();  rprintf("go!\n");      break;
        case '/': goNowhere();  rprintf("stop!\n");    break;
case '[':                                      break;
        default : processed = false;
            }
}
if(algorithm != remoteControl || !processed)
        {
            if(cByte == 13 || byteNum == BLUETOOTH_BUF_SIZE - 2)
            {
                if(cByte != 13)
                {
                    bluetoothBuf[byteNum++] = cByte;
                }
                bluetoothBuf[byteNum] = '\0';
                displayClear(&lcd);
                rrprintf(displayGetWriter(&lcd), "%s", bluetoothBuf);
                byteNum = 0;
            }
            else if(cByte == '#')
            {
                printAlgorithmMenu();
                waitingForAlgorithmChoice = true;
                byteNum = 0;
            }
            else
            {
                if(isprint(cByte))
                {
                    bluetoothBuf[byteNum++] = cByte;
                }
            }
        }
    }
}

void initBluetooth()
{   
    uartInit(BLUETOOTH_UART, 115200);
    uartAttach(BLUETOOTH_UART, &receiveUserByte);
}

#endif // bluetooth_h

well i just want to make a 2 wheeld robot