Connecting your phone to the LightBlue Bean

Andreas LundquistBlogs, Tutorials

Tweet about this on TwitterShare on FacebookShare on LinkedInShare on Google+

Got a LightBlue Bean microprocessor? Great, then this article is for you and others might find it interesting as well. It’s about how to connect your smartphone to the LightBlue Bean, a small form-factor Arduino-clone from PunchThrough Design. We use Bluetooth Low Energy (BLE) and our house toolset Evothings Studio to make this happen. We’ve also shared an example application for you, to use as a starting point for your own projects, showing you how to read and write data utilizing the provided scratch data areas on the LightBlue Bean with an Android or iOS device.



To run this example you need the following:


  • A LightBlue Bean unit
  • An Apple computer running OS X 10.9 or above
    (Windows Bean loader coming soon)
  • A modern smartphone running BLE hardware


Running under Android requires OS ver 4.3 or later with support for Bluetooth Low Energy communications. Please note that BLE support on Android is still not fully mature, and results may vary and depending the make and model of your device – you may experience difficulties running this example. If the app stops working, simply restarting the Evothings client app and/or reset Bluetooth on the device usually helps.

Loading a Bean

To load a sketch onto the LightBlue Bean, you need an Apple computer running OSX 10.9 or later. Punch Through Design provides a development schedule where you can get information about upcoming software releases. As of October, 2014 they are about to release a loader for Windows 8.1 as well.

To load the example sketch onto your LightBlue Bean you need to prepare your computer, and Punch Through Design provides an excellent guide on how to do that.

The provided sketch is very straight-forward; if there is a connection present, the microprocessor writes the current temperature to the scratch data area 2 and then reads the data in scratch data area 1 and configures the LEDs accordingly. If the connection is lost, the LEDs are turned off and the microprocessor is put to sleep.

After loading the sketch onto the LightBlue Bean, do not forget to disconnect it from the LightBlue Bean – Loader application, since it only can be connected to one client at a time.

Please note that the example will not work if the LightBlue Bean is configured to be safeguarded with a pin code. If you know the pin code you can remove it by right clicking on the device in the LightBlueBean – Load application and select Pin Code Settings. If you have no clue about the pin code you need to reset your device, here are the instructions.


Connect to your LightBlue Bean

In order to connect to your LightBlue Bean, you insert the name of your bean and press connect. If the bean is within range, the application will connect to it and show you various controls. The name of your bean is configured inside the Arduino sketch, by changing the variable beanName. If you do change the name, be aware of some issues that might occur, read more in the Known issues section below before proceeding.

When the Connect button is pressed the method app.connect() is executed. The method starts to scan after BLE enabled devices nearby. Each device is evaluated using the method deviceIsLightBlueBeanWithBleId(). If the correct device is detected a connection is established.

LED control

When one of the range sliders is changed, the application executes the method app.sendLedUpdate(). This is a method that reads all range sliders values and creates a buffer that is written to the scratch data area 1 using the established BLE connection.


When a connection is established, a timer is created using the setInterval() method. This method executes a certain function at a specified time interval – in this case twice every second. This function executes the method app.readTemperature(), which in turn reads the temperature from the scratch data area 2 using the BLE connection. The user interface is then updated with the new temperature.


If the connection is lost or the user presses the button Disconnect, the method app.disconnect() is executed. This method ensures that the connection is closed and resets all state variables.

Known issues on connecting

On iOS; clients can’t connect to a LightBlue Bean after its beanName has been changed, at least not without drastic measures.

The beanName is the advertising name the LightBlue Bean uses when in advertising mode. On iOS devices, there is a known issue where iOS caches that name. Unfortunately, there is no known method how to clear this cache as for now. If you experience issues after changing the beanName, try to turning your devices Bluetooth subsystem off and on again. Other remedies include restarting the Evothings Client and/or restart your iOS device in order to clear the cache.