The LinkNode BLE Sensors tag is a Bluetooth 4.0 BLE sensor development board. It integrates devices, such as NRF51822, LIS3DH, BMP180, buzzer, and dual-color LED. It is a powerful and also programming friendly development board. Even for non-embedded background programmer like myself – a Web developer, can set up a prototype with completed functions within 20 hours.
To write code for LinkNode it provides the online IDE – mbed online compiler. Go to the website and then you can start coding. So you don’t need to waste your time on environment setting or other trifle thing. It saves lots of time. When code is completed and compiled successfully you will get a hex file from this online IDE. After that connect the LinkNode to your computer, you will see an additional drive. Put the hex file into it, then LinkNode is working. Just several simple steps you can begin your work on development. This is the most efficient way I’ve ever seen. There’re lots of good examples on the online IDE. I learnt a lot from it when creating my own program.
My innovation idea is that to use LinkNode to create a health care device for people in office. The health care device is mainly to solve problems in below scenarios:
- People sitting long time
For developer or editor they may sit over hours once they focus on their work which caused lots of health problem like neck hurts or waist pain.
- Temperature is too low in office
Summer is coming and the air conditioner in office may be set to very low temperature e.g. lower than 18 degree, if people sitting in that environment too long time it will impact people’s health.
So the health care device has the following functions:
- Rest reminder for long time sitting people
The health care device will monitor people’s sitting time. If they sit long time e.g. over 1 hour it will reminder them to leave the seat to have a rest. If people already leave for a while e.g. more than 15 minutes, there will be no reminding.
- High/low temperature reminder
The health care device will monitor the temperature in office. If temperature in is too low or too high, it will remind the people to adjust the air conditioner.
- Send above data to phone App via Buletooth for user to review
Rest reminder function implementation
Extra Sensor: DSN-FIR800 human pyroelectric infrared sensor
PIN Connection
DSN-FIR800 PIN | LinkNode PIN |
VCC | 5V |
GND | GND |
OUT | TX (P0_23) |
DSN-FIR800 OUT PIN is connecting with TX PIN on LinkNode. If DSN-FIR800 sensor detects people around, the OUT PIN of the module will return True or 1. On LinkNode side, we can set TX PIN as DigitalIn and read its value in a certain time span (e.g. every minute). If the value is True or 1, the health care device will know there’s people around and then it will record people’s working time. Otherwise it will record people’s resting time.
[embedyt] http://www.youtube.com/watch?v=2fXf7VshqpE[/embedyt]
Sample Code
#define DIGITAL_IN_IsPeopleInfront_PIN P0_23
DigitalIn IsPeopleInfront(DIGITAL_IN_IsNoPeopleInfront_PIN);
if(!IsPeopleInfront)
{
//business logic here. E.g. record the cumulated time into array and wait for later process
}
else
{
//business logic here. E.g. record the cumulated time into array and wait for later process
}
Temperature reminder function implementation
Sensor: BMP180 Bosch temperature and pressure sensor on LinkNode
PIN Connection: Do not need to set anything
BMP180 module will detect the temperature around. LinkNode communicates with BMP180 using I2C port. The SCL port is connected to P0_18 and SDA port is connected to P0_17.
On LinkNodewiki you can get detail example code of BMP180. Here just list the key parts.
[embedyt] http://www.youtube.com/watch?v=sCYRzDQ1pWo[/embedyt]
Sample Code
#include “BMP180.h”
I2C i2c(P0_17, P0_18);
BMP180 bmp180(&i2c);
int main(void)
{
while(1) {
if (bmp180.init() != 0) {
printf(“Error communicating with BMP180\n”);
} else {
printf(“Initialized BMP180\n”);
break;
}
wait(1);
}
bmp180.startTemperature();
wait_ms(5); // Wait for conversion to complete
float temp; //To store temperature
while(1)
{
if(bmp180.getTemperature(&temp) != 0) {
printf(“Error getting temperature\n”);
continue;
}
else
break;
}
//business logic here. E.g. record the temperature and wait for later process
}
Bluetooth function implementation
Sensor: nRF51822 Bluetooth Low Energy on LinkNode
PIN Connection: Do not need to set anything
Via Bluetooth, LinkNode can send data to phone App. All above time and temperature data can be sent by this way. On LinkNodewiki you can get detail example code of enable Bluetooth on LinkNode. Here just list the key parts.
[embedyt] http://www.youtube.com/watch?v=zT_y9u7azUw[/embedyt]
Sample Code
m_status_check_handle is the key method to send data to phone. It’s using an uint8_t array to store the data.
void m_status_check_handle(void)
{
uint8_t buf[6];
//Business logic here e.g. store data to the uint8_t array which will be sent to phone App side
ble.updateCharacteristicValue(rxCharacteristic.getValueAttribute().getHandle(), buf, 6);
}
Phone App implementation
I create the phone App by Evothings Studio introduced in LinkNodewiki. Evothings Studio is to create phone by the Web development technology like HTML, CSS and JavaScript. It’s a good tool to create phone App demo.
Follow below steps to start phone App creation
- Download and install Evothings ViewerApp on your phone via AppStore or Google Play
- Download and install Evothings Workbench on your computer from Evothings website.
- Launch the Workbench on your computer, click Connecttab and then click the Get Key button. The Key will appear.
- Launch Evothings ClientApp on your phone, input the key and click CONNECT
- Go back to the Workbench on computer, click Examples You will find “Redbear Labs – Simple Control” example project there, click “COPY” button.
- In the Workbench, click My Apps Click “CODE” button you can view and modify the phone App code. Click “RUN” button in Workbench, on phone side the Evothings ViewerApp will load the code run on your phone.
You can edit the code in any text editor and after save the latest change will synchronize to phone side automatically.
Sample Code
app.css & index.html are used to control phone App display layout. App.js is used to control function.
app.receivedData = function(data)
{
if (app.connected)
{
var data = new Uint8Array(data);
//business logic here, data contains all the information receiving from buletooth on LinkNode
}
};
More detail code :https://developer.mbed.org/users/geekfamily/code/HiO/
The authors is Xin Wang
Leave a Reply
You must be logged in to post a comment.