About this demo
This demo is based on the Wireless UART example from the SDK available on Welcome | MCUXpresso SDK Builder selecting the QN908X board.
The main idea of this demo is to be able to send commands from one device to another, it could be from a QN9080DK, a phone using our NXP application: IoT Toolbox or even an FRDM-KW41Z, this is possible because of the BLE protocol used in all our devices.
The end-device used is a QN9080DK, this board receives the message, does parsing and triggers a PWM function using the values sent from another device. This signal can be used in different applications, typically controlling smart lighting brightness and color, speed of motor controls and audio or video amplifiers. The goal of this demo is to implement a task for our FreeRTOS scheduler in order to be able to control a PWM while the BLE connection is still running and receive new incoming messages.
- We only interpret ON, OFF and a string of values for our 3 signal outputs.
- The string of values has to be in the following syntax: rXXX,gXXX,bXXX. An example of this could be r255,g130,b200.
- The max value should be 255 in order to achieve 100% of the duty cycle, for this example, we are using is at 100 Hz.
- The connection is not using pairing or bonding modes, so no device information is saved on the non-volatile memory due to this if the connection is lost we need to follow the initial connection procedure.
- The amount of bytes that can be sent is limited by the macro: #define gAttMaxMtu_c in the ble_constants.h file from the project, we recommend to leave it as it is.
Useful documentation is available in the SDK previously downloaded: <SDK Installation folder>...\SDK_2.2.1_QN908XCDK\docs
|https://www.nxp.com/webapp/Download?colCode=QN908x-DK||QN908xDK User’s Guide|
|Welcome | MCUXpresso SDK Builder||SDK Builder site|
|Wireless Connectivity||NXP Wireless Community|
|Connectivity Software: Implement tickless mode in FreeRTOS||Document for implementing a new task using OSA Abstraction layer of FreeRTOS|
|https://www.nxp.com/docs/en/nxp/data-sheets/QN908x.pdf||QN908x Datasheet for pins functions|
|QN908x: Ultra-Low-Power Bluetooth Low Energy System on Chip (SoC) Solution | NXP||It is required at least one as an end-point.|
|Oscilloscope||An Oscilloscope to visualize the PWM.|
- Download de QN908x SDK
- Download the attached .zip file.
- Import it into MCUXpresso, for the end node you should only use the qn908xcdk_wireless_uart_peripheral project.
- If you want to use a second QN board to send the commands it is required to also import the qn908xcdk_wireless_uart_central project.
- Once the projects are imported, we need to flash each board with a project and connect the PA9, PA10, and PA18 pins to our oscilloscope in order to visualize the signal.
- Connect the USB cables to the computer and open Teraterm with the following values: 115200, 8 bits, none,1 bit, none.
- Press the RESET Button (SW3) of the Peripheral board
- Press the Button1 (SW1) after the message: "Wireless UART starting as GAP Peripheral, press the role switch to change it.", an "Advertising" should appear.
- If a second QN board is used (central), we need to open a second Teraterm session and set it to the same Serial configurations from point 5.
- If an Android phone is used we need to have the IoT Toolbox application installed and select the Wireless UART example and connect to the Peripheral board using the interface.
- To pair the Central board to the Peripheral it is required to press the RESET Button (SW3) of the Central board while the Peripheral board is advertising and then Push the Button1 (SW1).
- Once the boards are connected, we need to paste the message to our terminal in order to be sent as one message.
- The message should be seen in the other board terminal.
- Send "ON" to activate the PWM functionality.
- Send "r255,g128,b64" to set the PWM pins to 100%, 50%, 25%.
- This signal must be displayed at 100Hz on the oscilloscope.
- Send "OFF" to deactivate the PWM functionality.
- The Demo is based on the Wireless UART example, The BleApp_ReceivedUartStream function is modified to compare de received strings.
- The getValuesRGB converts the string into integer values to be assigned to the global variables red, green, blue.
- Inside getValuesRGB we use the OSA abstraction layer for FreeRTOS to create the task using: OSA_TaskCreate and creating the task named: vfnTaskPWM.
- vfnTaskPWM configures the timer and initializes the PWM values using the CTimer driver functions and starts the CTimers.
1. After the QN9080 is flashed and in Advertising mode, we have to connect our Central device, Which in this case is an Android phone. In or Teraterm we should be able to see this message:
2. Then, we get the Connected status from our devices and we should be able to send the ON command and the RGB values, Teraterm indicates the integer values and the string received.
3. When we send the OFF command the PWM signals should be 0 V.
4. Here is another example: