satish.gunjal
Posts: 42
Joined: Sat May 23, 2015 11:50 am

BluetoothError: error accessing bluetooth device

Tue Jun 09, 2015 1:48 pm

I am using HC-05 bluetooth module. Want to enable two way communication with my android phone. But unable to go pass the device inquiry step... Please help me to make it work....

Python script:

from bluetooth import *

print("performing inquiry...")

nearby_devices = discover_devices()

print("found %d devices" % len(nearby_devices))

for addr, name in nearby_devices:
try:
print(" %s - %s" % (addr, name))
except UnicodeEncodeError:
print(" %s - %s" % (addr, name.encode('utf-8', 'replace')))


Above python script returns error:

Traceback (most recent call last):
File "pi_bt_inquiry.py", line 12, in <module>
nearby_devices = discover_devices()
File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 17, in discover_devic es
sock = _gethcisock ()
File "/usr/lib/python2.7/dist-packages/bluetooth/bluez.py", line 226, in _gethcisock
raise BluetoothError ("error accessing bluetooth device")
bluetooth.btcommon.BluetoothError: error accessing bluetooth device

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: BluetoothError: error accessing bluetooth device

Tue Jun 09, 2015 3:06 pm

The HC-05 will appear to the Pi as a serial device, not Bluetooth. You don't need any Bluetooth software on the Pi. Instead, use pyserial to open the serial device at /dev/ttyAMA0. Remember to disable the serial console tty first, using raspi-config. Then pair from the phone with PIN '1234'.

satish.gunjal
Posts: 42
Joined: Sat May 23, 2015 11:50 am

Re: BluetoothError: error accessing bluetooth device

Wed Jun 10, 2015 9:58 am

Thanks Douglas6 ...

Using pyserial i am able to send data from my RP to BlueTerm app on Android phone. But not able receive data in RP.
If possible can you please share some sample script please.

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: BluetoothError: error accessing bluetooth device

Wed Jun 10, 2015 12:02 pm

Read the pyserial documentation and google for example code.

bostonpatriot
Posts: 5
Joined: Tue Jun 02, 2015 3:49 pm

Re: BluetoothError: error accessing bluetooth device

Sat Jun 20, 2015 12:38 pm

Douglas6 wrote:The HC-05 will appear to the Pi as a serial device, not Bluetooth. You don't need any Bluetooth software on the Pi. Instead, use pyserial to open the serial device at /dev/ttyAMA0. Remember to disable the serial console tty first, using raspi-config. Then pair from the phone with PIN '1234'.
Hello! Reading this post with interest. I have a Raspberry Pi Model B(2 USB ports). I am attempting to communicate serially with a Basic Stamp II. Have installed Pyserial and raspi-config and also have the newest Adafruit console cable. My questions are:

1) Connections. Do I connect the console cable to the Pi and the Stamp to the Pi's USB via the USB-RS232 adapter?
2) How do I figure out which serial ports would be active for purposes of configuring the appropriate Pyserial entries?

I was able to identify and configure Pyserial using my Windows 7 machine because the COM ports are easy to identify.

Any guidance would be appreciated.

User avatar
Douglas6
Posts: 4853
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: BluetoothError: error accessing bluetooth device

Sat Jun 20, 2015 3:16 pm

You might want to start a new thread; there's little in common between an HC-05 and that console cable. But I would proceed with caution. The Pi, and the console cable, operate at 3v3, the Stamp (as far as I can tell) at 5v. May not work and could cause damage, without level shifting. The cable (if it works) would appear on the Pi as /dev/USB0.

Return to “Python”