the code is working in python 2.7. l didn't understand why its not working in python 3.5
I installed the above setup too, but still didn't work with python3.5
J'ai eu le même problème la solution c'est qu'il faut installer 2 fois : sur python et python 3:
$ sudo apt-get install python-dev libbluetooth-dev
$ git clone https://github.com/karulis/pybluez.git
$ cd pybluez
$ sudo python setup.py install
$ sudo python3 setup.py install
1 of 1 people found this helpful
You need to install the bluetooth software onto the raspberry pi before you can use it. Open a terminal and enter the commands shown in this github repo https://gist.github.com/lexruee/fa2e55aab4380cf266fb
one of them is sudo apt-get install bluetooth which would make sense
I tried that
sudo apt-get install bluetooth, but that too didn't work,
it took bluetooth as pybluez and installed its relavant files
If you haven't found a solution by tomoro afternoon, I'll try and replicate the situation when I get back home and see if I can find a solution. I'm away right now and don't have my Pi with me
Here's something that might help understand why its not working, any Python modules that I download go into /usr/lib/python2.7/dist-packages There is also a folder at usr/lib/python3/ presumably any modules that you are going to import into a python3 script would have to go into the python3/dist-packages folder, it might be worth checking into this, if there is nothing in your python3/dist-packages folder that relates to bluetooth then thats probably causing the issues.
from here https://docs.python.org/3/installing/ to import specifically for python3.4 do:
python3.4 -m pip install SomePackage
2 of 2 people found this helpful
Hope fully this is the last post and solution
after following the steps in the link I posted above I did the following
sudo python3.4 -m pip install pybluez
this succesfully allowed me to import the bluetooth package in python 3.4, for python3.5 try:
sudo python3.5 -m pip install pybluez
don't forget to do it as root (with sudo). If this fails to work I can only assume that pybluez hasn't been ported over to python3.5 and you are out of luck
Hello World !
I wonder if this project is always in progress... But if it is, I have some informations for you, maybe.
In fact, Python 3.5 or above no longer accept pybluez module directly.
By now, Python3 calls BlueTooth as Socket with "Command Type", "Socket Type" and "Protocol Type" parameters, so in your case, this is a typical script :
#!/usr/bin/env python3 # Only if OS is not Microsoft © Windows
import socket # Socket module is used for network and bluetooth in Python3.5 and above
MACAdrBluetoothModule = 'XX:XX:XX:XX:XX:XX' # MAC Adress of the Bluetooth sender, not the RaspBerry Pi
BluetoothChannel = 1 # Indicate the appropriate transmission channel (generally 1 for a serial bluetooth module as HC-05)
SizeOfDataInBytes = 2 # Indicate the appropriate number of bytes you want to receive
# Function created for data read
def lecture_serie(MACAdrBluetoothModule, BluetoothChannel, SizeOfDataInBytes):
Connection = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
ReceivedData = Connection.recv(SizeOfDataInBytes)
ReceivedData = str(ReceivedData.decode('utf-8')) # To translate data to a correct string UTF-8 data
ReceivedData = "ERR"
So, every times you want to read the bluetooth serial data, you just use this function and it returns the received data by the RaspBerry Pi.
For example :
print(lecture_serie(01:23:45:67:89:AB, 1, 1024))
It will return 1024 bytes from the serial Bluetooth module where its MAC adress is 01:23:45:67:89:AB and its channel is 1.
So, good luck for your project,
Bye ! Best regards.
everyone, I am a new bee to raspberry pi. I am working on a project with arduino + HC-05 and raspberry pi 3
I have wrote a code to arduino to send temperature data to pi over bluetooth, and python code to receive the data. The python code throws error could not import bluetooth. Please can someone help me to rectify this...
Message was edited by: Naveen chand m