transmeter

Bluebee 4.0 Master and Slave

Introduction

Recently, Cytron Technologies has come out with the latest version of Bluetooth wireless module, BlueBee 4.0! Today I am going to show you how to setup master and slave connections between these modules to do some brilliant stuff. Remember BlueBee 4.0 can be only slave device when operating in EDR mode, so the modules will be operating in BLE mode during the master and slave communication.

Before I get to the topic, just a reminder to all users especially for those who have been using Cytron BlueBee (older version of Cytron Bluetooth module). Like BlueBee, BlueBee 4.0 has 2 operation modes: transparent mode and AT mode. However what make BlueBee 4.0 special is it doesn’t require manual switching between these 2 modes (You will notice that BlueBee 4.0 doesn’t have any onboard mechanical switch like BlueBee). When the module is not connected to any other Bluetooth devices, it is in AT mode, when it is connected, it will enter transparent mode automatically!

 
 
 bluebee_intro
 
 
 

Software

  • Arduino IDE
    • Arduino Serial Monitor – send AT command and receive response from BlueBee 4.0.
 
Hardware

 

HARDWARE SETUP FOR BLUEBEE 4.0 MODULES

STEP 1Plug BlueBee 4.0 onto Xbee shield. Then stack the shield onto Arduino Board.
DSC05100
STEP 2Make sure USB are selected for both UART selector jumpers.
usbjumper
STEP 3: Connect Arduino RESET pin to GND.
DSC05101
STEP 4: Connect Arduino Board to the computer using USB cable.
 
 

CONFIGURE 1st BLUEBEE 4.0 AS SLAVE

  • Grab one of the modules and set up the hardware as stated in HARDWARE SETUP FOR BLUEBEE 4.0 MODULES.
  • Open Arduino IDE, choose the correct COM number for your Arduino Uno. For this example, COM24 is used.

com port

 

  • Then open serial moniter and set up Arduino Serial Monitor with settings below.
    • 115200 Baud
    • No line ending

baud

  • Below is the list of AT commands that will be used in configuration of BlueBee 4.0 as slave module. Type ALL AT commands in Arduino Serial Monitor.
STEPS AT COMMANDS DESCRIPTION
1 AT If the result returns “OK”, it means you have successfully communicate with the module
2 AT+RESET If the result returns “OK+RESET”, it means you have successfully RESET the module.
3 AT+ADDE? The result returns “OK+Get:[EDR address]”, Bluebee module EDR address
4 AT+ADDB? The result returns “OK+Get:[BLE address]”, Bluebee module BLE address
5 AT+BAUD6 The result returns “OK+Set:6”,   Baudrate of number 6 is 115200. 115200 is default Baudrate for this module
6 AT+PARI0 The result returns OK+Set:0, Set UART parity bit to Parity none. Default: 0
7 AT+FLOW0 The result returns OK+Set:0, Set hardware flow control switch to off . Default: 0
8 AT+STOP0 The result returns OK+Set:0, Set UART stop bit 0-1 stop bit . Default: 0
9 AT+PINE1234 The result returns OK+Set:1234, Set Password for bluetooth module. Max Length: 8
10 AT+NAMBBluebee 4.0 Slave The result returns OK+Set:Bluebee 4.0 Slave, BLE Device name
11 AT+NAMEBluebee 4.0 Slave The result returns OK+Set:Bluebee 4.0 Slave, EDR Device name
12 AT+ROLB0 The result returns OK+Set:0, Set module as slave. 0 – Slave & 1 – Master
13 AT+CLEAB If the result returns “OK+CLEAB”, it means you have successfully clear previous device address.
14  AT+RESET Reset the module to allow changes to take effect.

 

  • Change UART jumpers to D0 and D1.

 

CONFIGURE 2nd BLUEBEE 4.0 AS MASTER

  • Before you do anything to setup BlueBee 4.0 as master device, make sure 1st BlueBee 4.0 (slave) is turned on and stay VERY CLOSE to 2nd BlueBee 4.0.
  • Grab 2nd BlueBee 4.0 module and set up the hardware as stated in HARDWARE SETUP FOR BLUEBEE 4.0 MODULES. (same as 1st BlueBee 4.0)
  • Open Arduino IDE, choose the correct COM number for your 2nd Arduino Uno Board.
  • Then open serial moniter and set up Arduino Serial Monitor with settings below.
    • 115200 Baud
    • No line ending
  • Type ALL AT commands below in Arduino Serial Monitor.
    • STEP 1 : AT
    • STEP 2 : AT+RESET
    • STEP 3 : AT+ADDE?
    • STEP 4 : AT+ADDB?
    • STEP 5 : AT+BAUD6
    • STEP 6 : AT+PARI0
    • STEP 7 : AT+FLOW0
    • STEP 8 : AT+STOP0
    • STEP 9 : AT+PINE1234
    • STEP 10 : AT+NAMBBluebee 4.0 Master
    • STEP 11 : AT+NAMEBluebee 4.0 Master
    • STEP 12 : AT+ROLB1**
    • STEP 13 : AT+RESET**
    • STEP 14 : AT+CLEAB**
 
  • Change UART jumpers to D0 and D1

** Very IMPORTANT 

These steps are critical because of the nature of this BlueBee 4.0 module. If it is configured as master and it has not connected to any device before, it will start searching for nearby first BLE slave device and connect to it. Once they are connected, the slave address will be stored in master device. Every time master device powers up, it will look for this address only to connect. If slave device with this address is powered up too, they will be automatically connected. Why will I say it is critical? Because BlueBee 4.0 will connect to any BLE device even MI phone (its Bluetooth is BLE type) at long distance. This is my experience – for once BlueBee 4.0 automatically connects to my neighbour’s MI phone after I have configured it as master and there is no BlueBee 4.0 slave device around. Turns out I have to reset the module and quickly set it as slave once it powers up. 

STEP 12 – 13 are important to make sure your master device is connected to your desired slave device. After STEP 12, make sure your desired slave device is powered on and stays close to master device before proceed to STEP 13. After STEP 13, wait for couple of seconds to allow them to connect. (You will notice their connection when their red LEDS turn on and stay lit)

If nothing happens, your master device might have connected to other device before and the old binding address still exists. Proceed to STEP 14 while your slave device is still powered on and stays close. This will erase the previous binding address, allowing master device to search for new device to connect. The effect will immediately be applied after the command is entered.

My Application:

Now I have successfully setup master and slave connection between 2 BlueBee 4.0 modules, what can I do next? After thinking for a while, I came up with a suitable application for it. Basically in this application, what I want to do is control LED brightness and RC servos connected to CT-UNO + master module via Bluetooth with potentiometer and push button connected to CT-UNO + slave module. When  I push the push button the slave module will send high or low value to master module to control LED on or off. When I rotate the potentiometer, the slave module will send the analog value to master module to control LED brightness. When I rotate another potentiometer the slave will send the value to master module to control the position of RC servo.

Circuit diagram:

The connection for potentiometer and push Button to BlueBee 1 is shown in fritzing schematic diagram below or frizting file here :

Transmeter

transmeter

 

The connection for Servo and 2 LEDs to BlueBee 2 is shown in fritzing schematic diagram below or frizting file here :

receiver

receiver

CODE OVERVIEW FOR SLAVE :


int potpin = A0;
int potpin1 = A2;
byte LEDState=0;
unsigned int val;
unsigned int val1;
void setup()
{
Serial.begin(115200);
}
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 225);
val1 = analogRead(potpin1);
val1 = map(val1, 0, 1023, 0, 225);
writeServo(val);
writeLED(val1);
if(digitalRead(A1)==0)
{
while(digitalRead(A1)==0); //wait for release
LEDState=!LEDState;
writeLEDonoff(LEDState);
}
delay(40);
}
void writeServo(byte pos)
{
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write('S');
Serial.write(pos);
}
void writeLED(byte Brightness)
{
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write('B');
Serial.write(Brightness);
}
void writeLEDonoff(byte onoff)
{
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write('L');
Serial.write(onoff);
}

CODE OVERVIEW FOR MASTER:


const char ledPin = 13; //red
#include <Servo.h>
Servo myservo;
byte packet[4];
byte rcvState=0;
void setup()
{
Serial.begin(115200); //initialize serial communication with baudrate = 9600bps
Serial.flush(); //flush out the contents in the receive buffer
pinMode(ledPin,OUTPUT); //set the led2 (or digital pin 13) as output
pinMode(11,OUTPUT);
myservo.attach(9,800 ,2200);
rcvState=0;
}
void loop()
{
while(Serial.available()<4); //wait for 4 bytes
for(int i=0;i<4; i++) //read 4 bytes
{
packet[i]=Serial.read();
}
if(packet[0]==0xFF && packet[1]==0xFF) //header verified correct
{
if(packet[2]=='S') //servo packet
{
myservo.write(packet[3]);
}
else if(packet[2]=='L')
{
digitalWrite(ledPin, packet[3]);
}
else if(packet[2]=='B')
{
analogWrite(11,packet[3]);
}
}
}

 

VIDEO:

 

REFERENCE:

 

ATTACHMENT:

Buy

Leave a Reply

Your email address will not be published. Required fields are marked *