smartBASIC for BLE
NEW to smartBASIC? See Laird's comprehensive walkthrough on smartBASIC to learn step-by-step how to start working with the language. And for a more specific example of how easy it is to code an Eddystone beacon in smartBASIC, see our Beacons for smartBASIC walkthrough!
Why Should I Use smartBASIC to Write Applications?
smartBASIC was designed to make BLE (Bluetooth Low Energy), or Bluetooth® Smart technology, development quicker and simpler, vastly cutting down time to market. The following are three good reasons for writing applications in smartBASIC:
- Since the Laird BL600 module and BT900 module can autorun the application every time it powers up, you can implement a complete design within the module.
- Many use cases would combine the BL600 of BT900 with a sensor device. smartBASIC allows sensor data to be manipulated using arithmetic and string processing functions allowing intelligent use of the Bluetooth Smart radio.
- If you already have a product with a wired communications link, such as a modem, you can write a smartBASIC application for one of our wireless modules that copies the interface for your wired module. This provides a fast way for you to upgrade your product range with the minimum number of changes to its existing firmware.
Sample smartBASIC Applications
Sample smartBASIC applications are available for download in the BL600 or BT900 Firmware Files in the Laird Bluetooth Download Center. More information is available in the BL600 smartBASIC Extensions Manual and the BT900 smartBASIC Extensions Manual. Current smartBASIC applications include:
|Blood Pressure||Buzzer Jungle||Heart Rate||Low Power / Deep Sleep||Temperature Sensor||iBeacon|
|LED Button Test||Read Supply Voltage||Health Thermometer||Proximity||UART Close||PWM|
|Buzzer Test||FindMe||Hello World||Trimpot Test||vSP - Virtual Serial Port (upass)|
- Register a Heart Rate Service
- Make the BLE device advertise every 25 mx for a period of one minute, inviting a BLE connection.
Modes of Operation
The BL600 or BT900 BLE module running smartBASIC has two different modes of operation:
- Interactive Mode – In Interactive mode, commands are sent via the UART and are executed immediately, analogous to the behavior of a modem using AT commands. Interactive mode can be used by a host processor or a PC to directly configure and control the module. It is also used to manage the download and storage of BASIC applications in the flash file system that is subsequently used in Run-time mode.
- Run-time Mode – In Run-time mode, the module reads pre-compiled BASIC applications directly from program memory and executed in-situ. The ability to interpret the application from flash ensures that the maximum amount of RAM memory is available to the user application for data variables.
By default, the module starts up in Interactive mode and checks to see if an application called $autorun$ exists in the file system. If present, it automatically runs unless the nAutoRUN input pin is used to signal that the module should skip that step. If the autorun application exits, which in virtually all cases is not the case, then the module returns to Interactive mode. It is possible to write autorun applications that continue to run to control the module’s behavior until power-down, which provides a complete embedded application.
Being a structured programming language, smartBASIC offers typical modern constructs such as subroutines, functions, while, if, and for loops. Applications written in smartBASIC are event-driven rather than the sequential processing seen in early versions of BASIC.
A typical smartBASIC application source code consists of the following:
- Variable declarations and initialization
- Subroutine definitions
- Event handler routines
- Startup code
The source code ends with WAITEVENT, a final statement which never returns. Once the run-time engine reaches the WAITEVENT statement, it waits for events to happen and, when they do, it calls the appropriate handlers (written by the user) to service them.
The core language, which is common throughout all smartBASIC implementations, provides the standard functionality of any program, such as:
- Arithmetic functions
- Binary operators
- Functions and subroutines
- String processing functions
- Arrays (single dimension only)
- I/O functions (GPIO, ADCs, I2C, SPI, and UART)
- Memory management
- Event handling
- Security - encryption and authentication
- Power management
- Wireless status
smartBASIC applications can be written in any standard text editor such as textpad or Notepad++ and do not require a complex or costly development environment. If you prefer syntax color highlighting, then treating the source as C or BASIC will display the code with color highlights. Applications are transferred to the module using a simple free terminal program called UWTerminal (available for download from www.lairdtech.com/wireless). Customers are able to develop their own utilities to download precompiled applications as the process involves the use of standard AT commands.