Control a Raspberry Pi with Bluetooth

You want a cool home automation or robot arm or something managed by a Raspberry Pi. Don’t waste any time dealing with UI, focus on your project and control everything from a desktop or mobile using druid.

Here well cover all the basics of getting device druid running on a Raspberry Pi. A quick overview is also available in this video:

Step 1: Define your Interface

Choose a menu structure, and which controls and inputs are required. Set it all up in the online druid builder, by heading to the design tab and adding commands, submenus and inputs. Drag & drop them into place until you’re satisfied.

From there, head to the code tab, enter a short name for your project. Be sure to select Raspberry Pi (Python/bluetooth) for the platform, in the top right.

Now, hit the big yellow wizard button, so it will do its magic and generate the project.

Downloads

Once the project has been generated, you’ll get a little report and the option to download the project. Save that zip file. Within, you’ll find the source code that was generated, along with a deb package, called YourProjectName.version.deb. Send that over to the Pi.

If this is the first time you install a druid program on the Raspberry Pi, you’ll also need some support libraries–get those on the download page and move them to the Pi, too.

Step 2: Raspberry Pi Setup

Whether via ssh or using a keyboard and screen, log into the Pi.

If you haven’t done so before, install the support debs as described. Short version is :

sudo dpkg -i libgobble* libserialui* 

If dpkg complains about missing dependencies, you can use apt-get to install those.

If you intend to run the druid program as the default “pi” user, then you’re all set. Otherwise, there’s a little config file to edit. With your preferred editor, e.g. vi or nano, edit

sudo vi /etc/dbus-1/system.d/gobblededruid.conf

Up at the top there’s a <!– commented –> section. Uncomment that (removing the “<!–” and “–>”), or replicate it, being sure to replace the user which whichever username you’ll be running the programs as:

<policy user="myusername">
... </policy>

Now you’re good to install your own program. Use the same dpkg -i command on the deb that was generated for you:

sudo dpkg -i YourProjectName.version_arhmf.deb

Step 3: Launch the program

The installation process will output a little help to indicate how to start the program. You should just be able to issue a /usr/local/bin/whatever to start her up.

Now, from your desktop or mobile, launch device druid. If all goes well, you should be able to see the Pi broadcasting your project name. Connect and start playing.

Step 4: Extending the functionality

If you can connect and play with the buttons, it may be pretty and all but it isn’t too useful yet. The next step is to use Python to extend the functionality and actually do something interesting when the user clicks “do it!“.

See the Extending Druid With Python section for info on that.

Troubleshooting

If the Pi-gods aren’t particularly smiley today, you may run into some issues. The first thing to do is get a bit more info. Start your program with the “-h” switch to see what’s available, or just do

/usr/local/bin/myprogramname -d

to get lots of debug info. It may be a permissions issue. Try running as root (“sudo” before the launch command). If that fixes the problem, then double check the gobblededruid.conf step, above. If it all looks good, you may need to restart dbus, or just reboot and try again to see if the configuration took effect.