The assignments for wk15 were as below;
This week, I decided to examine the connection of Bluetooth Law Energy(BLE) for my final projects. First, I mainly referred the this documentation
The breakout board for HM-10
Setting up the breakout board
First, I tried to have the breakout board communicate with my laptop using the serial monitor of Arduino. I used FTDI cable to connect.
I make sure you select the correct usb serial port and opened Serial Monitor. This time, make sure the baud rate is 9600, this is the default baud rate.
Type in;
AT+NAME? (NO SPACES IN AT COMMAND)
you should get OK+NAME:HMSoft
Next, I tested the bluetooth communication using the bluetooth detecting software, Lightblue, and succcessfuly detect the breakout board titled "HMSoft".
Lightblue
"HMsoft" detected on Lightblue
Cennectiong the bluetooth board with iPhone
I also downloaded Lightblue on iPhone and do the practice connectiong the board with iPhone.
LightBlue on iPhone
LightBlue on iPhone quickly detected the bluetooth module, named 'HMSoft'.
List of Bluetooth connection
Then, I connected the board with iPhone, which was very straight forward. Now paring had finished and I prepared to communicate between the two.
Detailed information of the connection
Next, I tried to send the message from my laptop using the serial monitor of Arduino as below.
Send 'hello from Arduino serial monitor on laptop
Then, I got quickly got the message from laptom on iPhone as below. At first, I was confused because I was not able to understand the message. Soon, I noticed that '68656C6C6F'
means 'hello' in hexadecimal notation(HEX)
'Hello'(HEX) message shown on lightBlue on iPhone
Second, I tried to send the text from iPhone(lightBlue) to laptop via bluetooth commucation. I typed same string '68656C6C6F'
on lightBlue as below
Typse '68656C6C6F'
on lightBlue screen
Then, I got the text 'hello' on Arduino Serial Monitor on my laptop, which meaned iPhone successfully sent the signal to raptop via serial communication by bluetooh!!!!
'hello' on Arduino Serial Monitor on my raptop
Since I decided to connect Fabkit with smartphone like iOS via Bluetooth connection, I tried to check the commucanication between the two. As a default, Fabkit is connected to laptop via FTDI cable which include tx/rx pin, so it was necessary for me to change the connection from default.
Pin configuration of Fabkit
Reffering the pin configuration of FTDI cable and Fabkit, I made the connection as below, in which I supply the power to Fabkit from laptop through FTDI cable, and connect Fabkit and BLE module with 4 pin(VCC/GND/RX/TX) communication.
Connection between Fabkit and BLE
1) Send counted up number from Fabkit to iOS
First, I wrote simple test code which could send counted up number from Fabkit to BLE through serial communication on rx/tx pin as below.
//#includeint count = 0; //counter to send void setup() { Serial.begin(9600); } void loop() { Serial.println(count); count++; delay(1000); }
After several trial and error I was able to get the result as below, and succeeded to receive the number from Fabkit thtough bluetooth serial communicaton.
Counted up numberes shown on Lightblue(iOS)
2) Read sensor value and send it, and remote control
Next, I zapped up several web site, and decided to make the network using Fabkit and BLE with function that:
Fabkit and BLE module with potentiometer
This must be useful practice for my final project, then I tried to write the programme. And the code is as below.#define sensor_pin 14 const int LED=13; int rsvData = 0; int sensorVal = 0; void setup() { pinMode(LED, OUTPUT); Serial.begin(9600); } void loop() { // receive if(Serial.available() > 0){ rsvData = Serial.read(); if(rsvData == 1){ digitalWrite(LED, HIGH); }else if(rsvData == 0){ digitalWrite(LED, LOW); } } //read sensor val sensorVal = analogRead(sensor_pin); sensorVal = sensorVal>>2; Serial.write(sensorVal); //wait delay(100); }
As a result, the former function has worked when I send the value from lightBlue on iOS through serial commucanication via Bluetooth module, however, I cannot receive the parameter from the potentiometer. I was not able to fix the bug because of lack of my time. I am wondering that the cause existed in the setting of network: around data type(Byte, Intiger, HEX, or such) ,Baud rate, and such.
1. BLE Tutorial
2. Connection between Fabkit and iPhone
Here are my output files for wk15:
Lecture Note
Tools
Here you can find this weeks's lectures on VIMEO:
(2016.05.11)
(2016.05.18)