Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Using LightBlue Bean+ with the UnaShield
The LightBlue Bean+ by Punch Through is a tiny Arduino-compatible board with built-in:
Lithium battery (600mAh)
Two ports for Grove sensors
And Bluetooth 4.0, supporting iBeacon and Arduino flashing / log access over Bluetooth!
By adding the UnaShield to the Bean+, you create a self-powered sensing device that can send sensor data to the SIGFOX cloud for many days on a single charge!
You may order the Bean+ online from SeeedStudio. They ship from Hong Kong and will arrive in Singapore within a week.
Here are the instructions for installing the Bean+ to be programmed from your Windows PC or Mac, and for connecting the UnaShield to your Bean+. Although the instructions provided below were meant for the Windows platform, the steps for the Mac are similar and simpler. In fact, I feel that the Bean+ works better with a Mac.
Connecting the Bean+ to the UnaShield
Check the Fritzing file for details:
Installing the Bluetooth Dongle
Mac users may skip this step
To program the Bean+ with your Windows computer, you need to use a supported Bluetooth 4.0 USB dongle (or built-in Bluetooth 4.0 adapter) that's listed here:
I used a Bluetooth 4.0 dongle from Asus, the results were somewhat erratic. Follow the dongle installation instructions here:
You should see Zadig screens like the below, for loading the WinUSB driver for Bluetooth.
Why is this step needed? The Bean+ tools assume that all Bluetooth adapters on Windows are accessible through a common API, which is the WinUSB API. We use Zadig to disable the native driver for the Bluetooth adapter and install the WinUSB driver instead.
Installing the Bean SDK
Follow the instructions here to install the Bean SDK, which includes command-line tools for browsing and flashing our Bean+ via Bluetooth:
On Windows, remember to run the commands in "Run As Administrator" mode. If you see an error like:
Error: No compatible USB Bluetooth 4.0 device found! TypeError: Cannot read property 'controlTransfer' of undefined
Check that WinUSB has been installed according to
Configuring the Bean+
Switch on the Bean+ and continue with the "Scan And Locate" instructions here to find our Bean+ over Bluetooth:
You should see something like this:
C:\> bean scan Scanning for LightBlue devices for 30 seconds... New Device discovered or updated! DEVICE_TYPE_LIGHT_BLUE: Name: Bean+ Address: 987bf3582ce7 Advertised Services: a495ff10c5b14b44b5121370f02d74de Command completed.
Every Bean+ has a unique ID like
987bf3582ce7 and we need to include this ID whenever we access the Bean+ via Bluetooth. For convenience, we may give the Bean+ a name that's easier to type:
bean rename lupyuenbean1 -a 987bf3582ce7
This means look for the Bean+ with address
987bf3582ce7 and rename it to
lupyuenbean1. From now, we may refer to our bean through
-n lupyuenbean1 instead of the hard-to-recall address.
Run the command above, change
987bf3582ce7 to your own values. You should see something like this:
Found device with name/address: 987bf3582ce7 Connected! Renaming Bean to: lupyuenbean1 Command completed.
Updating the Bean+ firmware
Run this command to update the Bean+ firmware:
bean -n lupyuenbean1 program_firmware
lupyuenbean1 is the name of our Bean+.
We should see:
Found device with name/address: lupyuenbean1/987bf3592ae0 2016-12-06T06:17:56.207Z INFO Connecting to device: lupyuenbean1 2016-12-06T06:17:56.629Z INFO Looking up services for device: lupyuenbean1 ... 2016-12-06T06:17:58.128Z INFO Offering image: 201611070000_b_BeanPlus_imgB_large 2016-12-06T06:17:58.151Z INFO REJECTED IMAGE: 201611070000_b_BeanPlus_imgB_large 2016-12-06T06:17:58.214Z INFO Offering image: 201611070000_c_BeanPlusSmallImgA 2016-12-06T06:17:58.241Z INFO ACCEPTED IMAGE: 201611070000_c_BeanPlusSmallImgA ... 2016-12-06T06:17:58.249Z INFO Got request for FW block 0 2016-12-06T06:18:00.836Z INFO Got request for FW block 512 2016-12-06T06:18:03.507Z INFO Got request for FW block 1024 ... 2016-12-06T06:18:26.817Z INFO Got request for FW block 5632 2016-12-06T06:18:27.417Z INFO Last block Sent 2016-12-06T06:18:27.417Z INFO Sent 5759 in 29 seconds ... 2016-12-06T06:18:30.087Z INFO Offering image: 201611070000_b_BeanPlus_imgB_large 2016-12-06T06:18:30.116Z INFO ACCEPTED IMAGE: 201611070000_b_BeanPlus_imgB_large ... 2016-12-06T06:18:30.125Z INFO Got request for FW block 0 2016-12-06T06:18:32.262Z INFO Got request for FW block 512 2016-12-06T06:18:34.408Z INFO Got request for FW block 1024 ... 2016-12-06T06:19:10.663Z INFO Got request for FW block 9728 2016-12-06T06:19:12.208Z INFO Last block Sent 2016-12-06T06:19:12.209Z INFO Sent 10111 in 42 seconds ... 2016-12-06T06:19:15.598Z INFO Comparing firmware versions: Bundle version (201611070000), Bean version (201611070000) 2016-12-06T06:19:15.600Z INFO Versions are the same, no update needed 2016-12-06T06:19:15.601Z INFO FW update COMPLETED for lupyuen2(987bf3592ae0) 2016-12-06T06:19:15.603Z INFO FW update process took 78 seconds Command completed.
Compiling and uploading an Arduino SIGFOX sketch
Continue with the "Associate With Arduino" steps described here:
This updates the Arduino system libraries to include the Bean+ libraries.
C:\> bean install_bean_arduino_core Where is Arduino core installed? (ex. C:\Program Files(x86)\Arduino\) Path: c:\Program Files (x86)\Arduino\
If you see an error like:
Error: EPERM: operation not permitted, mkdir 'c:\Program Files (x86)\Arduino\hardware\LightBlue-Bean'
make sure that you are running the command in "Run As Administrator" mode.
Copy the contents of these 2 files:
and overwrite these 2 files on Windows:
C:\Program Files (x86)\Arduino\hardware\LightBlue-Bean\avr\libraries\SoftwareSerial\SoftwareSerial.h C:\Program Files (x86)\Arduino\hardware\LightBlue-Bean\avr\libraries\SoftwareSerial\SoftwareSerial.cpp
or on Mac:
Why is this needed? We'll explain below under Serial Receive Issue
unabiz-arduino library from:
Unzip the file and open the example sketch in the Arduino IDE:
Click Tools -> Board -> LightBlue Bean+ to select Bean+ as the Arduino board. You don't need to select the port.
In the Arduino IDE button bar, click Verify and Upload
Normally this would cause the compiled program to be uploaded into the Arduino flash memory. But on the Bean+, the compiled program is actually stored in your Windows PC or Mac, waiting to be transmitted to your Bean+.
Run this command to transmit the compiled program for
send-light-level to your Bean+ via Bluetooth:
bean program_sketch -n lupyuenbean1 send-light-level
lupyuenbean1 is the name of your Bean+. You should see:
2016-12-02T20:40:35.300Z INFO Connecting to device: lupyuenbean1 2016-12-02T20:40:38.765Z INFO Sketch upload started! 2016-12-02T20:40:40.143Z INFO Sending Bean sketch block: 0/94 2016-12-02T20:40:40.347Z INFO Sending Bean sketch block: 1/94 2016-12-02T20:40:40.551Z INFO Sending Bean sketch block: 2/94 ... 2016-12-02T20:40:59.374Z INFO Sending Bean sketch block: 94/94 2016-12-02T20:40:59.547Z INFO Sketch upload complete! 2016-12-02T20:40:59.548Z INFO Sketch completed successfully!
Running and debugging the sketch
When the compiled program has been uploaded to the Bean+, the sketch will start running immediately. We may see the Arduino log by connecting over Bluetooth with this command:
bean log_serial -n lupyuenbean1
You should see this:
Found device with name/address: lupyuenbean1/583dc23b1c194d3cbff3443b85db51b1 Connected! Logging serial data... << 3e - Radiocrafts.sendBuffer: response: - Radiocrafts.sendBuffer: ff >> ff << 3e - Radiocrafts.sendBuffer: response: - Set frequency result = - Getting frequency (expecting 3)... - Radiocrafts.sendBuffer: 5900 >> 59 00 << 3e - Radiocrafts.sendBuffer: response: - Frequency (expecting 3) = light_level=498 Running loop #0 - Radiocrafts.sendBuffer: 55 >> 55 << 00 3e - Radiocrafts.sendBuffer: response: 00 - Radiocrafts.getTemperature: returned -128 - Message.addField: ctr=0 - Message.addField: lig=498 - Message.addField: tmp=-128 - Radiocrafts.sendMessage: 001c8653,920e000027317413b05100fb - Radiocrafts.sendBuffer: 58 >> 58 << - Radiocrafts.sendBuffer: response: - Radiocrafts.exitCommandMode: OK - Radiocrafts.sendBuffer: 0c920e000027317413b05100fb >> 0c 92 0e 00 00 27 31 74 13 b0 51 00 fb << - Radiocrafts.sendBuffer: response:
Note that the first few lines of the log may be missing. That's because the sketch started running the moment that the transmission of the program code has completed.
For Arduino Uno and most other Arduino boards, when we use Serial Monitor to connect to the default serial port (D0, D1), the sketch will automatically restart so that we can see the start of the log. This restart doesn't happen on the Bean+.
(FYI: On the Bean+, you may use D0 and D1 for connecting your sensors because D0 and D1 are not reserved for the default serial port. When you call
Serial.print on Bean+, it actually gets routed to the Bluetooth logging interface.)
You may also troubleshoot your programs through Slack as usual:
Serial receive issue
For the SIGFOX communications to succeed, the Arduino board must be able to send and receive data over a UART / Serial port configured over pins D4 and D5, to the SIGFOX module connected at those pins.
When I tested with a UART-USB adapter, the Bean+ was able to transmit data properly, but it can't receive any data. I believe there is a problem supporting interrupts in the SoftwareSerial class, so I provided my own class BeanSoftwareSerial to handle interrupts the Bean way.
The existing SoftwareSerial class has been modified so that it is not compiled into the app.
Out of memory?
If your sketch contains too much program code or data, you may exhaust the available runtime memory without any warnings. The Bean+, like the Arduino Uno, has only 2 KB of dynamic memory.
The following commands may help you to find out the biggest chunks of code/data and slim them down.
~/Library/Arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.3-arduino2/avr/bin/readelf -a -z -W -g -I -t /var/folders/gp/jb0b68fn3b187mgyyrjml3km0000gn/T/build7cf9eadc19be45730de287bcbfcb7ca8.tmp/send-light-level-161203a.ino.elf ~/Library/Arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.3-arduino2/avr/bin/readelf -w /var/folders/gp/jb0b68fn3b187mgyyrjml3km0000gn/T/build7cf9eadc19be45730de287bcbfcb7ca8.tmp/send-light-level-161203a.ino.elf
unashield.fzpz: Fritzing component / part for UnaShield
beanplus.fzpz: Fritzing component / part for Bean+
unashield.svg: SVG vector graphic used to create Fritzing part for UnaShield
beanplus.svg: SVG vector graphic used to create Fritzing part for Bean+
unashield.ai: Adobe Illustrator source for SVG graphic of UnaShield
beanplus.ai: Adobe Illustrator source for SVG graphic of Bean+