How To: BrewPi Over Bluetooth

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

day_trippr

The Central Scruuuutinizer
HBT Supporter
Joined
May 31, 2011
Messages
44,177
Reaction score
31,757
Location
Stow, MA
As promised, here is a procedure to run BrewPi over a Bluetooth link to the Arduino UNO R3. I've had this running for a few days without a single hiccup, even have had two instances running (and sharing the host-side Bluetooth/USB dongle) without any issues. btw, I don't know how many BT/Serial links the host BT/USB dongle (et al) can support, but for sure it can handle at least two.

I have parked an archive on my Google Drive here. It contains instructions, a sketch file, wiring diagrams and a copy of the latest BrewPi hex file for the UNO.

So...What follows is taken directly from the contents of brewpi_over_bluetooth.txt.
Hopefully it's lucid enough for others to follow, but as always, let me know if there's something that could use revising.

Finally, I cannot stress enough the importance of obtaining the correct HC-05 module. There's a myriad of variations of similar modules out there, but they sport different pin counts and connections at the header, and different operating firmware. It took me three tries to get a "good" one. First test: if it doesn't have a pin labeled "Key", give it a miss. If you want a sure bet, use the link provided.

The Bluetooth/USB dongle is recommended as it's pretty much the latest/greatest, but other dongles may work fine. The BT/Serial modules had no problem talking to computers in the house using different dongles, fwiw, so that end may be significantly less critical.

Cheers!

----------------------------------------------------------------------------------
BrewPi Over Bluetooth Setup
14dec2014

Forward:

This procedure will enable communication between a BrewPi host and an Arduino UNO R3 over Bluetooth.
It uses a BT/USB dongle in master mode on the host side and a BT/Serial module in slave mode on the UNO side.

NOTE: To free the UNO hardware serial port pins for use by the BT/Serial module instead of the UNO USB-serial bridge, the UNO USB port cannot be plugged.
This requires the UNO to be powered by its power receptacle using a 7V to 12V DC power supply.

This procedure assumes the user has BrewPi already running successfully under Raspbian on a RaspberryPi using an Arduino UNO R3 and wants to change the connection between the BrewPi host and the UNO from USB to Bluetooth.
While most of the instructions will still apply, using a different BrewPi host setup is outside the scope of this procedure.

Stuff needed:

Recommended BT/USB dongle: CSR 4.0 http://www.amazon.com/gp/product/B00L08NCPQ/?tag=skimlinks_replacement-20
Recommended BT/Serial module: Innogear HC-05 http://www.amazon.com/gp/product/B00JP05S6C/?tag=skimlinks_replacement-20

(2) 1K ohm resistors (1/8W axial)
(2) 2K ohm resistors (1/8W axial)

Dupont jumpers or alternative as required

Overview:

The first steps install the necessary packages to support Bluetooth and loading code to the UNO.

Then, as the BT/Serial Module default operating baud rate is usually not what is needed to work with BrewPi, the next steps will set up the Arduino UNO to allow changing the BT/Serial module settings. This includes a wiring scheme and uploading a sketch that will allow the user to communicate with the BT/Serial module in a maintenance mode.

Once the BT/Serial module baud rate has been changed, the BT/Serial module will be removed, and the BrewPi code will be uploaded to the UNO using the BrewPi web gui.

Finally, the BT/Serial module will be wired to the UNO in the operating configuration, the system powered up, the BT/Serial module will be paired with the BT/USB dongle, the BrewPi config file will be changed to use the virtual serial port provided by its BT/USB dongle, and BrewPi will be configured to use the UNO - just as if it was still connected via USB.

====================================================================================================
Procedure:

1. Installing Bluetooth USB Dongle support on the RPi:

First, update package pointers:

$ sudo apt-get update

Clear out orphaned packages:

$ sudo apt-get autoremove

Install the Arduino IDE (if not already installed):

$ sudo apt-get install -y arduino

Install Bluetooth support and tools:

$ sudo apt-get install -y bluetooth bluez-utils blueman

This may install as many as 93 packages!
The vast majority are drivers for Bluetooth devices.


Restart the system

Plug in BT/USB dongle

..............................................................................................

For information only:

$ lsusb - lists all attached USB devices

Example:

pi@rpints ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 005: ID 2341:0043 Arduino SA UNO R3 (CDC ACM)
Bus 001 Device 006: ID 0c40:8000
Bus 001 Device 007: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)


$ /etc/init.d/bluetooth status command shows Bluetooth status

Output should be: Bluetooth is running


Scanning for Bluetooth devices:

$ hcitool scan command to list discovered BT devices

Example:

pi@rpints ~ $ hcitool scan
Scanning ...
30:14:09:02:06:22 HC-05
D0:37:61:51:34:D5 DROIDX
00:02:72:32:D8:2C OBELISK

..............................................................................................

DO NOT PAIR WITH THE HC-05 YET!


2. Wire the BT/Serial Module to the UNO in programming configuration:

Wire the 6-pin BT/serial module to the UNO using resistor dividers on the BT RX and BT KEY input signals.
Refer to first image (hc05_wiring_programming.jpg)

UNO digital IO pin 9 to resistor divider then to BT/serial module KEY pin
UNO digital IO pin 10 from BT/serial module TXD pin
UNO digital IO pin 11 to resistor divider then to BT/serial module RXD pin
UNO 5V pin to BT/serial module VCC pin
UNO GND pin to BT/serial module GND pin


3. Connect UNO to host via USB and power up

BT/serial module LED should be blinking rapidly (~ half-second period)


4. Now load the programming sketch to the UNO:

Launch the Arduino IDE

File - Open to load the HC_05.ino sketch (included in the kit and listed below):

*************************************************************************************************************

Code:
/*

AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)

*/


#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() 
{
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH); 
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop()
{

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

*************************************************************************************************************

File - Upload to compile the sketch and upload to the UNO

Tools - Serial Monitor to launch the Arduino terminal session
The Serial Monitor should be set to 9600 baud, 1 stop bit, no parity bit, no flow control

The BT/Serial Module LED should be blinking slowly

Note: Dialogue commands and responses are framed with single quotes for clarity.
Do not use quotes in commands.


5. Change the HC-05 operating baud rate:

Check to see if HC-05 is alive:

Type: 'AT' and click the Send button
Response should be 'OK'

Check the operating baud rate:

Type: 'AT+UART?'
Response could be '+UART:9600,0,0' followed by 'OK'

Change the operating baud rate to 57600 1 stop no parity:

Type: 'AT+UART=57600,0,0' and click Send.
Response should be 'OK'

You can check to see if the command "took":
Type: 'AT+UART?'
Response should be '+UART:57600,0,0' followed by 'OK'


6. Reload the BrewPi hex file to the UNO:

Note: (see the edit3 postscript at bottom of this post - you may not have to revert to the USB connection to reprogram the Uno with the BrewPi hex file)

Remove power from UNO and BT/Serial module

Disconnect BT/Serial module

Connect UNO to BrewPi host via USB and power up.

Load BrewPi web gui and connect to instance

Start the script using the gui.

Use BrewPi Maintenance Panel - Reprogram Arduino to upload BrewPi AVR hex file.
A copy of the latest BrewPi AVR hex file (brewpi-UNO-revC.hex) is included with this kit.

NOTE: I've had varied success with restoring the BrewPi "old settings and devices" to the UNO so I usually don't bother and just set both to "No".
This will wipe the serial eeprom requiring re-entering the settings.

Stop the script using the gui.

Power off the UNO and disconnect from host


7. Wire the BT/Serial module in operating configuration:

Remove USB cable from UNO.

Connect BT/Serial module to UNO.

Refer to second image (hc05_wiring_operating.jpg)

UNO digital IO pin 0 ("RX") from BT/serial module TXD pin
UNO digital IO pin 1 ("TX") to resistor divider then to BT/serial module RXD pin
UNO 5V pin to BT/serial module VCC pin
UNO GND pin to BT/serial module GND pin

NOTE: Do not connect BT/serial module KEY pin to anything


8. Power up in operating configuration:

Connect UNO to power. You must use the UNO power receptacle with a 7V to 12V supply!

The BT/Serial Module LED should be blinking rapidly

You can use hcitool on the RPi to scan for BT devices

pi@rpints ~ $ hcitool scan
Scanning ...
30:14:09:02:06:22 HC-05


9. Pairing the BT/Serial module to the BT/USB dongle:

On the LXDE Desktop: launch Menu>Preferences>Bluetooth Manager (make a desktop shortcut while you're in the menu)

In Bluetooth Manager GUI:

Click Search: Find available BT devices

HC-05 will appear (listed as Unknown with its device address)

Select HC-05 (click once on the item)

Click the green Plus icon to add HC-05 to the Known Devices list

Click the Key icon to pair with HC-05
- pairing code is 1234

The HC-05 device should now have a Key (paired) and Star (trusted) icon
The BT/Serial module LED should now be blinking slowly (~once per two seconds)

Click Setup to view the local serial port associated with the HC-05 connnection - it should be /dev/rfcomm0
The BT/Serial module LED should now be double-blinking slowly (~two blinks per two seconds)



10. To get BrewPi to use the /dev/rfcomm0 port:

Edit the BrewPi config.cfg file for this instance.
This will be somewhere under the /home/brewpi folder.

If this is the only BrewPi AVR instance, the path most likely will be: /home/brewpi/config.cfg

Change the 'port' entry to use /dev/rfcomm0:

$ sudo nano /home/brewpi/settings/config.cfg

scriptPath = /home/brewpi/
wwwPath = /var/www/
port = /dev/rfcomm0
altport = /dev/null
boardType = UNO

Save (ctrl-o) and Exit (ctrl-x)


In this example this Uno is the second BrewPi in a multi-instance system, using the paths shown:

$ sudo nano /home/brewpi/brewpi2/settings/config.cfg

scriptPath = /home/brewpi/brewpi2/
wwwPath = /var/www/brewpi2/
port = /dev/rfcomm0
altport = /dev/null
boardType = UNO

Save (ctrl-o) and Exit (ctrl-x)



11. Finally, in a web browser, load the BrewPi web gui on the host for this instance.

Start the BrewPi script

Launch the Maintenance panel and check the log window.
- Should see script starting on device connected to /dev/rfcomm0

Configure Devices and Settings and you should be good to go!

Notes:
If the BrewPi web gui is unable to communicate with the UNO you will see messages in the log file.
At least one of those messages will list the device that BrewPi is trying to use.
Make sure it is trying to use /dev/rfcomm0 (note that's a ZERO)
If it's looking in the right place, check the wiring.
If it's not looking in the right place, go back and check the config.cfg file.


Cheers!

/dave t. aka day_trippr on homebrewtalk.com

[edit1] Corrected the voltage dividers in the two graphics
[edit2] Fixed an error in the programming graphic, added picture of Uno with the BT/serial module (note I ran out of 2K resistors so I used all 1K)
[edit3] fwiw, curiosity got the better of me so I tried reprogramming one of the BT Unos with the BrewPi revC hex file over the Bluetooth link.
And it totally worked - restored all the settings and automagically restarted the running script perfectly.
While a short USB connection is undoubtedly the most robust, if you want to try programming the Uno via BT, give it a try. Basically skip over step 6, execute steps 7 to 11, then once you get the BrewPi web gui up, use it to reprogram the Uno.

hc05_wiring_programming.jpg


hc05_wiring_operating.jpg


uno_with_bt_module.jpg
 
Last edited by a moderator:
Honestly don't know yet. I'll be pushing the two ends apart over the next few days to see what it will do.

In fact, thanks for reminding me, I'm going to move an UNO outside my office for the night...

Cheers!
 
Ok, roughly 20 feet and definitely two walls away, the BT UNO automatically reconnected and BrewPi is pinging away. The BT/Serial module is still inside a plastic case as well.

I wiped the log so if anything burps overnight it'll stand out...

Cheers!
 
A couple of the reviewers for the module you linked stated that it ran fine at 5 volts. Is the voltage divider necessary or does it serve another purpose?
 
The baseboard that the actual BT/serial MCM is soldered to has a linear regulator that steps down the 5VDC at the header to the 3.3VDC used by the MCM (multi-chip-module).

- The I/O pins are not rated for operation beyond 3.6VDC.
- If you go beyond that, you're on your own.

And, let me be as frank as any old fart who has been designing exotic digital equipment since 1973 and has been enjoying the brew-related fruits of his labors this evening:

- If you break a receiver to save the cost of a pair of resistors, you're a *******.

So, there's that...

Cheers! ;)
 
Ha.

Don't worry, just asking. I wasn't able to pull up a data sheet or anything on this board to see if it had the necessary on board protection.
 
Great that you got it working! And that you took the time to write this guide.

But.. aren't your resistors swapped?
If you want to go from 5V to 3.3V, the 2k resistor should be connected to GND.
 
Apparently santa, is bring some toys to get this project on the way. Fantastic work again day trippr. Subscribed

ED: Pity this didn't take off, would have been nice to add SG to the pi and of course no more need for thermowells. Then again is that the next hack?
when will the chase for better toys end!?!
 
Great that you got it working! And that you took the time to write this guide.

But.. aren't your resistors swapped?
If you want to go from 5V to 3.3V, the 2k resistor should be connected to GND.

DOH! &^%$#@!

Good catch, and thanks for pointing that out.
I've corrected the two diagrams...

Cheers! :mug:
 
So we're coming up on a full day with a BT UNO two walls and roughly 20 feet from the RPi's BT dongle running a script. Log file is totally clean, zero hiccups.

That's two walls and about 6 feet further than I need to work, so I'm going to go ahead and build a pair of controllers around these for my two fridges...

Cheers!
 
fwiw, these BT/serial modules are proving to be robust li'l dudes.
The first one has been running for a week or so and the second for a few days and neither one has so much as burped in that time.

Picked up project boxes, Leviton duplex outlets and some dpdt switches to build two BrewPi "satellites".
Business-wise I got all of my designs (totally unrelated to anything "beer") out in time for the first-builds to make their respective appearances at CES so I should have some time to play this week (and catch up on sleep :drunk:)

Cheers!
 
What kind of project boxes, plastic? You figure they'll work through metal enclosures?
 
Plastic, definitely. Specifically, these cheap Philmore boxes that are available locally.
I used one of them for the dual-stage Love TSS2 controller that's currently running my fermentation fridge.
That will be relegated to emergency backup status soon.

The BrewPi BT "satellite" that's been running 2 walls + 20' away has been inside an orphaned RPi plastic box all this time and had no problem with that.
I would't expect it to work as well inside a metal enclosure...

Cheers!
 
Curiosity got the better of me so I tried reprogramming one of the BT Unos with the BrewPi revC hex file over the Bluetooth link.
And it totally worked - restored all the settings and automagically restarted the running script perfectly.

I'll add this as a postscript to the "How To"...

Cheers!
 
Tada! The first of two (at least) BrewPi "Bluetooth Satellite" units (the second is mostly done, just waiting on a relay module). At 7 x 4 x 2 inches, with the 9V wall wart things got tight towards the end, but I got everything squished in there.

I'll let this run in my office for a few days but given how steady it's run so far "out of the box" I don't foresee anything that'll preclude it from running my ferm fridge while talking to the RPi under my keezer.

Might eventually upgrade these with the 16x4 LCD, depends on whether I'll miss having a direct reading display ala the Love controller currently running my ferm fridge...

Cheers!

brewpi_satellite_01.jpg


brewpi_satellite_02.jpg


brewpi_satellite_03.jpg
 
Now that is one sexy set up, great work! Will Pints be going Blue tooth as well?
 
Now that is one sexy set up, great work! Will Pints be going Blue tooth as well?

Thanks! Things got a bit dicey when I realized half-way into the build that my placement drawings had left out the wall wart.
Had to redrill the mount points for the two modules but luckily had just enough room to squeeze everything in without having to chop up the wart's plastic shell.

Raspberry Pints runs on the RPi that's under my keezer, managing the tap list, flow meters, etc, along with running the temperature logger and motion detector and other random stuff.
That system also has a wired BrewPi Uno instance that controls the keezer compressor.

These BT Uno satellites will sit atop and control my two brewery fridges (roughly 8 and 11 feet away from the keezer) and communicate back to the same RPi, giving me network visibility into the status and control of those two units, something I've wanted for awhile.

The issue has been that connection: the two fridges are on the opposite side of an aisle, so stringing wires would be a pita (leaving aside the fact that USB wasn't going to work over that distance anyway).
Wireless was the way to go, but it had to be totally transparent to avoid having to modify the BrewPi AVR code.

Afaik, this is the only solution that meets all the requirements, and does it in a rather painless fashion :)

Cheers!
 
Good looking box. How did you connect to that wall wart?

The shell comes apart with one screw and a bit of futzing about.

Once opened I removed the stock line cord and soldered in a short run terminating in insulated couplers that plug into mating ends from the AC distribution.
That was all about removing bulk - it's pretty tight inside that box :)

Cheers!
 
Both satellites up and running - and for grins I wired up another Uno with a BT/serial module and have that running as well.

So you can run at least three of these through a single Bluetooth host dongle.
That could come in handy down the road...

Cheers - and Happy Holidays! :mug:
 
fwiw, I finally got an HC-06 (a slave-only version BT/serial module) working on BrewPi. The HC-06 is typically a couple of dollars cheaper than the master-slave capable HC-05.

As the HC-06 is a slave-only device its serial port is always in "maintenance mode" unless the BT side is connected to a master device. Hence it doesn't use the Key function at all - it basically just listens for AT commands on the serial side. So it's a slightly different wiring scheme for the programming, and a totally different sketch.

I've updated the kit on my Google Drive with added instructions and wiring diagrams for the HC-06...

Cheers!
 
Thank you very much for that, i ordered my bluetooth-serial module from dx.com, it seems to be exactly the same that you used (HC-05). They also have the right CSR 4.0 USB bluetooth stick. Taht makes only 12$ for both modules incl shipping.

http://www.dx.com/p/hc-05-wireless-bluetooth-serial-pass-through-module-w-backboard-green-blue-298911#.VLVJVXs6yW4

http://www.dx.com/p/ultra-mini-bluetooth-csr-4-0-usb-dongle-adapter-black-143276#.VLVJV3s6yW4


I configured my Raspberry PI with command line only because i dont have a GUI. I used this tutorial to make the bluetooth connection:

http://www.heatxsink.com/entry/how-to-pair-a-bluetooth-device-from-command-line-on-linux

To change the PIN of the HC-05 module i used the AT command:

"AT+PSWD=1234"


Works perfectly!
 
I just got one of these HC-05 modules in the mail and have been playing around with it. I found that the speed for AT command mode was 9600 baud.

Also, to get the module to go into command mode I found that I had to have the arduino powered up but vcc disconnected from the hc-05, after the arduino sketch initialized I could then connect vcc on the module and it would successfully enter command mode.

I should note that I used this module off of ebay because the seller linked in the OP didn't have it in stock at the time.
 
I've had the same thing happen, and good for you for figuring out how to get around it :)

There are two ways to enter command/AT Mode on the HC-05: Key Before Power-On, and Key After Power-On. The former will cause the HC-05 uart to always communicate at 9600 baud, the latter has the HC-05 communicate at whatever baud rate was programmed into it.

I have three HC-05s and the third one arrived already programmed to use 57.6K baud for normal operations. The other two were set for 9600 baud. There's probably something to be said to simply go for the Key Before Power-On mode as it should always end up at a known baud rate (9600)...

Cheers! :mug:
 
I just tried for 5+ hours to get the bluetooth autoconntect running on my raspberry pi.

On my test notebook with Debian Wheezy everything worked flawlessly.

But on my RPi the brewpi script always failed with:

Code:
serial.serialutil.SerialException: write failed: [Errno 107] Transport endpoint is not connected

I could connect manually but it did not connect at boot or if the HC-05 somehow lost connection from a reboot.

After a good night sleep and some google searches i found that the problem lies in the Linux kernel 3.12.6 to 3.14.4

So after a simple

Code:
sudo rpi-update

the Kernel was updated to 3.18.3 and everything works!
 
Curiosity got the better of me so I tried reprogramming one of the BT Unos with the BrewPi revC hex file over the Bluetooth link.
And it totally worked - restored all the settings and automagically restarted the running script perfectly.

I'll add this as a postscript to the "How To"...

Cheers!

Are you sure that this actually worked? It was my understanding that the arduino needs to be reset at the right moment to accept a new sketch (DTR pin I think), and the uno takes new sketches at 115200 baud but the BT module is only at 57600 baud. I suspect that if you were to put another sketch on there with a usb cable, like blink for example, then tried to reprogram it again using the BT module and the brewpi scripts that you'd find it didn't work.
 
A curious comment and supposition, in light of everything I've done with these things over the last year...

Cheers!

Don't get me wrong, I have no doubt you know much more about these things than I do. But I'd encourage you to double check. If I hit the upload button in the brewpi script and watch the output closely it'll say something along the lines of couldn't upload and out of sink, the messages just keep scrolling by and the script continues as if it worked. If the arduino already had the brewpi uploaded it could trick one into thinking it worked, but it only just restarted. YMMV
 
Damnit day-trippr, you're always making me spend money on this cool stuff. Lol:) I just ordered the parts last night. Patiently waiting on the mailman now. Has anyone else attempted this on an old PC running Debian/Brewpi? Or shall I be the test subject? I'm using a very old dell laptop for my Brewpi setup that already has Bluetooth capabilities so I'm hoping that the instructions will work just the same with just the omission of the extra dongle that would normally plug into the pi.

By the way, My plan is to copy your "Bluetooth satellite" box because I really like the way it's set up, but with the exception of the LCD screen. For my situation and location of where the box will live, the screen wouldn't do me much good...

....eh, who am I kidding, it will probably someday get that upgrade too. Lol. When the parts arrive I'll post my results. Thanks again!
 
Waiting on the rj-12s and some Dallas probes. This ones going in my kegerator on the other end of the house. I may have to extend the BT antennae somehow. But this should house all the components to monitor and control the whole thing on one board with a header to header connection for the relay. I got these awesome little 2" through hole pcbs. I may build a tiny brewpi in the future stacking them up to add an lcd and encoder.
 
For my brewpi I made a raspberrypi 'shield' with an arduino pro mini mounted on a small pcb, and the pcb mounted on the gpio header. It really is a space saver, much cheaper too. Putting together stackable modules for LCD and extra bits and pieces is a good idea.
 
Back
Top