Bluetooth Application Guide

From Flowcode Help
Jump to navigationJump to search

Introduction

These examples demonstrate the use of the Flowcode Bluetooth component.

In particular they make use of the EB024 E-blocks Bluetooth board, connected to an EB006 E-blocks PICmicro multiprogrammer fitted with a 16F1937 microprocessor.

However, the examples are easily changed in Flowcode to support other microprocessors and platforms.

The Matrix TSL EB934SI6 Easy Bluetooth bundle has all the items required for these sample applications and is an ideal introduction to Bluetooth technology.


Setting up the project hardware

Connect the E-Blocks as indicated in the table below.

The Bluetooth, LCD and Switch E-Blocks all need to be powered via wire connections to the +V on the EB006.

Hardware Setup
EB006 PICmicro multiprogrammer
Port A EB004 E-blocks LED board
Port B EB005 E-blocks LCD board
Port C EB024 E-blocks Bluetooth board
Port D EB007 E-blocks push-to-make switch board

Example 1: Discoverable serial device setup

FC6 Icon.png Discoverable Serial Device Setup Example

Example 1 is a simple program that sets up the Bluetooth module by using a script to setup the module as a generic serial communications bus. Once the device has been setup the LCD will display the message OK. When a pair request is received from another Bluetooth device the MAC address of this device is shown on the LCD.

Once the Bluetooth device has been setup to be discoverable and a pairing key has been assigned, this information is stored into the firmware of the Bluetooth module using the AT&w command. For example 1 we show you how to set up these details so that your Bluetooth board is available for use as a serial device. Once this has been done the Bluetooth module will recover these settings every time it is powered on or until it is reprogrammed.

In examples 2 and 3 use the RS232 component to communicate over the Bluetooth serial connection. The RS232 component and the Bluetooth component both use the hardware UART so only one of the components can be connected to a single program.


Example 2: Simple serial display device

FC6 Icon.png Simple Serial Display Device Example

The example 2 program simply demonstrates an echo function. Any data that is received via the Bluetooth connection to our serial display device is passed to the LCD to be printed out as an ASCII character before being also retransmitted back to the sending device.

So we need to setup a PC to communicate with our Simple serial display device...

Insert a Bluetooth USB dongle into your computer USB socket and install it.

Ensure your E-blocks setup is programmed with the Simple Serial Display Device Example and is powered up and running.

(Win 7 Users) Click the start menu and in the search field at the bottom type in Bluetooth and select Add device.

In the Add Bluetooth Device Wizard tick the box stating that the device is ready and then click the Next button.

After a few seconds our Bluetooth device should be detected and appear in the device list as a Ezurio device. Select the device and then click Next.

Select "Let me choose my own passkey" and set this to be 1234 as specified in script 1 of example 1.

Click Next and then the computer should automatically connect and pair with our device. At this point the LCD attached to the system should be displaying "OK".

Once the device has been paired you should have two COM ports set up. The Outgoing COM port is the port number to use when using serial PC communication software such as Hyperterm or Realterm etc.

When you open the COM port using your terminal software the LED on-board the Bluetooth module should light.

As you type characters into the terminal window you should see these appearing on screen as anything sent to our device is echoed back to the PC.

You should also be able to see the data appearing on the E-blocks LCD.


Example 3: Serial data acquisition and control example

FC6 Icon.png Serial Data Transfer Example

The example 3 program demonstrates how the Bluetooth serial channel can be used to transfer simple serial data to and from the device in order to provide data acquisition and control.

In this example we have introduced a switch in code that looks for incoming characters of ‘a’, ‘b’ or ‘c’, which when received causes the device to respectively turn on LED A0, turn off LED 0 and return an ADC value.