Vorpal Factory Paired Bluetooth Modules

From Vorpal Robotics
Jump to: navigation, search

Contents

Introduction

The Vorpal Factory Paired Bluetooth Modules product is available from Amazon.com. It provides you with two inexpensive Bluetooth modules that are factory configured so that they auto-pair when power is applied. There is no easier way to get a fast, reliable transparent serial connection for projects involving Arduino, Rasberry Pi, and other microcontroller products.

What's in the package

The package contains:

  • Two HC05 Bluetooth modules, one configured as mastera and configured as slave. (The HC05 is the module with 6 pins but you typically only use 4 of them). The modules are labeled with a name such as VORPAL1234. This indentifies which slave it is configured to pair with.
  • Eight female-female Dupont cables, color coded, 10cm (2.5") long. These can be conveniently used to make connections for power and data to your microcontroller.

How are the modules configured?

NOTE: You don't need to fully understand this section in order to use the modules, this is provided for more advanced users.

The modules are both configured at a speed of 38,400 baud, no parity, 8 bits. The slave module has a name which is identical to the label you will find on it, for example VORPAL1234. This name will show up if you have a device such as an Android smartphone which can detect Bluetooth devices.

The MAC address of the slave is preconfigured in the master such that they auto-pair and connect when power is applied to both modules.

When unpaired, both modules will have a rapidly blinking red light. During pairing you may see the lights blink slowly a few times or go off for a couple of seconds. After pairing is successful, both modules will show a light pattern as follows: off for 2 seconds, two rapid blinks, off for two seconds, etc. Pairing normally only takes 5 to 10 seconds after both modules are powered on.

How fast are they?

The modules are factory configured at 38,400 baud. This means you can transmit approximately 4,000 to 4,500 bytes per second. This is plenty fast enough for robot control, remote sensor applications, etc. This will not be fast enough for some data intensive applications like camera transmissions, however.

The modules themselves can transmit faster than 38,400, however we have found there can be problems if the speed it too high. 38,400 is a good compromise, allowing enough speed for a very wide range of applications, but with high reliability.

What is the range of the radio signal?

Bluetooth is typically used for short-range applications. These modules are very reliable up to about 30 feet line-of-sight (in other words, nothing blocking the signal). When using these modules in your applications, try to mount the modules to your project such that they are not enclosed in metal or too close to large metal objects. Plastic generally doesn't reduce range much. Walls or other obstructions will also reduce the range considerably.

Is there error correction on the transmission?

No, there is no error correction built into the protocols the modules use. We have found that there can be occasional bad characters received, approximately 1 byte out of every 100 to 500 bytes depending on the situation. This is due to a number of factors such as how many other devices that use the 2.4 gHz radio band are nearby, how far the modules are apart, how fast your Arduino clock speed is, etc., so your results may vary.

For many applications, such as radio control of a robot, this amount of error is not really a problem. If you are transmitting motor speeds, every now and then there might be a twitch due to a bad packet. This would generally be acceptable.

If data reliability is very important to your application, you should design your system to detect errors. There are numerous ways to do this. A simple scheme is to start each transmission with a known value, such as the number 0, then follow that by a "checksum" which is created by summing the values of all the rest of the data and keeping only the lower byte. Then output the length of the data, then the data bytes one by one. On the receiving side, reject any packet that doesn't start with the known start byte (just flush any bytes received until you see the start byte), and reject any full packet that doesn't have the correct checksum. In some applications, you may need to implement a "retransmit" protocol to recover lost data. There are many other schemes for data checking which can be found on the Internet!

Can I operate multiple pairs in the same general area?

Yes, you can run many pairs of modules in the same room. Bluetooth uses a frequency hopping scheme combined with many different channels to ensure devices do not significantly interfere with each other. We have run 15 in a single room, within 30 feet of each other, with no problems at all. The maximum number is probably much higher than that. That makes these modules perfect for classroom use. You could have 15 or more groups of students using radio controlled projects in the same classroom.

Can I receive and transmit at the same time?

Absolutely! These modules provide a full duplex, transparent serial connection. That means your microcontrollers can be sending and receiving data from each other at the same time.

However, please note that even though the modules themselves are full-duplex, some other aspects of your software environment may make it hard to access this functionality if you don't take some care.

For example, the Arduino Serial ports pins, D0 and D1, use the microcontroller's built-in UART (hardware that implements serial transmission) and so can provide full duplex operation. The downside of using D0 and D1 and the Serial object is of course that you can't upload a new program to your Arduino without remembering to disconnecting power to the Bluetooth module during upload. (The UART is also used to upload programs so if you left a Bluetooth module actively connected there would be interference). In addition, you would be unable to use the Serial monitor while the Bluetooth module is powered on and connected to D0 and D1.

There is a standard Arduino library called SoftwareSerial that will allow you to use other pins for transmit and receive. Unfortunately, SoftwareSerial does not support simultaneous transmit and receive operations, so you would be limited to half-duplex, meaning you'd have to write your code so that one module talks first, then waits for a reply, ensuring they never transmit at the same time.

However, there are alternative packages such as altSoftwareSerial that do properly support full duplex operations on pins other than D0 and D1. The downside is, these packages are not a native part of the Arduino offering and my not be well supported at all times.

In any case, if full duplex operation is something you want to use, you certainly can do it, but you need to carefully choose how you attack the modules to your Arduino systems and which serial library will best meet your needs.

How do I connect the modules to Arduino or Similar Devices?

NOTE: The package includes Female-Female cables. These will work great if you're connecting either to an Arduino with an IO shield (male pins) or if you're connecting directly to an Arduino Nano, Pro Mini, or similar model which also typically provide male pins. However, if you are connecting directly to an UNO or similar model that provides female sockets, you would need a short Male-Male jumper, or just a piece of typical hookup wire, to make the connection work.

The HC05 has six pins, but you're not going to use two of them.

  • EN: (May be different labels on some units). You're not going to use this, leave it disconnected.
  • VCC: You should connect a RED Dupont jumper cable to this and connect it to a regulated +5v power supply that can provide at least 50 to 60 milliamps of power. For example, an Arduino UNO can provide the right power from its +5V pin. Do not connect this to unregulated battery power. Connecting this lead to a power supply greater than +6.0 volts will immediately destroy the module.
  • GND: Use a BLACK cable and connect this to the ground side of a power supply.
  • TXD: "Transmit Data". Use a YELLOW cable and connect this to a digital IO pin on your controller. For the Arduino examples used in this wiki page, connect it to digital pin 3 (of course, not the same Arduino as you used for the slave, the whole point of this is to let two different Arduinos communicate!). Again, any digital pin can typically be used.
  • RXD: "Receive Data". Use the GREEN cable and connect this to another digital IO pin. For the Arduino examples used in this wiki page, connect it to digital pin 2. Again, any digital IO pin should work.
  • STATE: (May be different label on some units.) Leave this disconnected, you don't need it for basic communications.

Once connected and power is turned on, both modules should light up. The lights will both blink rapidly at first. After about 5 to 10 seconds, the lights will show a pattern of 2 seconds off, then two quick blinks, the two seconds off, etc.

If either module will not light up at all, that's almost always due to power not being applied correctly. Disconnect power immediately and check connections again.

If the module gets hot, that probably means you reversed the VCC and GND pins. Unfortunately, this will destroy the module within a few seconds, so be very careful.

ARDUINO SAMPLE CODE

Here is sample code to send a message from one module to the other, assuming each one is connected to an Arduino. This code assumes you have two Arduino modules, one will transmit and the other receive. (You can of course write code that does both from either module, this code is being kept simple as an example.)

This code uses the SoftwareSerial library, which is a standard part of the Arduino IDE. This allows you to leave the hardware serial IO line free for debugging purposes, or to allow program upload. It is perfectly ok to use digital ports 0 and 1 for the TXD and RXD lines, but that's very inconvenient because you would need to disconnect the Bluetooth module before uploading a new program!

TRANSMITTING ARDUINO CODE

This code simply transmits the word "Hello!" once per second over the Bluetooth connection. It assumes digital IO port 2 is connected to RXD and digital IO port 3 is connected to TXD.

#include <SoftwareSerial.h>

SoftwareSerial BlueTooth(3,2);  // Tx goes to pin D3, Rx to pin D2

void setup() {  
  Serial.begin(9600);
  BlueTooth.begin(38400);
}

void loop() {
  BlueTooth.println("Hello!");
 
  delay(1000);
}

RECEIVING ARDUINO CODE

This code receives bytes one by one (if there are any available) and prints them out to the USB serial port. You can use the Ardunio IDE serial port monitor to see it working. It assumes digital IO port 2 is connected to RXD and digital IO port 3 is connected to TXD. You can use either of the modules, master or slave.

#include <SoftwareSerial.h>

SoftwareSerial BlueTooth(3,2);  // Tx goes to pin D3, Rx to pin D2

void setup() {  
  Serial.begin(9600);
  BlueTooth.begin(38400);
}

void loop() {
  if (BlueTooth.available()) {
      int c = BlueTooth.read();
      Serial.write(c);
   }
}

NOTES

  • The SoftwareSerial library in Arduino cannot simultaneously receive and transmit, although the Bluetooth modules are quite able to do this. There are alternative Arduino libraries that do not have this limitation, such as altSoftwareSerial. You can either use one of the alternatives that does support full duplex operation, or you can make sure your application alternates between sending and receiving data by designing your protocols in that way. For example, your application could have the master unit first transmit, then a protocol element tells the slave when it's time for it to respond.
  • It is also possible to use standard Serial instead of SoftwareSerial if you hook up the Bluetooth modules to digital pins 0 and 1. Remember to cross the wires, in other words TX on the Arduino should be going to RX on the Bluetooth module, and vice versa. In that case, you will need to remember to disconnect the RED wire from the module whenever you want to upload a new program to your Arduino, because digital pins 0 and 1 are also used for flashing new programs to the Arduino. However, because the Serial library uses an actual UART (hardware serial port) you can simultaneously receive and transmit using this method.
  • The manufacturer of these modules says they consume about 60 mA of current when pairing. We have found that to be safe you should make sure they get at least 100 mA of regulated 5V power. An Arduino Nano can supply this much from its +5V and GND pins. For example, we run these all the time from a Nano which is powered through its VIN pin using a 9V battery, then we supply power to the HC05s through the Nano's regulated +5V and the second GND pin on the Nano.
  • However, the same trick will not work for a Pro Mini, because the Pro Mini (at least the ones we've used) are very borderline on being able to supply +5V at 100 mA from their power pins. They may work sometimes but not others, and this is not a reliable setup. In that case we recommend using an inexpensive 5V BEC to provide regulated power to the Bluetooth modules.
  • Although these are using 3.3V Bluetooth chips, the power in pin is +5V and the data pins are 5V tolerant. We have run these for hundreds of hours using a 5V Arduino Nano.