Tuesday, February 13, 2018

Fix for HC-06 connection problem with Windows 10

Many people, including myself, have used HC-06 with many earlier versions of Microsoft Windows, such as Windows Vista, 7 and 8 without any problem. The HC-06 module did it's job happily and the Bluetooth Serial link was very reliable. I have used it in many applications where I had to hook up a device with Serial Communication to my PC, just to get rid of the trouble of using long wires. I once made it to work as a wireless communication gateway to monitor a marine engine that came with a serial communication interface, which worked extraordinarily well between the engine room and the cabin.
However it all came to an end with the release of Windows 10, as all good things come to an end at one point. As Windows 10 prefers BLE communication, it became almost impossible for HC06 to get connected with a Bluetooth Serial port. It gets paired alright, but fails to be listed as a Bluetooth Serial connection.




However, after an years effort I realized that the following simple fix could solve this issue without any struggle.

The Issue 

The issue could be summarized as below.
  • HC-06 gets paired with windows 10.
  • Cannot add a Bluetooth Serial Port for the device
    • HC-06 is not listed in the device list
  • Bluetooth Serial port does not show up in the terminal software

The fix

This is not an uncommon issue. The same issue has occurred with many other Bluetooth devices including the HC-06 transceiver module and the good people at Microsoft must have heard of it through different error reports. As a result, it is most likely that the manufacturer of your PC's Bluetooth radio has released a driver update that will fix this issue. They have done so, in my case.

  1. Update the Bluetooth Driver
    • Try to find the update from the manufacturer's website directly.
    • If  the above step is not successful, the driver could be updated using windows update service.
  2. Restart the PC
    • Restarting all the services helps.
  3. Pair the device again, and add a Bluetooth serial port.

Check the drop-down menu for our module

Only the Outgoing port is useful for HC-06

Once the port is added, it will be visible in any Terminal software.

Bluetooth Serial port is available



Hello from Arduino (Over HC-06)


So after just a simple driver update, HC-06 Bluetooth Serial communication on Windows 10 works well, at least for me.

My OS Version is Microsoft Windows 10 Pro. Find version info from the below image.

My Windows version info

I cannot guarantee that this will work for everyone, but it did for me. So it's worth a try, as it would only cost you a few minutes and a few megabytes of data.

I am Dilupa Herath. 
You can reach me on Whatsapp (+94 77 45 45 624) 
or by email (dilupaherath1990@gmail.com)




Saturday, February 10, 2018

Connecting Arduino to Android with HC-06 Bluetooth module

HC-06 Bluetooth module

Many of my colleagues and friends often ask me help on connecting their Arduino boards with Android apps, so that they could control external devices using their smartphones. For this task, I always recommend the HC-06 Bluetooth slave module. It is cheap, reliable and does the job with a minimum setup.  

How does it work?

HC-06 works as a UART to Bluetooth radio, which broadcasts whatever the data read from the UART interface, and vice versa. Therefore, no special commands are required to communicate over Bluetooth using HC-06. It will simply transmit the data sent to it by using Arduino's Serial.print() function.

Hooking up HC-06 with an Arduino UNO


Getting Started: The Android app

To get started, I recommend using the Bluetooth Control for Arduino from Play Store. This app provides a good interface to control digital outputs.


Each of the four large buttons on the front screen of this app could be used to turn on and off four digital output pins separately.  When each button is pressed for the first time, they will send out the characters '1', '2', '3' and '4' respectively. When the are pressed again, the characters 'A', 'B','C' and 'D' will be sent out respectively.
The first set of characters could be used to turn on the outputs, and the second set of characters could be used to turn them off. 

Getting Started: The Arduino code


 #include <SoftwareSerial.h>  
 SoftwareSerial mySerial(10,11); //Software Serial, RX=pin 10, TX=pin 11  
   
 const int output1=3;  
 const int output2=4;  
 const int output3=5;  
 const int output4=6;  
 String input;  
   
 void setup() {  
  Serial.begin(9600);  
  mySerial.begin(9600);  
  pinMode(output1,OUTPUT);  
  pinMode(output2,OUTPUT);  
  pinMode(output3,OUTPUT);  
  pinMode(output4,OUTPUT);  
 }  
   
 void loop() {  
  while(mySerial.available()) {   //read the serial input  
   input += (char)mySerial.read();  
   delay(5);  
  }  
  if (input.length()>0) {   //if the input is not empty  
   setOutputs(input);    //call the setOutputs function  
  }  
  input="";  
 }  
   
 /*set Outputs according to the inputs*/  
 void setOutputs(String input){  
  if(input.indexOf("A")>-1)  
   digitalWrite(output1,LOW);  
  else if(input.indexOf("B")>-1)  
   digitalWrite(output2,LOW);  
  else if(input.indexOf("C")>-1)  
   digitalWrite(output3,LOW);  
  else if(input.indexOf("D")>-1)  
   digitalWrite(output4,LOW);  
   
  else if(input.indexOf("1")>-1)  
   digitalWrite(output1,HIGH);  
  else if(input.indexOf("2")>-1)  
   digitalWrite(output2,HIGH);  
  else if(input.indexOf("3")>-1)  
   digitalWrite(output3,HIGH);  
  else if(input.indexOf("4")>-1)  
   digitalWrite(output4,HIGH);  
  }  

This code will turn on and off four LEDs attached to digital pins 3, 4, 5 and 6. They could be replaced with relays to control devices that requires AC mains to operate. Eventhough there are other complex methods to get this task done, this simple method is useful as it keeps things simple and does its job well.

Monday, February 5, 2018

Reading Arduino Inputs to a Binary Number



In one of my recent projects, I had to read a few digital inputs of an Arduino board into an integer variable as a binary number. My initial thought was to use direct register addressing, but later on, I came up with two other methods which work really well. Here on my blog, I share all three of them, hoping that these would help someone else as well.

Note: Pull down resistors MUST be used for each example.


1. Only using digitalRead()
 void setup() {  
  Serial.begin(9600);  
  pinMode(2,INPUT);  
  pinMode(3,INPUT);  
  pinMode(4,INPUT);  
  pinMode(5,INPUT);  
 }  
 void loop() {  
   int b0 = digitalRead(2);  
   int b1 = digitalRead(3);  
   int b2 = digitalRead(4);  
   int b3 = digitalRead(5);  
   int output=b0+(2*b1)+(4*b2)+(8*b3); //create the binary number  
   Serial.println(output);  
   delay(100);  
 }  


2. Using BitShiftLeft (<<)

 void setup() {  
  Serial.begin(9600);  
  pinMode(2,INPUT);  
  pinMode(3,INPUT);  
  pinMode(4,INPUT);  
  pinMode(5,INPUT);  
 }  
 void loop() {  
   int b0 = digitalRead(2);  
   int b1 = digitalRead(3);  
   int b2 = digitalRead(4);  
   int b3 = digitalRead(5);  
   b1=b1<<1; //Shift the second bit by one binary place  
   b2=b2<<2; //Shift the third bit by two binary places  
   b3=b3<<3; //Shift the fourth bit by three binary places  
   int output=b0+b1+b2+b3; //add them together  
   Serial.println(output);  
   delay(100);  
 }  


3. Reading the registers directly - Simplest method so far

In AVR microcontrollers, there is a register called Chip Register, which stores the input value of a particular group of pins (a port). In This example, Chip register is read and assigned directly to an int variable.

 void setup() {  
 Serial.begin(9600);  
 }  
 void loop() {  
 DDRC=0x00; //Set all the pins of PortC to be inputs (A0 to A5 on Arduino Uno)  
 int a=PINC; //Read the input pins directly into a binary number   
 Serial.println(a);  
 delay(500);  
 }  


This last code is amazingly simple, and lightweight.  It could be way more useful when combined with Arduino Core functions.