Hello everyone,
I am still waiting for my Bluetooth devices. However, I decided that I should test the Bluetooth adapter on the BeagleBone Black Wireless in case the adapter was defective. I did not want to wait too long if I had to replace the BeagleBone Black. I used a HC-06 Bluetooth device, from a previous robotics project, to communicate with the BeagleBone Black Bluetooth adapter. The HC-06 was attached to an Arduino Uno.
I ran into one problem. I had to fix an SAP driver error that occurred while checking the Bluetooth service status (Section I). I decided to use Python to access the Bluetooth adapter on the BeagleBone Black. Therefore, I installed the PyBluez libraries.
I wrote a “Hello World” Python program on the BeagleBone Black to send a message, via Bluetooth, to the Arduino Uno. I wrote an Arduino sketch to receive and display the message sent by the BeagleBone Black. Running the programs verified that the Bluetooth adapter on the BeagleBone Black was functioning properly.
I forgot to discuss securing the Root user last week. So, I added the discussion in the Security section.
I wrote a tutorial for each task I completed. If you are interested in the details you can view the following sections below. The sections are:
Section I – Pair the BeagleBone Black Bluetooth Adapter to the HC-06
Section II - Install the PyBluez Development Libraries
Section III – Create the Bluetooth Application Software
Section IV – Connect the HC-06 to the Arduino
Section V – Test the Bluetooth Connection
Section VI - Security
This week I will take inventory to see what remaining items I need to order. Since I did not do it last week, I will design the main module for the controller program.
Talk to you soon.
Quote of the Moment -
It’s not broke. It just doesn’t work.
-- My 15-year-old granddaughter.
Section I - Pair the BeagleBone Black Bluetooth adapter to the HC-06
First, we need to check to see if the Bluetooth service is running.
Run “sudo service bluetooth status” (Figure 1).
You should see: Active: active (running) If you see: Active: inactive (dead)
Run “sudo service bluetooth start”
Then run “sudo service bluetooth status” again.
Figure 1.
Note that I received the following error when displaying the Bluetooth status:
beaglebone bluetoothd[2604]: Sap driver initialization failed.
beaglebone bluetoothd[2604]: sap-server: Operation not permi...)
To get rid of the error we need to edit the /etc/systemd/system/bluetooth.target.wants/bluetooth.service file. The example in Figure 2 uses nano since it is easy to use. By the way my favorite editor is vi. It is a more powerful editor than nano. However, vi has a steep learning curve. Hence, nano is my editor of choice for displaying examples.
- Run “sudo nano /etc/systemd/system/bluetooth.target.wants/bluetooth.service” (Figure 2).
- Change the line : ExecStart=/usr/lib/bluetooth/bluetoothd to: ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=sap
- Enter Ctrl-O to save the file. When the file name is displayed press the Enter key.
- Then enter Ctrl-X to exit nano
- Run “
sudo systemctl daemon-reload
” to reload systemd.
- Run “sudo service bluetooth restart” to restart the Bluetooth service.
- Run “sudo service bluetooth status”. Note that the error message is gone (Figure 3).
Figure 2.
Figure 3.
- Run “bluetoothctl” (Figure 4).
- To ensure the Bluetooth device is powered on. Enter “power on”.
- Enter “devices” to see available Bluetooth devices that the BeagleBone knows exist.
- If the target device is not displayed enter “scan on”. Any nearby Bluetooth devices will be displayed.
- Note the MAC address of the device to pair to. In this example, we will pair to the HC-06 Bluetooth device.
- We need to turn on the agent so that we can enter the PIN code when requested. Enter “agent on”.
- We can now pair the devices. Enter “pair 20:16:12:12:58:43”
- Enter “1234” to the prompt: [agent] Enter PIN code:
- The following messages are displayed:
- [CHG] Device 20:16:12:12:58:43 Paired: yes
- Pairing successful
- The following messages are displayed:
- Enter “exit” to terminate the bluetoothctl utility.
Figure 4.
Figure 5.
- Connect a jumper wire from the receive pin on the HC-06 to the transmit pin on the Arduino (pin 2).
- Connect a jumper wire from the transmit pin on the HC-06 to the receive pin on the Arduino (pin 4).
- Connect a jumper wire from the ground pin on the HC-06 to the ground pin on the Arduino.
- Connect a jumper wire from the VCC pin on the HC-06 to the 5-volt pin on the Arduino.
Figure 12.
Figure 13.
Figure 18.
- Run “nano /etc/ssh/sshd_config”
- Press Ctrl-W
- Enter PermitRootLogin and then press the Enter key to perform the search.
- Change yes to no (Figure 20).
- Enter Ctrl-O to save the file. When the file name is displayed press the Enter key.
- Then enter Ctrl-X to exit nano.
- The change will not take effect until you restart the SSH server.
- Run “/etc/init.d/ssh restart” (Figure 21).
Figure 19.
Figure 20.
Figure 21.
Top Comments