Tag Archives: UART

MSP430 Voice Control Over Bluetooth HC06 module and Launchpad

MSP430 Voice Control Over Bluetooth

 

In this tutorial I will demonstrate a MSP430 voice control over Bluetooth, using a HC06 Bluetooth module.  I will be using an Android App I programmed which can be downloaded and installed, the C code for the MSP430 is also downloadable at the end of the tutorial.

**Update 18/01/2015 the Android App has been updated and now includes 23 generic commands

So before we look at everything in further detail, the video below gives a demonstration of what the simple App and basic hardware set/up can do.  Note it was filmed with an older phone, so excuse the quality and dodgy camera angles.

HC06 Bluetooth Module

This is my first foray into bluetooth, I will be looking at Bluetooth 4 (aka BLE) soon, but for now lets take a look at the HC06 bluetooth module.

MSP430 Voice Control Over Bluetooth HC06 module

The image above shows the HC06, the module is shown already soldered to a blue PCB and a connecting wire.  I purchased the whole assembly for under £3.50 including postage and packaging from Ebay.  You can also buy the module on it’s own for even cheaper, but you then need to mount it on a suitable PCB, as well as taking into account a few configuration considerations.  If you want to keep things simple then I recommend buying the same assembly as used in this tutorial.    An alternatively option if you looking for a neater Boosterpack design, is to source some parts from the 43oh website store, they sell the modules and Boosterpack PCB.  So lets look at a few specifications for the module, I have just listed the ones that are pertinent, bear in mind any module you buy may differ slightly.

  • Bluetooth protocal: Bluetooth Specification v2.0+EDR
  • Frequency: 2.4GHz ISM band
  • Emission power: ≤4dBm, Class 2 (~10 meter range)
  • Speed: Asynchronous: 2.1Mbps(Max) / 160 kbps, Synchronous: 1Mbps/1Mbps
  • Power supply: +3.3VDC 50mA (3.6V ~ 6V on-board regulator input)

The HC06 kits has six external connections, only four have header pins connected these are VCC, GND, TXD and RXD (Wakeup and State are not connected).  The TXD and RXD form the transmit and receive for a serial connection, these will be connected to the Universal Asynchronous Receiver/Transmitter (UART) on the MSP430G2553.

Hardware Set-Up

For this tutorial I kept it very simple, the demonstration uses the Launchpads on-board LED’s. The VCC and GND pins from the bluetooth module are connected to the launchpads VCC and GND pins.  TXD from the module is connected to P1.1 on the launchpad, this is the UART receive, and RXD from the module is connected to P1.2 on the launchpad, this is the UART transmit.  The image below should clarify the connections, as it shows the colour coded wire clearly.

MSP430 Voice Control Over Bluetooth HC06 module connected to Launchpad

Thats all there is to it for the hardware set-up, there was no need to add any further electronics as the potential control applications will become evident.

Software

I was originally just playing around with the UART, and had intended to write a tutorial on this but remembered I had brought the HC06 module, so decided to dig it out.  Before I connected the module I had already tested the UART using a free terminal program called Putty running on Windows.  The MSP430 UART example programs are enough to learn the basics and get you started, the code I used is based on one of the examples.  After having great success with the initial UART tests, I then connected the bluetooth module.  To test the module I needed a similar program to Putty but running on Android, you will find dozens of terminal programs for Android just by searching the Play Store.

After some initial tests this worked fine and I had an LED switching on and off via bluetooth, all for about one hour of playing around.  It was at this point I thought wouldn’t it be cool to have voice control, my Nexus 5 supports ‘Ok Google’ for voice activation and that gave me the idea. Now I have to stress my App doe’s not support ‘Ok Google’  this is the first iteration, in fact you have to hit a button first and then speak the command.  I will write more about the Android App, but first lets go through the MSP430G2553 code.

MSP430G2553 Code

I am only going to run through the code quickly, as it can be downloaded below so will just walk through the main parts.

The first block of code deals with the watchdog and clock set/up, this also ensures the clock is calibrated, the accuracy is required for the UART operation although there is still a small margin of error due to the internal oscillator tolerance.

The GPIO’s are set-up next in lines 2 and 3, P1.1 and P1.2 are used for the UART.  In order to configure these both the GPIO function select registers need to be set to 1, this configures the pins to function with the secondary peripheral module.  If you are not familir with some of the GPIO or registry configuration commands, I would recommend you take a look at my two part MSP430 Programming Tutorial Part/1 and Part/2.  Lines 4 and 5 are used to configure P1.0 and P1.6, these are connected to the on-board LED’s, and are purely used here as a simple demonstration.

The next block of code is used to configure the Universal Serial Communication Interface (USCI), this supports multiple serial communication modes.  The MSP430G2553 has two USCI modules, USCI_A and USCI_B, USCI_A is used here in UART mode.

Starting with line 2 this configures USCI_A0 control register 1 and sets the clock source as the SMCLK.  Line 3 configures the USCI_A0 baud rate control register 0, using a value of 104.  The SMCLK is running at 1MHz, therefore 1MHz divided by 104 = 9615.4, which is almost 9600 baud. Line 4 configures the USCI_A0 baud rate control register 1, this is used for clock prescaler settings more information can be found in the family guide with relation to this.  Line 5 configures the USCI_A0 modulation control register, this parameter determines the modulation pattern, in short terms this allows extra adjustment depending on the divided clock frequency and desired baud rate.  Therefore providing a mechanism to achieve the most accurate result, with as little deviation from the desired baud rate.  Line 6 configures the USCI_A0 control register 1, this time it performs a software reset which initialises the USCI state machine.  Line 7 enables the interrupt on the USCI_A0 receive buffer.  Line 8 enables low power mode 0 which turns the CPU off and interrupts.

So now that the USCI_A is configured the processor will switch off until data is received, then when the receive buffer has a new byte of information an interrupt will be called.

The code snippet above is inside the interrupt handler for the USCI_A receive buffer.  Line 1 assigns the data inside the buffer to the variable Rx_Data, line 2 is used to wake up the CPU.

The variable Rx_Data is then used in a switch case statement to determine what has been sent over bluetooth.  The App on the phone can be programmed to send a string, but this first iterations simply converts a string into a single ASCII value, which is then sent over bluetooth. In the case of the code running on the MSP430, it is using the switch case to determine the ASCII value represented by a hexadecimal number.  The ASCII value sent and shown in line 3 is 0x41 which is a capital A, and line 4 is 0x42 which is a capital B.  So when you say the word ‘On’ the phone App translates this and sends a capital A to the HC06 bluetooth module, when you say the word ‘Off’ a capital B is sent.  There are other commands and I can and will add more, the full list currently supported is further down the tutorial.

The rest of the code shown is purely for demonstration, basically line 4 and 11 are used to disable a timer interrupt.  The timer interrupt requires disabling as the flash demo is not used if the on or off commands have been given.  Line 5 and 12 are used to change the function of pin P1.6 to a GPIO function.  Line 6 is used to turn the on-board launchpad LED’s on, and line 13 is used to turn the on-board launchpad LED’s off.

Android Voice App

I am not an Android App developer so this was put together quite quickly, literally six or so hours.  I have been testing it with the launchpad and it performs well, there were a few early teething problems but now it seems pretty solid in operation.  The App can currently only be downloaded here, I was going to upload to the Play Store but Google wanted 25$ for the privilege.  So I decided not to upload at this stage, as it may not be of any use to anyone other than me…time will tell!

 

I am not running through how to code the App here, just showing some screen shots of the operation with some notes, as the video should really cover this.  I have only tested this on my Google Nexus 5, so unsure if the layout will change on other phones.  If I have left any areas unclear or you have issues, leave a comment at the end of the article and I will answer as soon as I can.

Before running the App you need to enable your Bluetooth, wasn’t sure how to do this and it does not prompt you to enable it yet.

MSP430 Voice Control Over Bluetooth HC06 module Android App Not ConnectedOk the first screen capture shows the Apps main and only window, you will notice the big red text that says ‘Not Connected’ .  To connect a bluetooth device tap the blue box with the text ‘Choose BT Device’

MSP430 Voice Control Over Bluetooth HC06 module Android App Bluetooth SelectionYou will then be taken to a screen with a list of bluetooth devices, as you can see I have the HC06 device listed.  To select the device just tap on the listed device.  The HC06 module has a small LED on the board, this flashes when not connected, becoming solid once the device is connected.  If its your first time connecting you will need to pair the devices, the most common password used for the HC06 seems to be ‘1234’.

MSP430 Voice Control Over Bluetooth HC06 module Android App ConnectedAfter a few seconds the screen will return to the main window, and you should notice the red text has now changed green and reads ‘Connected’.  You will notice directly below this text is more black text which says ‘Captured Speech = ?’, this indicates no speech has been captured. By pressing the orange button which says ‘Press Then Give Voice Command’, you will enter the speech capture mode.

MSP430 Voice Control Over Bluetooth HC06 module Android App Capture ModeThe capture mode is just Google’s Speech to Text, this as the name suggests will convert your speech to text.

MSP430 Voice Control Over Bluetooth HC06 module Android App Unaccepted Code WordThe next screen shot demonstrates the captured speech being displayed, this is not a recognised command word shown, it could be in future though.  I have left all words displayed as if Google’s application has misidentified your speech, it’s better to know where the error lies. I guess I could have the recognised word change green for a valid command and red for an invalid one, so will maybe implement that at a future date.  You can disconnect the bluetooth device any time by pressing the red button labelled ‘Disconnect BT’.

A few of the commands supported are as follows:

  • on‘ command then generates a capital A and sends over bluetooth or hex 0x41
  • off‘ command then generates a capital B and sends over bluetooth or hex 0x42
  • flash‘ command then generates a capital C and sends over bluetooth or hex 0x43
  • 1‘ command then generates the number 1 and sends over bluetooth or hex 0x31
  • 2‘ command then generates the number 2 and sends over bluetooth or hex 0x32
  • 3‘ command then generates the number and sends over bluetooth or hex 0x33
  • 4‘ command then generates the number 4 and sends over bluetooth or hex 0x34
  • 5‘ command then generates the number 5 and sends over bluetooth or hex 0x35

I will probably add forward, backward, left, right and a few other obvious command words.

MSP430G2553 C Code

The link below contains the zip file with the full example C code, there is a small advert page first via Adfly, which can be skipped and just takes a few seconds, but helps me to pay towards the hosting of the website.

MSP430 Voice Control Over Bluetooth MSP430G2553 C Code

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.

Android App BT_Voice_MCU.apk

**Update 18/01/2015 the Android App has been updated and now includes some additional commands, for a full list see this Excel file, the link below has also been updated.

The link below contains the zip file with the full Android App.apk file, there is a small advert page first via Adfly, which can be skipped and just takes a few seconds, but helps me to pay towards the hosting of the website.  I guess I need to put some sort of disclaimer here as this is a phone App, and untested on any other phone except my Nexus 5, but it appears 100% stable and has not caused any issues.  If you download and use this App, I am not responsible for any issues you may encounter so you do so at your own risk.

MSP430_Bluetooth_Voice_Control

*Original* – MSP430 Voice Control Over Bluetooth BT_Voice_MCU Android App

I take great care when writing all the tutorials and articles, ensuring all the code is fully tested to avoid issues for my readers.  All this takes time and a great deal of work, so please support the site by using the Adfly links etc.  If you have found this useful or have any problems implementing, please feel free to leave a comment and I will do my best to help.