smartBASIC for BLE

smartBASIC Introduction

smartBASIC is an implementation of a structured BASIC programming language optimized for use on low-cost embedded systems with limited memory by being highly efficient in terms of memory usage. The BASIC programming language has been around for over 40 years in many variants and platforms, a good background and introduction is available at http://en.wikipedia.org/wiki/BASIC.


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. Click here to view the BL600 User's Manual or click here to view the BT900 User's 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)

 


smartBASIC Example

Requirement:

  • Register a Heart Rate Service
  • Make the BLE device advertise every 25 mx for a period of one minute, inviting a BLE connection.
smartBASIC_embedded_processor_img 

vs.

smartBASIC_code_img2

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.

 


 

Autorun

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.

 


 

smartBASIC Essentials

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
  • Conditionals
  • Looping
  • Functions and subroutines
  • String processing functions
  • Arrays (single dimension only)
  • I/O functions (GPIO, ADCs, I2C, SPI, and UART)
  • Memory management
  • Event handling

In addition smartBASIC adds Bluetooth Low Energy Extensions to control the wireless connectivity of the BL600 or BT900:

  • Advertising
  • Connecting
  • 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.

Contact us

PHOTO

Contact us for information on our company, solutions and products.

Contact Us

Embedded Wireless Support Center

PHOTO

The support center provides links to documentation, software, articles and more...

Go to support

Wireless Connectivity Blog

PHOTO

Read the latest blog posts on wireless connectivity

READ MORE

Hide Me