Remote GPIO Control with Bluetooth

Introduction to Raspberry Pi 4 Wireless Communication in the Raspberry Pi 4
7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€67.09
List Price:  €95.85
You save:  €28.75
£55.67
List Price:  £79.54
You save:  £23.86
CA$100.61
List Price:  CA$143.73
You save:  CA$43.12
A$111.94
List Price:  A$159.93
You save:  A$47.98
S$94.87
List Price:  S$135.54
You save:  S$40.66
HK$544.46
List Price:  HK$777.83
You save:  HK$233.37
CHF 62.54
List Price:  CHF 89.34
You save:  CHF 26.80
NOK kr792.28
List Price:  NOK kr1,131.88
You save:  NOK kr339.60
DKK kr500.54
List Price:  DKK kr715.08
You save:  DKK kr214.54
NZ$123.72
List Price:  NZ$176.75
You save:  NZ$53.03
د.إ257.07
List Price:  د.إ367.26
You save:  د.إ110.19
৳8,361.37
List Price:  ৳11,945.33
You save:  ৳3,583.95
₹5,945.38
List Price:  ₹8,493.77
You save:  ₹2,548.38
RM315.51
List Price:  RM450.75
You save:  RM135.24
₦108,452.30
List Price:  ₦154,938.50
You save:  ₦46,486.20
₨19,476.23
List Price:  ₨27,824.38
You save:  ₨8,348.15
฿2,393.75
List Price:  ฿3,419.79
You save:  ฿1,026.04
₺2,463.20
List Price:  ₺3,519.01
You save:  ₺1,055.81
B$425.95
List Price:  B$608.53
You save:  B$182.58
R1,281.50
List Price:  R1,830.80
You save:  R549.29
Лв131.12
List Price:  Лв187.32
You save:  Лв56.20
₩101,234.93
List Price:  ₩144,627.53
You save:  ₩43,392.60
₪255.76
List Price:  ₪365.39
You save:  ₪109.63
₱4,117.86
List Price:  ₱5,882.91
You save:  ₱1,765.05
¥10,950.28
List Price:  ¥15,643.93
You save:  ¥4,693.65
MX$1,405.25
List Price:  MX$2,007.58
You save:  MX$602.33
QR255.07
List Price:  QR364.41
You save:  QR109.33
P967.09
List Price:  P1,381.63
You save:  P414.53
KSh9,046.20
List Price:  KSh12,923.70
You save:  KSh3,877.50
E£3,561.31
List Price:  E£5,087.81
You save:  E£1,526.49
ብር8,934.81
List Price:  ብር12,764.56
You save:  ብር3,829.75
Kz64,250.82
List Price:  Kz91,790.82
You save:  Kz27,540
CLP$69,230.60
List Price:  CLP$98,905.10
You save:  CLP$29,674.50
CN¥510.67
List Price:  CN¥729.56
You save:  CN¥218.89
RD$4,260.81
List Price:  RD$6,087.13
You save:  RD$1,826.32
DA9,439.27
List Price:  DA13,485.25
You save:  DA4,045.98
FJ$162.13
List Price:  FJ$231.62
You save:  FJ$69.49
Q539.13
List Price:  Q770.23
You save:  Q231.09
GY$14,638.94
List Price:  GY$20,913.67
You save:  GY$6,274.72
ISK kr9,737.70
List Price:  ISK kr13,911.60
You save:  ISK kr4,173.90
DH704.21
List Price:  DH1,006.07
You save:  DH301.85
L1,285.64
List Price:  L1,836.70
You save:  L551.06
ден4,129.86
List Price:  ден5,900.06
You save:  ден1,770.19
MOP$560.15
List Price:  MOP$800.26
You save:  MOP$240.10
N$1,288.20
List Price:  N$1,840.36
You save:  N$552.16
C$2,574.79
List Price:  C$3,678.42
You save:  C$1,103.63
रु9,517.84
List Price:  रु13,597.49
You save:  रु4,079.65
S/260.55
List Price:  S/372.23
You save:  S/111.68
K283.74
List Price:  K405.36
You save:  K121.62
SAR262.92
List Price:  SAR375.62
You save:  SAR112.69
ZK1,936.44
List Price:  ZK2,766.46
You save:  ZK830.02
L333.95
List Price:  L477.10
You save:  L143.14
Kč1,686.22
List Price:  Kč2,408.98
You save:  Kč722.76
Ft27,781.13
List Price:  Ft39,689.03
You save:  Ft11,907.90
SEK kr772.16
List Price:  SEK kr1,103.13
You save:  SEK kr330.97
ARS$71,509.21
List Price:  ARS$102,160.40
You save:  ARS$30,651.18
Bs483.51
List Price:  Bs690.76
You save:  Bs207.25
COP$305,137.08
List Price:  COP$435,928.80
You save:  COP$130,791.72
₡35,302.85
List Price:  ₡50,434.81
You save:  ₡15,131.95
L1,776.18
List Price:  L2,537.51
You save:  L761.33
₲545,595.73
List Price:  ₲779,455.88
You save:  ₲233,860.15
$U3,131.93
List Price:  $U4,474.38
You save:  $U1,342.44
zł286.05
List Price:  zł408.66
You save:  zł122.61
Already have an account? Log In

Transcript

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.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.