Develop BLE applications with Puck.js

Our step-by-step guide to program the open smart button for wireless sensing and identification applications.

Develop BLE applications with Puck.js

The TL;DR (Too Long; Didn't Read)

Learn how to program Puck.js with existing or custom code.

What's Puck.js?
Puck.js is an open hardware device that combines a Bluetooth Low Energy (BLE) microcontroller with plenty of sensors in a nifty button format.
What will this accomplish?
The Puck.js will share its sensor data and/or identifiers wirelessly using BLE advertising packets.
Is there an easier way?
Programming Espruino devices like the Puck.js from the browser using Web Bluetooth is already incredibly easy.


A Puck.js and Web Bluetooth.

Many—but not all—modern browsers such as Chrome support Web Bluetooth by default. MDN maintains this list of browser compatibility.

Connecting to the Puck.js   Step 1 of 2

Browse to the Espruino IDE and connect using Web Bluetooth.

What's Espruino?
Espruino enables low-power microcontrollers to run JavaScript, the language of the Web.
What's Web Bluetooth?
Web Bluetooth provides the ability to connect and interact with Bluetooth Low Energy devices from a web browser.

Browse to the Espruino IDE Part 1

Point a web browser to

Espruino IDE

Connect with Web Bluetooth Part 2

Click on the Connect/Disconnect icon at top left, and then select Web Bluetooth from the popup.

Connecting to a device in the Espruino IDE

Pair with the Puck.js Part 3

Identify and select the Puck.js from the list of scanned devices, then click Pair.

If the desired Puck.js does not appear, check the following:

  • is it powered on?
  • is it in range of the computer?
  • is it connectable in the Settings menu?
Web Bluetooth pairing in the Espruino IDE

If pairing is successful, the Connect/Disconnect icon at top left will turn green. The Puck.js can now be programmed wirelessly from the browser using Web Bluetooth.

Programming the Puck.js   Step 2 of 2

Load a JavaScript file and send it to the Puck.js.

Why JavaScript?
JavaScript runs on almost every modern website (client-side), on many back-ends with Node.js (server-side), and lends itself well even to embedded devices.
Any alternatives?
The Espruino IDE provides a Graphical Editor for novices to program with blocks.

What to program?

The Puck.js can be programmed with an existing file, or from code written in the IDE as either JavaScript or blocks.

The following files are maintained by reelyActive:

  • Espruino Apps
    reelyActive GitHub repository of apps for Espruino devices.
  • DirAct
    Proximity identification with Bluetooth Low Energy.

Hello Puck* in JavaScript:

var on = false;
setInterval(function() {
  on = !on;
}, 500);

* This is the default code loaded in the Espruino IDE. It will blink the red LED.

Hello Puck* in Blocks:

Hello Puck as blocks

* This is the equivalent of the Hello Puck JavaScript. It will blink the red LED.

Open a file to program Part 1

Click on the Folder icon in the centre toolbar to select a JavaScript file to program the Puck.js.

Opening a file in the Espruino IDE

Send to Espruino Part 2

Click on the Send to Espruino button in the centre toolbar with the default option to write the file to RAM.

Sending a file to Espruino

Confirm the program runs successfully Part 3

A few seconds after the file send begins, status messages will indicate if the file was successfully sent. At this point, the program will begin execution.

If there are errors in the program, these will appear in the console on the left side of the screen. Otherwise, the program will run in memory until the Puck.js is reset or power-cycled.

File sent to Espruino

Disconnect from the Puck.js Part 4

Once the program runs successfully, disconnect from the Puck.js by clicking the Connect/Disconnect icon at top left.

Disconnecting from Puck.js in the Espruino IDE

Where to next?

Configure other Espruino devices, or continue exploring our open architecture and all its applications.