This guide will help get you started with understanding the capabilities of the LightBlue Bean and how the Bean works and communicates with the outside world.  Before trying out any of the examples in the guide, be sure to run through the installation instructions found in our Getting Started guide.

But first, what is the LightBlue Bean… really?

The LightBlue Bean is an Arduino compatible Bluetooth Low Energy (BLE) development board that you can program wirelessly using BLE. Since it has BLE built-in, it can communicate to your devices over BLE, extending the capabilities of your Arduino sketches to communicate with your phone, laptop, and other BLE capable devices. The Bean also has a bunch of useful peripherals and I/O to use in your projects.

It has:

  • An on-board accelerometer
  • A temperature sensor
  • An RGB LED
  • Digital/analog I/O
  • I²C (Inter-Integrated Circuit)
  • SPI (Serial Peripheral Interface)
  • A built-in protoboard

All of these features should get you going building a multitude of projects with the potential to add BLE connectivity.

So how do I communicate with the Bean?

The Bean provides two easy methods of communication over BLE. The first is wireless serial using the built-in read/write functions in the Arduino Serial Library. The second is a native interface to BLE using what we call “Scratch Characteristics“.

Wireless Serial

The native  Arduino Serial Library communicates with your BLE device using a virtual serial port. When using the loader app, you can enable this serial port in OS X as /tmp/tty.LightBlue-Bean. All the nitty gritty protocol serial-BLE-serial bridging is taken care of for you in the background.

To get started experimenting with the serial-BLE bridge, choose the “SerialLoopback” example in the Arduino IDE by navigating to: “File->Examples->LightBlue-Bean->01.Basics->SerialLoopback”. Once it’s open click “Upload”. Be sure to have LightBlue Bean selected as your dev board.

Go to your Loader App and upload the sketch to your Bean.

Right-click on your connected bean and choose “Use for Virtual Serial”. This will open up the /tmp/tty.LightBlue-Bean virtual serial port for your use.

Loader app Virtual Serial

Back in the Arduino IDE, select the LightBlue Bean serial port:

LightBlue Bean Virtual Serial Port

Open up the Arduino Serial Monitor by choosing “Tools->Serial Monitor”. Type some stuff into the text box and press enter. What appears in the console is what the Bean has returned.

Hello, World!

Scratch Characteristics

In addition to the BLE wireless serial, we’ve added 5 “scratch” characteristics that can be used to send any type of data to your devices. Using an application like LightBlue, you can easily read and write data to these characteristics. Here’s a view of these characteristics in LightBlue:

LightBlue Scratch Characteristics

The Arduino Bean Library

We’ve included an Arduino Bean Library that can be used to:

Digital I/O and I2C/SPI Buses

To read the digital/analog pins, you use the regular Arduino digitalWrite/Read and analogWrite/Read functions you may already be familiar with (note: analogWrite is actually used on PWM pins which are digital pins). The same is true of using the I2C and SPI bus libraries.

Here’s a diagram of the pinouts (inspired by the Teensy pinout diagrams) :

 

Pinout-diagram

A0 and A1 are your typical analog input pins. D0-D5 offer 6 digital I/O pins. A0 and A1 can also be used as digital I/O, giving you 8 digital I/O total.
Digital pins 0-3 can be used for PWM and “analog” outputs (analogWrite is really just a digital PWM output).

SPI and I2C also share these same 8 pins. SPI is on D2-D5, whereas I2C shares the A0 and A1 analog pins. Connecting both a SPI and I2C device to your bean should still leave you with 2 digital I/Os.

The pins below the A0-1 and D0-5 pins are protoboard pins that are isolated from one another and the Arduino.

If you’d like to wire your own battery, pins BAT and GND can be connected to V+ and V-, respectively. The Bean doesn’t have an on-board voltage regulator, so be sure to limit voltages between 3.0V and 3.6V.

To understand why the Bean library is used for certain features, we should take a look at a systems view of the Bean.

A Systems View of the Bean

Bean Systems Diagram

At the heart of BLE communications on the Bean is the LBM313 Bluetooth Low Energy Module. The LBM313 handles all BLE traffic to and from the Arduino. But the LBM313 has more duties than this alone; it also controls communication between the BMA250 accelerometer and temperature sensor, and sets the intensities of the RGB LEDs. The Bean is designed this way to free up the digital and SPI/I2C bus pins on the Atmega328p so they can be used freely in your projects.

The Arduino microcontroller used is the Atmega328p. This is bridged to the LBM313 using serial communication (UART at 57600bps). We’ve constructed a serial protocol that allows the LBM313 and Atmega328p to communicate both messages from the client (OS X, iOS, etc.) to the Arduino, as well as send special commands to the LBM313 to do things like read the temperature sensor and set the LED. This is all done behind the scenes to make the Bean easy to use. It’s useful to understand how the Bean works as a system, but its primarily built to help you experiment and get projects completed without a lot of fuss.

Conclusion

We hope this guide helps you to start getting the most out of your Bean! If you have further questions, our Community Forum provides a great source of project ideas and technical help.

 

Chris KellerArduino User’s Guide to the LightBlue Bean