element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
microbit
  • Learn
  • Learning Center
  • STEM Academy
  • microbit
  • More
  • Cancel
microbit
micro:bit Blog 1 Micro:Bit + 1 Raspberry Pi 3 + 1 Bluez Upgrade = 1 Huge Headache
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join microbit to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: modalpdx
  • Date Created: 16 Sep 2016 4:49 AM Date Created
  • Views 878 views
  • Likes 2 likes
  • Comments 3 comments
  • micro:bit
  • bluez
  • raspberry pi
  • headaches
Related
Recommended

1 Micro:Bit + 1 Raspberry Pi 3 + 1 Bluez Upgrade = 1 Huge Headache

modalpdx
modalpdx
16 Sep 2016

Updated 9/21/2016 to include an image and Bluez/BLE setup instructions for Raspbian "Jessie" on Raspberry Pi 3.

 

Oh deary dear...this is not what I wanted to do on a Thursday afternoon.

 

Some background:

 

I recently won an opportunity to build an "alert button" project using a Micro:Bit and a Raspberry Pi (thanks again, element14!). The Micro:Bit will be shipping soon, and the Raspberry Pi (not supplied by element14) is sitting in my office humming very warmly under a table, waiting to be put to work.

image

Coincidentally, a Mini Maker Faire took place last weekend in my city, and one of the workshops at the event was about Micro:Bits. I made sure I was first in line, and lucky me, the first 20 people got a free Micro:Bit. That was a very nice surprise! So, all week I've been playing around with a Micro:Bit while I wait for the element14 Micro:Bit to arrive.

 

Communication between a Micro:Bit and my Raspberry Pi is central to my project. Both devices support Bluetooth Low Energy (BLE), so I figured I'd be in good shape communication-wise. What I didn't consider was how well BLE is supported on Raspbian, which is the version of Linux running on the Raspberry Pi. And by "how well BLE is supported," I actually mean "how little BLE is supported." In fact, I'm pretty sure there is no distribution of Linux for Raspberry Pis that supports BLE out of the box. BLE support is experimental at best, and you can't even get the experimental support without replacing a tricky software package/suite called "Bluez". The version of Bluez in the latest Raspbian (Linux on Raspberry Pi) is 5.23, but you need at least version 5.40 to get BLE. And folks, let me tell you, this is one BEAR of a package to replace. It's ugly, very ugly, and even when it's installed and allegedly running it does not always work as expected. To make things even more fun, there are many forums and webpages that discuss upgrading Bluez, but none of them describes 100% of the process.

 

I managed to upgrade Bluez today. I took detailed notes as I upgraded, and they are shared below. The problem is, like anything that sporadically works on Linux, good instructions can get you 95% of the way to a solution but that last 5% is going to resemble throwing spaghetti at a wall. Maybe that's why none of the online help takes you 100% of the way toward a solution? Once the software is installed and running, nothing short of a series of random power on/off cycles, scan sessions, connect and pairing attempts, reboots, etc will get the Micro:Bit seen and paired. Once paired, the pairing seems to stick at least for a while. Sometimes the pairing mysteriously drops and the process begins again. And even when the Micro:Bit is paired and connected, experimenting with its GATT attributes is sometimes effective, sometimes not so effective. After a few hours of experimenting, I felt like a caveman banging two rocks together trying to get them to talk.

 

Anyway, here are the steps and/or commands that I executed to get Bluez/BLE set up on my Raspberry Pi so my Micro:Bit could at least pair and connect to it:

 

sudo apt-get install bluetooth

 

sudo apt-get install bluez-tools

 

sudo apt-get install build-essential

 

sudo apt-get install autoconf

 

sudo apt-get install glib2.0

 

sudo apt-get install libglib2.0-dev

 

sudo apt-get install libdbus-1-dev

 

sudo apt-get install libudev-dev

 

sudo apt-get install libical-dev

 

sudo apt-get install libreadline-dev

 

Download and extract the latest Bluez source code (v5.41 is the latest as of 9/21/2016):

 

wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.41.tar.xz

 

tar xf bluez-5.41.tar.xz

 

Change into the directory created by the tar command above, then configure, build, and install Bluez:

 

cd bluez-5.41

 

./configure --prefix=/usr \

            --mandir=/usr/share/man \

            --sysconfdir=/etc \

            --localstatedir=/var \

            --enable-experimental \

            --enable-maintainer-mode

 

make

 

sudo make install

 

You may want to play with gatttool at some point. It is part of Bluez and is built in the make step above, but it is not installed by default. You will need to manually install it (optional):

 

sudo cp attrib/gatttool /usr/local/bin

 

Enable experimental support in the bluetooth daemon (this enables BLE). Put this all on a single command line:

 

sudo sed -i '/^ExecStart.*bluetoothd\s*$/ s/$/ --experimental/' /lib/systemd/system/bluetooth.service

 

Raspbian installs bluetooth firmware in directory not recognized by Bluez, so make a symbolic link (it's like a Windows alias) that references the firmware directory in the location Bluez expects it to be in (/etc/firmware):

 

sudo ln -s /lib/firmware /etc/firmware

 

Now, enable bluetooth to load during system boot, then reload daemons to load it without rebooting, or just reboot after enabling it.

 

sudo systemctl enable bluetooth

 

sudo systemctl daemon-reload

 

The following seems to be needed every time the Raspberry Pi boots. This should go in a startup script somewhere, but I have not figured out which one yet. For now, every time the Raspberry Pi reboots, just run this command:

 

/usr/bin/hciattach /dev/ttyAMA0 bcm43xx 921600 noflow -

 

At this point, you should be able to run bluetoothctl as root (sudo bluetoothctl) and start playing. If you wish to do bluetoothy things as user pi, allegedly you can make this happen by duplicating the entire policy for user root and changing root to pi in /etc/dbus-1/system.d/bluetooth.conf. Just copy/paste the entire section from the opening root policy tag to its closing policy tag and edit the username. I suspect you need to be root to do other things so I won't promote this as a solid path to follow. It's best to stick with root (sudo command).

 

Some people think it's best to set the bluetooth system to be BLE-only. If you want to do this, ensure that /etc/bluetooth/main.conf contains the following line:

 

ControllerMode = le

 

I tried this and did not notice any difference, but your mileage may vary.

 

One last thing. Be sure to suspend updates to the Bluez package in Raspbian, otherwise you'll overwrite your hand-built version of Bluez next time you update/upgrade:

 

sudo apt-mark hold bluez

 

To remove the hold at a later date:

 

sudo apt-mark unhold bluez

 

WHEW, that's a lot of steps just to get one package updated. Quite frankly, I'm surprised that the Raspbian folks use such an outdated version of Bluez in "Jessie" considering that bluetooth is one of the Raspberry Pi's bigger selling points.

 

As a backup plan, I took a shot in the dark and ordered two 2.4GHz transceivers via eBay in case the vanilla 2.4GHz radio support in the Micro:Bit works better without being clogged with BLE. Something tells me the Micro:Bit radio protocol relies on Micro:Bits speaking only with other Micro:Bits, but the transceivers were dirt cheap so I won't be upset if they don't work like I want them to. I'll do something else with them, I guess. The transceivers have arrived, and as soon as I come up with a method by which Micro:Bits can chat with Raspberry Pis via a transceiver, I'll write another post. This one's long enough.

 

I was inclined to write this off as a Raspberry Pi + Bluez issue more than a Micro:Bit issue, but my two Roku boxes have had no problems being seen by Bluez while Micro:Bits have been more finicky, so the issues I've experienced are probably a combination of Bluez, Raspberry Pi's bluetooth hardware, and Micro:Bit's bluetooth hardware. Don't know. It will work eventually, I just know it.

 

Onward.

  • Sign in to reply

Top Comments

  • modalpdx
    modalpdx over 8 years ago in reply to neilk +1
    I actually had to put this project on the shelf because of time constraints so I haven't beaten on it lately. Around the time I stopped working on it, I was working with the radio transceivers and having…
  • neilk
    neilk over 8 years ago in reply to modalpdx

    Thanks for the update image

     

    I've seen how cheap the 2.4GHz transceivers are - I may invest in a pair in the new year, try them out with Arduinos & then see if I can get into the BBC micro:bit radio.

     

    My experiences with the micro:bit BLE are getting worse - things that are definitely supposed to work - ie someone has posted a solution, only work if you load their code written at low-level. If you try to do the equivalent with their PXT blocks, it doesn't work, even the poster did have it working.....not sure where I'm going with this.

     

    Merry Christmas

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • modalpdx
    modalpdx over 8 years ago in reply to neilk

    I actually had to put this project on the shelf because of time constraints so I haven't beaten on it lately. Around the time I stopped working on it, I was working with the radio transceivers and having no luck. I got two Raspberry Pis to chat with each other using the transceivers, but I never got a peep to be passed between a Micro:Bit and an RPi via radio. I think the problem was in the radio user and group values passed from the Micro:Bit. I found a website that allegedly had default values used by Micro:Bits, but either I didn't know how to connect with them via Python on the RPi side or the site had incorrect default values. Either way, no communication. It was severely frustrating, and it made me wonder if there's something wonky in Micro:Bits that's different just for the sake of being different. Grr... So no, unfortunately I have not tried Arduinos and transceivers yet (just RPis with Python libraries) but some day when I have time to try this again my two Arduinos will be employed to help me out. image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 8 years ago

    Great posts!

     

    Playing with a micro:bit myself at the moment but not getting anywhere with micro:bit BLE and my phone - I can pair, connect and disconnect, but can't establish communications.

     

    Have you tried (and had any luck with) Arduino and 2.4 GHz radio?

     

    Neil

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube