Skip to main content, firmware, options)

Initializes the imp’s Bluetooth sub-system and readies it for use


Only available on the imp004m (impOS 38+) and imp006 (impOS 42+)


Name Type Description
uart An imp UART object The imp UART bus connected to the module’s Bluetooth sub-system
firmware String or blob The Broadcom-proprietary firmware for the Bluetooth sub-system
options Table Optional override Bluetooth MAC address


A new bluetooth instance


This method initializes a compatible imp’s Bluetooth sub-system and opens it for use. It returns an instance of the bluetooth class for you to use, so make sure you don’t allow the instance to go out of scope if you don’t want it to be automatically closed.

The uart parameter takes the imp UART bus which you have connected to the Bluetooth component of the imp004m’s integrated Cypress CYW43438 communications chip, or the imp006’s CYW43455. It will be taken over and configured by impOS and should not be used for other tasks while you have the bluetooth instance open — ie. until you call the bluetooth.close() method on the instance returned by this call.

Note It is possible to set the size of the selected UART’s receive buffer by calling uart.setrxfifosize() before you call A minimum receive buffer size of 1KB is imposed, so any buffer size smaller than this will be increased to 1KB by, but sizes greater than 1KB will be respected. If you do not call uart.setrxfifosize(), will set the receive buffer size to 1KB.

You must pass Cypress-proprietary radio firmware into the second parameter. This is then loaded into the CYW43438/43455, which is restarted. The firmware is approximately 16KB in size, and you can choose to include it as a string in your application code, or as binary data stored on and read in from SPI flash. Indeed, you should note that a future implementation of this API will replace this parameter with a reference to a function in your application that will stream the firmware in from flash.

The required Bluetooth LE firmware is available as a Squirrel library which you can inlcude in your code with this statement:

#require "bt_firmware.lib.nut:1.0.0"

Use the appropriate constant when you call

  • imp004m:
    bt <-, BT_FIRMWARE.CYW_43438);
  • imp006:
    bt <-, BT_FIRMWARE.CYW_43455);

Note You will need to include the firmware in any subsequent call you make, for example after an earlier call to bluetooth.close().

The final parameter, options, allows you to override certain connection settings if you wish. To make changes, pass a table into options containing any of the following keys:

options Key Data Type Description
mac String An alternative MAC address. It must be provided as a 12-character lower-case hexadecimal string
baudrate Integer The preferred baud rate to use for HCI traffic once bluetooth has booted

Example Code

#require "bt_firmware.lib.nut:1.0.0"

// Set up BT on imp004m Breakout Board
bt <- null;
bt_uart <- hardware.uartFGJH;
bt_lpo_in <- hardware.pinE;
bt_reg_on <- hardware.pinJ;

// Boot up BT
bt_lpo_in.configure(DIGITAL_OUT, 0);
bt_reg_on.configure(DIGITAL_OUT, 1);

// Pregnant pause while BT boots...

local start = hardware.millis();

try {
    // Instantiate BT
    bt =, 
    server.log("BLE initialized after " + (hardware.millis() - start) + " ms");
} catch (err) {
    server.log("BLE failed after " + (hardware.millis() - start) + " ms");