How to do it...

With the Bluetooth module configured and connected, we can pair the module with a laptop or smartphone to send and receive commands wirelessly. Bluetooth spp pro provides an easy way to use a serial connection over Bluetooth to control or monitor Raspberry Pi for Android devices.

Alternatively, you may be able to set up a Bluetooth COM port on your PC/laptop and use it in the same way as the previous wired example:

  1. When the device is connected initially, the LED flashes quickly to indicate that it is waiting to be paired. Enable Bluetooth on your device and select the HC-05 device:
The HC-05 Bluetooth module viewable in Bluetooth spp pro
  1. Click on the Pair button to begin the pairing process and enter the device's PIN (the default is 1234):
Pair the Bluetooth device with the PIN code (1234)
  1. If the pairing was successful, you will be able to connect with the device and send and receive messages to and from Raspberry Pi:
Connect to the device and select the control method
  1. In Keyboard mode, you can define actions for each of the buttons to send suitable commands when pressed.

For example, Pin12 ON can be set to send gpio 12 on and Pin12 OFF can be set to send gpio 12 off.

  1. Ensure that you set the end flag to rn via the menu options.
  2. Ensure that menuSerial.py is set to use the GPIO serial connection:
serName="/dev/ttyAMA0"  
  1. Run the menuSerial.py script (with the LEDs attached):
sudo python3 menuSerial.py
  1. Check that the Bluetooth serial app displays the GPIO Serial Control menu as shown in the following screenshot:
GPIO control over Bluetooth

We can see from the output in the following screenshot that the commands have been received and the LED connected to pin 12 has been switched on and off as required:

Raspberry Pi receiving GPIO control over Bluetooth
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.78.83