Radio remote GPIO control over Bluetooth. In this video, we are going to learn how to control the GPIO pins of the Raspberry Pi for wirelessly using Bluetooth from an Android smartphone. And later, you will be given an activity to build a remote control robot using the blue dot library. We're going to use a nifty Bluetooth library called blue.to establish remote control between the Raspberry Pi and the smartphone. This library also provides functions to control one Raspberry Pi from another Raspberry Pi. The blue dot library uses a client server model to establish communication.
The blue dot class inside the library creates a Bluetooth server on the server device that is the Raspberry Pi. And the blue dot application installed on the client device will connect to this server via Bluetooth communication, the transmission of data from client to server or server to the client is a simple stream of data. No acknowledgments or data is sent in response to commands when using the blue dot library. Now, let's install the blue dot library. Open the terminal and first type sudo apt install Python three hyphen D bus debug module is a prerequisite for working with the blue dot library. This library provides an abstraction layer for the blue dot library to do inter process communication for the Bluetooth interface.
Now, enter the following to install blue dot sudo PIP three install blue.if your Raspbian OS version already has blue.it is always a good thing to check for any updates in upgraded using the following command. sudo PIP three install blue dot, hyphen hyphen upgrade. The next step is to pair your Raspberry Pi to the Android phone. Go to Android devices settings and inside the Bluetooth configuration menu, make your device discoverable and then enable the Bluetooth. Now go to your Raspberry Pi desktop and click the Bluetooth icon and select make discoverable. Then click Add Device.
Your phone will appear in the list selected and enter a PIN code for pairing. Now on the Android phone, enter the same PIN code when prompted and touch okay. You have now successfully paired your phone with a pi. Now go to the Play Store in your Android phone and search for the Bluetooth app. Install the one made by Martin and open the app. It will ask for permission to use Toad, please accept it.
Now you can see our pie is on the list of connected devices selected, and you can see a blue dot, the blue.is, a joystick, as well as a button. You can tell if the dot was pressed in the middle, on the top, bottom, left or right, the app can send the information of the exact relative position of touch within the.to your PI via Bluetooth. We are going to leverage this incoming data to implement wireless projects using the Raspberry Pi. First, let's control an LED using Bluetooth. wire up a red LED on the breadboard with a current limiting resistor and connect it to the GPIO pin 17 as we did in the last section. Now, in a Tony ID open the bluetooth.py file from the repository and run the code now on your blue dot app.
If you press the blue dot, the LED will become on, it will be on till you release the blue.in the app. In the code, we have imported the blue dot class from the blue dot module with the first command. This class consists of all the methods also known as API's that allow us to establish and communicate with the client device, I highly recommend you to go through the API documentation to know about all the API's offered by the blue dot library. The link is provided in the resources section. As we are working with the LED on the GPIO pin 17 we need to import the LED class from the GPIO zero library. By using the following line of code.
We cannot directly access the methods of a class. We need to create instances of both classes and assign them to variables which can later be used to access the map. Add. An object named BD is created as an instance of the blue dot class with no arguments. This means that the Bluetooth communication will be established with the default configuration. Check out the class definition of blue.in.
The API documentation to learn to do custom Bluetooth configuration, we have created an object with the LED class by defining the GPIO pin as 17, which is where the red LED is connected to. Then an infinite loop is created inside which we use the weight underscore four underscore press method and the weight underscore four underscore release method to sense the button presses wirelessly and take appropriate action. Here, the action is to make the LED on or off. These methods have conditional branching implemented inside themselves. Does The user doesn't have to create an if else statement. But if you want more control over what is happening internally, you will need to learn and implement these methods from the API documentation.
Now, I want you to build a two wheel drive remote controlled robot using the robot and the blue dot library. You will need to wire up two motors to the motor driver module and control the robot. Based on the relative position of touch detected in the blue.on. The Android app, I will give you a clue. You need to use the methods in the builder position API to detect the position of the touch. If you go through the documentation, you can see that they have even methods to detect top press bottom press, left press and right press on the blue dot app.
I think I have given too much away. Anyways, try to implement this mount your project on the chassis, and test out your remote control car. I have provided the complete working code in the resources section if you're stuck with this activity summary In this video, we have covered the following topics, setting up the PI with the blue dot library, implementing GPIO control over Bluetooth remote control robot project. In the next video, we will learn to control the GPIO of the Pi over the internet.