Newb Question

I’m new to bluetooth communication devices and I just bought the Serial port bluetooth module (Master/Slave) [WLS123A1M].

I tought I would just have to power on the board and connect to it with my PC via bluetooth and that I would then be able to program it as I would like it to work.

But as I powered it on it was not discoverable and I’ve been unable to go further than this…

I’m powering it with my seeeduino mega with the 3.3V pin and I’ve connected the TX–>RX and RX–>TX between the 2 boards… I also added the 2 leds on pin PIO10 and PIO11 to get feedback from the bluetooth chip. I get the blue led (PIO11) flashes 2 times/s wich means it’s disconnected.

So can someone tell me what I’m doing wrong…

Do I have to program the chip to be discoverable and how can it be done ?

Thanks in advance.

K-OTIX

Hi,

Your connect is fine.
BTW: which mode you use the bluetooth module as? If you want to use the PC to send the data to it, you should set the bluetooth module as a slave. And you can find the equipment on the PC. Here is the demo code of the Arduino which set the the bluetooth module as slave, you can refer to it.

[code]
#include <LiquidCrystal.h>
#include <NewSoftSerial.h>
#include <string.h>

NewSoftSerial mySerial(11, 12);//pin2-Rx,pin3-Tx
//LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

char addrBuffer[64];
int addrLen = 0;
char specName[]=“seeedstudio”;

void setup()
{
Serial.begin(9600);
Serial.println(“Goodnight moon!”);

// set the data rate for the NewSoftSerial port
mySerial.begin(38400);
//mySerial.println(“Hello, world?”);

//lcd.print(“hello world”);//display “hello world” on lcd module
//lcd.setCursor(0, 1);//display received info on the next row of LCD

}
void FlashLed(unsigned char ledPin,int times, int interval)
{
pinMode(ledPin,OUTPUT);
for(int i = 0; i < times; i++)
{
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(ledPin,LOW);
delay(interval);
}
}

void CheckOK()
{
//Serial.print("\r\n\r\n**********start**************");
char a,b;
while(1)
{
if(int len = mySerial.available())
{
a = mySerial.read();
//Serial.print(a);
if(‘O’ == a)
{
b = mySerial.read();
//Serial.print(b);
if(‘K’ == b)
{
Serial.print(“OK”);
break;
}

}

}
}

while( (a = mySerial.read()) != -1)
{
//Serial.print(a);
}

//Serial.println("\r\n**over");
}
void GetSlaveAddr(char *addr,int *addrLen,char *specName, int nameLen)
{
char a,b;

while(1)
{
if(int len = mySerial.available())
{
a = mySerial.read();
Serial.print(a);
if(’=’ == a)
{
while(1)
{
int i = 0;
a = mySerial.read();
Serial.print(a);
if( a != -1)
{
//Serial.print(“break1”);
if( ‘;’== a)
{
delay(500);
*addrLen = i;
char tempName[20];
for(int j = 0;j < nameLen; j++)
{
a = mySerial.read();
Serial.print(a);

            if('+' == a)
            {
              //Serial.println("break1");
              break;
            }
            else
            {
              tempName[j] = a;
            }
          }
          int flag = 0;
          for(int k = 0; k < nameLen; k++)
          {
            if(tempName[i] != specName[i])
            {
              flag = 1;
            }
          }
          if(0 == flag)
          {
            //Serial.print("break2");
            return;
          }
          else
          {
            //Serial.print("continue");
            break;
          }
        }
        else
        {
          addr[i++] = a;
        }
      }
    }
  }
}

}
}
void loop()
{

// mySerial.print("\r\n+STWMOD=0\r\n");
//delay(1000);
//enable been inquired
mySerial.print("\r\n+INQ=1\r\n");

while(1)
{
if(mySerial.available())
{
if(mySerial.read() == ‘4’)
{
Serial.println(“OK OK!”);
}
if(mySerial.read() == ‘3’)
{
mySerial.print("\r\n+INQ=1\r\n");
}
}
}

}[/code]
BluetoothBeeSlaveTest.zip (1.37 KB)
LiquidCrystal.zip (14.7 KB)
NewSoftSerial.zip (7.43 KB)

OK… That’s a lot of information you’re giving me here…

My goal is to set the Bluetooth module so it could be a slave and being able to send some chars from my pc to the module.

For now I’ve been able to access the settings of the chip by passing thru the serial of my seeeduino board giving me the opportunity to put it as slave and to try many different settings.

I’ve been able to connect to it 1 time for about 50 minutes. I had to do this routine -->

  1. Set it as master (+STWMOD=1)
  2. Put it in inquiring mode (+INQ=1)
  3. Stop the inquiring mode (+INQ=0)
  4. Set it as slave (+STWMOD=0)
  5. Put it in inquiring mode (+INQ=1)

After these 5 steps, I’ve been able to connect my macbook to the bluetooth chip and I’ve been able to send data to the chip via bluetooth and receive it thru the seeeduino and then to another PC via the usb hook to the board.

After it disconnected for no reason (Always stayed powered) I’ve never been able to reconnect to it…
I’ve never been able to make it work while the settings for auto-reconnect were “on”
maybe that is the problem

@SQX
From what I understand from your code is that the seeeduino should be initiating the bluetooth module ?


char addrBuffer[64];
int addrLen = 0;
char specName[]="seeedstudio";

void GetSlaveAddr(char *addr,int *addrLen,char *specName, int nameLen)
{
  char a,b;
  
  while(1)
  {
     if(int len = mySerial.available())
    {
      a = mySerial.read();
      Serial.print(a);
      if('=' == a)
      {
        while(1)
        {
          int i = 0;
          a = mySerial.read();
          Serial.print(a);
          if( a != -1)
          {
            //Serial.print("break1");
            if( ';'== a)
            {
              delay(500);
              *addrLen = i;
              char tempName[20];
              for(int j = 0;j < nameLen; j++)
              {
                a = mySerial.read();
                Serial.print(a);
              
                if('+' == a)
                {
                  //Serial.println("break1");
                  break;
                }
                else
                {
                  tempName[j] = a;
                }
              }
              int flag = 0;
              for(int k = 0; k < nameLen; k++)
              {
                if(tempName[i] != specName[i])
                {
                  flag = 1;
                }
              }
              if(0 == flag)
              {
                //Serial.print("break2");
                return;
              }
              else
              {
                //Serial.print("continue");
                break;
              }
            }
            else
            {
              addr[i++] = a;
            }
          }
        }
      }
    }
  }
}

void loop()
{
  
// mySerial.print("\r\n+STWMOD=0\r\n");
  //delay(1000);
  //enable been inquired
  mySerial.print("\r\n+INQ=1\r\n");
  
  while(1)
  {
    if(mySerial.available())
    {
      if(mySerial.read() == '4')
      {
        Serial.println("OK OK!");
      }
      if(mySerial.read() == '3')
      {
        mySerial.print("\r\n+INQ=1\r\n");
      }
    }
  }
}

Is this the function I should be using to initiate the connection between the chip and my PC ?

Aside from all this do you know how to do multi tasking with threads with an Arduino ?

BTW: Thanks alot for your help !!!

KOTIX

Hi KOTIX

After it disconnected for no reason (Always stayed powered) I've never been able to reconnect to it...

You should also stay powered the bluetooth module of the master and connect them again.

From what I understand from your code is that the seeeduino should be initiating the bluetooth module ?

The the seeeduino will be initiating the bluetooth module again when power on. The bluetooth should be put in inquiring mode again(+INQ=1) or you can’t fine the equipment.

Is this the function I should be using to initiate the connection between the chip and my PC ?

Yes, so you should set the inquiring mode and connect them again.

Aside from all this do you know how to do multi tasking with threads with an Arduino ?

Sorry, I have no this experience. You can give me the info when you realize it.

Regard,
-qingxiao

HI every one,
Could you help me please I have got similar Bluetooth module.
I would like to use it in slave module paired with arduino mega
her is the code

[code]void setup() {
// connect to computer
Serial.begin(9600);
// connect to bluetooth module
Serial1.begin(115200);
// set proper baud rate
Serial1.write("\r\n+STBD=115200\r\n");
// set mode to slave
Serial1.write("\r\n+STWMOD=0\r\n");
}

void loop() {
int buf_size;
// serial buffer size from arduino docs + 0 terminator
char buf[129];
char msg_buf[250];
buf_size = Serial1.available();
if (buf_size > 0) {
sprintf(msg_buf, “Buffer size: %i”, buf_size);
Serial.println(msg_buf);
Serial.print(“Buffer hex content:”);
for (int i=0; i < buf_size; i++) {
buf[i] = Serial1.read();
sprintf(msg_buf, " %X", buf[i]);
Serial.print(msg_buf);
}
buf[buf_size] = 0;
sprintf(msg_buf, “\nBuffer string content: %s”, buf);
Serial.println(msg_buf);
char* cmd = trim(buf);
if (strcmp(“WORK:SLAVER”, cmd) == 0) {
Serial.println(“Starting inquiring”);
Serial1.write("\r\n+INQ=1\r\n");
}
else if (strcmp(“ping”, cmd) == 0) {
Serial1.println(“pong”);
}
}
delay(100);
}

char* trim(char* str) {
char *end;
while(*str < 33)
str++;
end = str + strlen(str) - 1;
while(end > str && *end < 33)
end–;
*(end+1) = 0;
return str;
}[/code]

But after this my Bluetooth module is not discoverable.