In the previous guide you downloaded the PIC-BLE or AVR-BLE firmware to connect to the LightBlue app from Punch Through and were able to:
- Turn the on-board LEDs on and off
- Observe the accelerometer data as you moved the board
- Observe the button state changing in the app when you pressed the on-board button
- Observe the board temperature in both Celsius and Fahrenheit
In this guide you will learn how to write "Hello World" to the Serial Data window in the LightBlue app.
"Hello World" with LightBlue:Start by opening the PIC (or AVR) LightBlue Explorer project in MPLAB X that you created in the previous guide.
Click on the Clean & Build (hammer & brush) icon to ensure that the code builds.
1. Add Application CodeNow click on the arrow next to Source Files and double-click on the main.c file as shown in Figure 1.
Scroll down the main.c file and find the main function. Inside the main function, find the while(1)
loop. You will see the function calls for all of the onboard sensors, such as:
LIGHTBLUE_TemperatureSensor();
LIGHTBLUE_AccelSensor();
LIGHTBLUE_PushButton();
LIGHTBLUE_LedState();
LIGHTBLUE_SendProtocolVersion();
Place your cursor below those function calls and type the following:
lightblue_
then press <CTRL> and <spacebar> together and it will give you a list of the available functions. The one you need to send serial data is:
LIGHTBLUE_SendSerialData(char* serialData)
as shown below in Figure 2.
Double click on that entry and the function will auto-complete for you. Now all you to do is to pass it a string.
Inside the parentheses type the following:
“Hello World!”
Then at the end of the completed line don’t forget to add a semicolon (;)
So now the completed line should look like:
LIGHTBLUE_SendSerialData("Hello World!");
Click the Clean & Build button to make sure there are no errors.
Then, after the project has finished building, make sure the PIC-BLE is connected to your computer’s USB port and click the Make & Program Device button to program the PIC-BLE (or AVR-BLE) development board.
Once it finishes open the LightBlue app on your smartphone and connect to the PIC-BLE (or AVR-BLE) as you did in the previous guide. Now you should see Hello World!
written to the Serial Data window as shown in Figure 3 below.
Comment below to tell us what you made with your PIC-BLE or AVR-BLE development board!
Comments
Please log in or sign up to comment.