Download as pdf
Download as pdf
You are on page 1of 31
Robot Pro Sophia is the world's first robot citizen and the first robot Innovation Ambassador for the United Nations Development Programme. Sophia was created to help people in real uses like medicine and education, and to serve Al research. Her very existence provokes pu! ic discussion regarding Al ethics and the role humans play in society, especially when, 4 human-like robots become ubiquitous 20 Key Features Expression * Integrated set g¥ emotional émgn-sized appearance expressions st realistic human-like expressive face + Sentence and contexmefiderstanding Patented artificial skin with cloud connection + Customized skin tone, facial design, * Mouth, face and whole body motion language and arm colors available synchronized with speech output Sensors Motion + Face detection and body tracking + 74 degrees of freedom + Can be programmed for wide range of + Articulated fingers, arms and shoulders physical interaction tasks * Three different rolling base options including self- navigating * 600 gr. payload for eggteRand Programming Robots & Single Board Computer Student Learning Outcomes After going through this chapter, students will be able to: 1. Understand what single board computers is Understand what Raspberry Pi, Raspbian OS and its components Understand the components of Raspberry Pi Understand the basics of Python Programming Language Create an electric circuit using jumper wires, breadboard, resistor & LED Understand what SONAR and Servo motor Create and code a program for interacting with SONAR Create and code a program for interacting with Servo Motor ~POENANAWH Build a smart robotic car ISTE Student Standard Coverage ae Cre ueTy fer Rives cP) Loa) 5.1. Single-Board Computers A single-board computer (SBC) is a complete computer built on a single circuit board, with microprocessor(s), memory, input/output (I/O), and other features required of a functional computer. Single board computers were made as demonstration or development systems, for educational systems, or as embedded computer controllers. Many types of home computers or portable computers integrate all their functions ‘onto a single printed circuit board. Unlike a desktop personal computer, single board computers often do not rely on ‘expansion slots for peripheral functions or expansion, Single board computers have been built using a wide range of microprocessors. Simple designs, such as those built by computer hobbyists, often use static RAM and low-cost 8- or 16-bit processors. Other types, such as blade servers, would perform similar to a server computer, only in a more compact format. 5.2. Introduction to Raspberry Pi The Raspberry Pi, which is a single board computer (S&C), is a small credit card sized computing device that can be used for a variety of purposes that include but not limited to: experimentation learning how to program, building a media player or NAS drive, robotics home automation performing computing tasks such as web browsing or word processing. SBCs are also increasingly used for a wide range of industrial applications in areas that include robotics and the Internet of things (IoT). Ely e lors gle-Board Computers C] 2 fe) Q ° a D & IE = 5 Ie a ° 2 iy Oe Besides having all the essential components of a traditional computer Raspberry Pi has one special feature that normal computers don't: General Purpose Input Output (GPIO) Pins. Thus, allowing you to connect with the real world. VA ed Components of Raspberry Pi GPIOS: to connect devices to real world, for instance, sensors, LEDs, motors etc. USB Port: to connect a mouse, a keyboard, or other peripherals. Ethernet Port: to connect to the internet using an Ethernet cable. Audio Jack: to connect an audio device. CSI Connector: to connect a camera with a Camera Serial Interface ribbon. HDMI Connector: to connect a monitor or TV. Power Port: to power up your Pi. DSI Connector: to connect Display Serial Interface compatible display. Accessories Needed for Raspberry Pi When you buy a Raspberry Pi board, you only get a bare electronic board that doesn’t do much on its own. You need several accessories to get started. There are a lot of accessories for the Raspberry Pi, but you need at least a microSD card and a power supply. Without these accessories your Raspberry Pi is useless. ig Robots & Single-Board Computers (F Power Adapter: you'll need one that provides 25 amperes and 5 volts. ) Micro SD Card: you'll need one with at least 8GB storage, speed class 10 T You need a microSD card to store your files and the Pi’s operating system. F © The Pi doesn’t have hard drive, so everything you do on your Pi is saved on the microSD card, even the operating system. You can get a microSD card with the ‘operating system preloaded or install the operating system yourself. There are also useful accessories you may consider important such as an HDMI cable to connect an LCD. A spare mouse and keyboard can also be useful to set your Raspberry Pi as a desktop computer. She City Fehoel 2023-2024 5.3. Raspberry Pi Architecture The Raspberry Pi has an ARM Architecture based Processor. With a high-speed processor and 1 GB RAM, the PI can be used for many demanding projects like digital image processing and many loT and connected projects. The Raspberry Pi also consists of a set of pins that allow it to communicate with other nearby electronic devices. General purpose input-output (GPIO) A powerful feature of Raspberry Pi'is the set of GPIO pins along the top edge of the board. GPIO pins can simply be used to turn devices on and off. GPIO pins allow the Raspberry pi to be configured for different purposes, interact with different circuits, and work with several types of electronic components, for example, motors, LEDs, switches, etc. GPIO pins can simply be used to turn devices on and off. The image on the right provides an understanding of the pinout labelling, pare 00 — Raspberry Pi pins are labelled in two en 2 (508) 00 i er ways, ie. the GPIO pinout labelling and gacrann> rs —— Physical pin labelling. The physical pin Grain O° P1014 x0) crow Ce) crow pot a9 labelling is starting from 1 and ending cna ot mad oon or cron (on 40 in the image. en 38 a Ports eonees Oe ewe 700) rr) a + Raspberry Piis equipped with four erence eo cro ace cond oe orem USB 2.0 ports and one LAN Port. wooo ac yr) cao Teas! * USB ports allow USB devices to be eros oso) Ground PI06 ao 610 12 (Pwnta) connected together and transfer _— me data over a USB Cable. sw eCM. FS) Cry mow oon Od «02 04.009 + The LAN port allows the raspberry — pi to connect to a network using a wired connection Raspbian is a Debian-based (32 bit) computer operating system for Raspberry PI. There are several versions of Raspbian including Rospbian Buster and Raspbian Stretch. Since 2015 it has been officially provided by the Raspberry Pi Foundation as the primary operating system for the family of Raspberry Pi single-board computers. The operating system is still under active development. Raspbian is highly optimized for the Raspberry Pi line’s low-performance ARM CPUs. Raspbian uses PIXEL, Pi Improved X-Window Environment, Lightweight as its main desktop environment as of the latest update. The Raspbian distribution comes with a copy of the computer algebra program Mathematica and a version of Minecratt called Minecraft Pi as well as a lightweight version of Chromium os of the latest version. Mena to access tools, soware webbrowser WA) Wireens Terminal Bletocth 5.4. Python Basics Python is a high-level programming language designed to be easy to read and simple to implement. It is open- source, which means It Is free to use, even for commercial applications. Python can run on Mac, Windows, and UNIX systems. Running Python Using IDLE- The IDLE interpreter is a sort of “sandbox” where you can work with Python interactively without having to write whole scripts to see what they do. The name IDLE stands for Integrated Development Environment. You can find IDLE in the taskbar under the label of programming, Follow the steps to run your first program: 1. Click on the Raspberry Pi icon in the taskbar and then go to programming and hit Python 3 (IDLE). 2. Let's start with the first program that prints “Hello World” message on the screen. 3. Write print (“hello world”) on IDLE and hit enter. Running Python as a Script on IDLE A script or scripting language is a feature 4 of computer language with a series of Checkpoint commands within a file that is capable of being executed. Scripts are just the piece of code, in which the code is written in the form of scripts and get executed. Error checking is done when the code is executed or run. Ihe City Feheel 2023-2024 Follow the steps to run python as script on IDLE: 1. On Python IDLE click File>>New File. 2. In the resulting window type the following program and then save the file as testl.py in the default location. 3. Then press F5 to execute the program. }. The program output will be 15.. Sample code: # This program adds two numbers x= 10 yes # Add two numbers and store result in z zexty # Display the sum print(z) ing Robots & Single-Board Computers 5.5. Variables in Python A variable is the storage placeholder for text and numbers. It must have a name so that you can find it again. The variable is always assigned with an equality sign, followed by the value of the variable. Variables can store data that can be used elsewhere. They're one of the most powerful tools programmers can use. In python IDLE, enter the following statement: score=9 All this does is tell Python that you want to use score as a new name for the value 9. After this point, whenever Python sees score, it will insert the value 9. To demonstrate this, try entering the following: print (score). Remember that python executes instructions in order, and you must give score a value before you use it or you will get an error. Program| Sample code: # This defines a variable score and assigns a value to it score = 9 # Display the value stored in the variable print(score) Ihe €ity Teheel 2023-2024 This illustrates another great aspect of python and that is dynamic typing. This concept is defined with respect to the point at which the variable data types are checked. In our code, the variable is score which holds the value 9 which is a number, or we can label it as a data. A variable just stores the value, whereas the value could be of different data types. The data type defines the type of data that is stored in the variable. Being said that, dynamic type languages are those in which the data type checking is done at the run time. We don't have to declare the data type in our code in python. Python is smart enough to judge which data type is being held by the variable. Data Types in Python Values have types, every piece of data has to have a type associated with it so it knows what it is dealing with. Python sets the variable type based on the valve that is assigned to it. Following are the data types which will be used throughout in coding: Numbers: integers and float ‘String: any character or text Boolean: true or false 5.6. LIST in Python In Python, you can store your data into variables, but you can also put them in lists. A list is just an ordered collection of items which can be of any data type. Creating a list is as simple as putting different comma separated values between square brackets. Each element of a list is assigned a value by using an index. An example of list could be: newList=[10, 20, 30, ”Samsung”] To call or print a specific element of list, write the following code: Sample code: # This defines a List called newList newList=[10, 20, 30,”Samsung”] # Prints the third element in the List; starting from @ print(newList[3]) Eel Delete Elements in List Del command is used to delete a list element as mentioned in the example below: Sample code: # This defines a List called newList newList=[10, 20, 30,”’Samsung”] # Deletes the element at the index 1 del newList[1] # Prints the List after deleting an item print(newList) Output: [10, 3@, ‘Samsung? ] Add Elements in List To add an item to the end of the list, use the append) method. The code below demonstrates this: Sample code: # This defines a List called thislist thisLtst=[”apple”, banana”, *cherry”] # adds a new element at the end of the List thisList.append(“orange“) # Prints the List after deleting an item print(thisList) ” 2 g pd a = io) ce} se] 2 5 [o) ao x4 ro.) = 7) ] a 2 fe) 2 ° c Da = £ f= 5 me a ° i a Output: [ ‘apple’, ‘banana’, ‘cherry’, ‘orange? ] URE eed 5.7. Conditional Statements in Python Conditional statement is a set of rules performed if a certain condition is met. IF Statement if statement is a programming conditional statement that, if proved true, performs a function or displays information. An if statement in python is written by using the if keyword. The sample code below shows the if statement in python. Sample code: a= 33 b = 200 if b>a: print(“b is greater than a”) In this example, we use two variables, a and b, which are used as part of the iF statement to test whether b is greater than a. As a is 33, and b is 200, we know that 206 is greater than 33, and so we print to screen that *b is greater than a’. Indentation is necessary; if we do not use the indentation as mentioned in example, python will give an error. Elif Statement The elif keyword is Python's way of saying “if the previous conditions were not true, then try this condition”. The sample code below demonstrates Elif statement. Sample code: a= 33 b = 200 Checkpoint 4 ifboa: print(“b is greater than a”) elif b == a: print(“a and b are equal”) In this example a is equal to b, so the first condition is not true, but the elif condition is true, so we print to screen that “a and b are equal”. Else Statement The else keyword catches anything which isn’t caught by the preceding conditions. The sampe code below shows else statement. Sample code: # This program compares two numbers using else statements a= 33 b = 200 # tf block if b>az print(“b is greater than a”) # elif block elif b == a: print(“a and b are equal”) # else block else: print(“a is greater than b”) In this example a is greater than b, so the first condition is not true, also the elif condition is not true, so we go to the else condition and print to screen that “a is greater than b”.We con also use the else without using elif. 5.8. Conditional and Logical Operators Conditional operators refine the statement you're testing for. For instance, you can specify the statement whether it's greater than, less than, and a whole lot more. Creme ecm Equal too Greater than Less than More than or equal to Less than or equal to Not equal to o fe oy 2 J a = io) (w) bo} is 5 [o) a 2 f=.) = w o mn my ie) a2 Io) « D fs = 5 2 Da ° a VEAL eed Logical operators are similar to Boolean expressions that return a boolean result. These operators are called binary because they acquire two operands ecm) eo AND Both sides must be true OR One one the two conditions must be true XOR One side or other must be true but not both NOT Negates truth 5.9. Looping Statement in Python A For loop is used for repeating over a sequence (that is either a list or a string). This is less like the FOR keyword in other programming languages and works more like an iterator method as found in other object-orientated programming languages. For example, we have a list of students and we want to display the student with the highest marks without using the max() function: Sample code: # This defines a List of student marks stdMarks = [70, 80, 92.5, 60.2] # This variable keeps track of the max marks maxMarks = 0 # for Loop block for i in range(@,4): if stdMarks[i] > maxMarks: maxMarks = stdMarks[i] # Prints highest student marks print(“Highest student marks are:”, maxMarks) es 5.10. Python Functions In Python, a function is a group of related statements that perform a specific task. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable. Furthermore, it avoids repetition and makes code reusable. Function names cannot have spaces in between. instead of spaces use _ underscore to connect the words. In Python, a function is defined using the det keyword and for executing the function we can use the function name along with parentheses () The sample code below demonstrates how functions are used in python Sample code: def my function(): print(“Hello from a function”) my_function() Output: Programming Robots & Single-Board Computers 5.11. Getting Started with Python and Raspberry Pi One of the classic electronic analogy to “Hello World” is to make an LED blink. It is one of the very basic f tutorials to begin with. To get started, you first of all need to build the circuit on the breadboard; a board for electronic prototyping. Equipment needed Following componentes are required for this project: + 1 breadboard + 1LED + 2jumper wires + Tresistor: 2200/1KQ Ua ces ierd The circuitry of LED blink is pretty simple, you just have to connect the electronic component with raspberry pi properly as shown in the picture above. Connect resistor through jumper wire (represented in blackcolour) with PIN 6. Connect the positive leg of the LED with PIN 12 (GPIO 18). . After completing the circuitry, It’s time to move on to Raspberry Pi. . Turn on the Raspberry Pi On the desktop, go the start menu and click on python IDLE and enter the following code: vauwne # calling header file for GPIO’s of PI. ‘import RPi.GPIO as 10 # calling for time Library to use sleep command for delays in program import time # programming the GPIO by BCM 10.setmode (I0.BCM) # initialize digital pin as an output. IO. setup(i8,10.0UT) # turn the LED on (making the voltage Level HIGH) 10. output (18,1) # sleep for a second time. sleep(1) 10. output (18,0) time. sleep(1) 10. output(18,1) time. sleep(1) 10. output (18,0) time.sleep(1) 10.output (18,1) time. sleep(1) 10. output (18,0) time.sleep(1) LET ars BCM stands for Broadcom SOC channel. These pin numbers follow the lower-level numbering system defined by the Raspberry P's Broadcom System on Chip (SOC) brain. The above program will turn the LED on and off thrice with a one second delay, Resistor: The resistor is a passive device that controls or resists the flow of current to your device, for example if we don't use the resistor in the above experiment, the LED may allow too much current to flow which can damage both the LED and the Pi. Awecoe Bread Board: Breadboards are one of the most oo] 10000 fundamental pieces when learning how to build Ba 38 circuits. A breadboard is a construction base for 0° 330090) prototyping of electronics for temporary testing. Ba ss 8 8 3 a The following diagram shows how a breadboardis _|33| "22000 connected. rere 88] woooee Jumper Wire: A jump wire (also known as jumper 22] sooooe wire, or jumper) is an electrical wire, or group of them ina z igle-Board Computers eM atello ec} cable, with a connector or pin at each end (or sometimes without them - simply “tinned”), which is normally used to connect the components of a breadboard or other prototype cr test circuit. Jumper wires typically have a solid core which means they have 1 single strand of wire as opposed to the usual multiple thin strands used in electrical circuits. This makes them easy to bend into @ particular shape. Blinking LED Program In this program, the same components will be used which we have used earlier, but this program is a bit different than the previous one as we will use the while loop for continuous repetition of the program. Enter the following code in Python IDLE program using the raspberry Pi import RPi.GPIO os GPIO import time GPIO. setmode(GPIO.BCM) GPIO. setwarnings (False) GPIO. setup(18,GPIO.OUT) while True GPIO. output (18, True) time.sleep(0.5) GPIO. output (18, False) time. sLeep(0.5) Button Controlled LED In this program, the same components will be used which we have used earlier, except the button. in this program, we will control the blinking or turning on and off the LED using a button. Enter the following code in Python IDLE program using the raspberry Pi ‘import RPi.GPIO as gpio import time as t f gpio. setmode(gpio.BCM) gpio. setwarnings(False) gpio.setup(18, gpio.BCM) gpio.setup(23, gpio.OUuT) while True: ‘if gpio. input(18): gpio. output (23, True) t.sleep(1) else: gpio. output (23, False) In this program, we will understand the SONAR Sensor and its working. SONAR is an acronym of Sound Navigation & Ranging. It is used for measuring distance regardless of the shape colour and surface of the object. Hardware of this project is made simpler for your handling and does not require any soldering or messy wiring. We will use the Pi Shield on the top of the GPIO pins of Pi as a stack and connect the SONAR sensor on the Pi shield, But this time we will power the Pi via power adapter or battery outlet available on the Pi Shield. UR Eee We have also used the conditional statements in while loop. According to the if condition, if the voltage is detected on the GPIO18, then the Pi will turn on the LED, which is connected to GPIO23. The voltages will be detected on GPIO18 when the button is pressed. 5.12. Interfacing with SONAR Sensor Equipment needed Following components are required for this project: + Sonar Sensor + PiShield + Raspberry Pi + Power Adapter / Battery + Keyboard, Mouse & LCD Hardware of this project is made simpler for your handling and does not require any soldering or messy wiring, We will use the Pi Shield on the top of the GPIO pins of Pi as a stack and connect the SONAR sensor on the Pi shield, But this time we will power the Pi via power adapter or battery outlet available on the Pi Shield Programming Robots & Single-Board Computers Interfacing code: ‘import RPi.GPIO os gpio import time as t gpio. setmode(gpio.BCM) gpio. setwarnings (false) trigger=17 echo=27 gpio.setup(trigger, gpio. OUT) gpio.setup(echo, gpto. IN) def distance(): gpio. output (trigger, True) Fx*d for Neurons Naru km Riel} programming languages at Gi CTR CULN a Reacts aed es acheter eieel st) Python. UT t.sleep(@.0001) gpio. output(trigger, False) while gpio.input(Echo) =: StartTime=t.time() while gpio.input(Echo) == StopTime=t.time() TimeELapsed=StopTime-StartTime dis=(TimeELasped/2)*34300 return dis while True: D=distance() Deint(D) print(“Measured distance= ”, D, “cm”) t.sleep(0.5) In this program we are determining distance by using a Sonar Sensor. This explains the application of sensors and they talk to the real world. We have created the function by the name of Distance. This function will control voltages to trigger pin which will cause Sonar Sensor to transmit the ultrasonic sound wave, which is inaudible to human ear, for 0.0001 seconds. The transmitted wave will bounce back when it hits the object and will be received by the echo pin. We have included two libraries in this code as well First is the RPLGPIO and second is the time library. Distance is the product of Speed into time. 5.13. Interfacing with Servo Motor A servo motor is an electrical device that can push or rotate an object with great precision. If you want to rotate and object at some specific angles or distance, then you use a servo motor. It is just made up of a simple motor and the servo mechanism. In this, program, we will work with the concept of Pulse-Width Modulation as it is one of the basic operating principles of a servo motor. We will learn how to control servo motors. These motors have its application where an object must be pushed or rotated at a precise angle. We will use the Pi Shield on the top of the GPIO pins of Pi as a stack and connect the Servo motor on the Pi shield. And this time we will also power the Pi via power adopter or battery outlet available on the Pi Shield. Colour codes are marked on the Pi Shield (B for brown, R for Red, and Y for Yellow). Make sure to connect the correct wire on the header, Equipment needed Following components are required for this project: Servo Motor Pi Shield Raspberry Pi Power Adapter / Battery Keyboard, Mouse & LCD Interfacing code: ‘import RPi.GPIO os GPIO ‘import time as t GPIO. setwarnings (False) GPIO. setmode(GPIO.BCM) GPIO. setup(13, GPIO.OUT) p=GPIO. Phili(13, 250) p.start(24) while True: t.sleep(1) p.ChangebutyCycle(37) t.sleep(1) p.ChangebutyCycle(75) t.sleep(1) p.ChangebutyCycle(24) v 2 ov 2 5) a = ° 0 co] fe 5 [o) a £4 a S re) w em Py i>) a2 ° c D fs = fe} ie Da ° fg a EE Servo motors are controlled by PWM (Pulse Width Modulation). PWM works like On- time and Off-time of a signal. On-time represents the active time of the signal required to power the servo motor whereas the Off-time is for the inactive time of a signal. In the code, we are instructing the Pi to start the wave at 24% using the start command. Then we use the command ChangeDutyCycle() which understands the value in percentage format, referring to the on-time of signal or to change the angle. We just have to input the percentage of on-time signal to rotate servo motor to a particular angle. This is the standard method to program a servo motor. The ChangeDutyCycle() is in while True loop which means that the servo motor will keep changing its angle after a particular time. 5.14. Building Smart Robotic Car Bumble Pi is an educational robot kit specially designed for beginners to learn and get hands- on experience with mechanics, electronics, and Computer Science. Bumble Pi is easy to assemble. Follow the step-wise instruction for making Bumble Pi Equipment needed + Raspberry Pi (with Raspbian OS) + PiShield + Screw Set * Chassis (Upper and lower planks ‘and side planks) + Battery with a zip tie * DC Motors Chassis (upper and lower planks) DC Motors + SONAR with Holder * Servo Motor + Wheels & Caster Wheel + Android Mobile Device with TechTree Bumble Pi Application installed in it. Wheels for DC Motor Caster wheel for the front Bumble Pi is an educational robot kit specially designed for beginners to learn and get hands-on experience with mechanics, electronics, and Computer Science. Bumble Pi is easy to assemble. Follow the step-wise instruction for making Bumble Pi SS I Left motor connector Right motor connector SONAR sensor connector ‘SERVO motor connector Steps to Assemble = = Eo cE 4 os = F : é a f a~ f= 1 v Oe & ee ie ees Bumble-Pi Programming Enter the following code in Python IDLE and save the file name as SRC # importing the Libraries from Bluetooth import * ‘import RPi.GPIO os GPIO # Addressing the GPIO Pins as per Pi Shield configuration GPIO. setmode(GPIO. BCM) GPIO. setwarnings(False) GPIO. setup(16,GPIO.OUT) # Creating variables for motor functionality MotorL1 = 21 MotorL2 = 18 enA = 20 MotorR1 = 26 MotorR2 = 12 enB = 19 # initializing the output pins GPIO. setup(MotorL1, GPIO. OUT) GPIO. setup(MotorL2,GPIO. OUT) GPIO. setup(enA, GPIO. OUT) GPIO. setup(MotorR1,GPIO.OUT) GPIO. setup(MotorR2, GPIO. OUT) GPIO. setup(enB, GPIO. OUT) GPIO. output (MotorL1, False) GPIO. output (MotorL2, False) GPIO. output (MotorR1, False) GPIO. output (MotorR2, False) #setting up the speed of motors P=GPIO. Piili(enA, 1000) p.start(75) q=GPIO. Plili(enB, 1000) q.start(75) Programming Robots & Single-Board Computers #activating the on-board bluetooth server_sock=8|uetoothSocket (RFCOMM) port = 1 server_sock.bind(("",port)) server_sock.listen(1) port=server_sock.getsockname()[1] GPIO. output (16, True) uuid ="94f39d29-7d6d-437d-973b-fba39e4ad4ee" advertise_service(server_sock, "SampleServe", service_id=wuid, service_classes=[wuid, SERIAL_PORT_CLASS], profiles=[SERTAL_PORT_PROFILE], ) client_sock,client_info=server_sock.accept() print("Accept connection", client_info) #setting conditions while True: data=client_sock.recv(1024) print(“Receive[ %s]” % data) if (data == quit”): print(“quit”) GPIO.cLeanup() break #forward functionality elif (data == ”F”): GPIO. output (MotorL1, True) GPIO. output (MotorL2, False) GPTO. output (MotorR1, True) GPI0. output (Motork2, False) #backward functionality elif (data == "D”): GPIO. output (MotorL1, False) GPIO. output (MotorL2, True) GPIO. output (MotorR1, False) GPIO. output (MotorR2, True) VE Ee Ee es elif (data == "S”): GPIO. output (MotorL1, False) GPIO. output (MotorL2, False) GPIO. output (MotorR1, False) GPIO. output (MotorR2, False) GPIO. output(16, False) elif (data == "R”): GPIO. output (MotorL1, True) GPIO. output (MotorL2, False) GPIO. output (MotorR1, False) GPIO. output (MotorR2, False) elif (data == "L"): GPIO. output (MotorL1, False) GPIO. output (MotorL2, False) GPIO. output (MotorR1, True) GPIO. output (MotorR2, False) client_sock.close() Programming Robots & Single-Board Computers server_sock.close() After successfully entering this code and saving your file with the name of SRC.py follow these steps to connect your smart car using the android mobile device. Checkpoint 1 1. Connect and pair the Bluetooth of the mobile device with raspberry pi 2. Open terminal and type sudo python SRC.py & 3. You will notice the blue LED light will be on Pi Shield, this means that bluetooth module is ready to connect 4. Open the TechTree-Bumble pi application on the mobile device which you have already paired with Bluetooth to this Raspberry Pi UR Ee eed Click on the Bumble Pi icon on the right bottom corner. For security purposes, your mobile device will ask for permission to give bluetooth module access to this application. Select the Allow option to give permission. ae 7. After that, a list of Bluetooth devices will be available to connect, select the raspberry pi option which will be listed with the physical (MAC) address of the Bluetooth. 8. Car Controlling screen will appear and the Blue LED on your bumble pi shield will turn off it means your Bluetooth connection is successful now you can control your car from your smartphone. 9. If Blue LED doesn't turn off it means you're not connected with the Raspberry Pi so reboot your Raspberry Pi by turning off its switch and then repeat from step 2. Making a Bootloader For mobility purposes, we can also make a bootloader which will automatically start the command whenever the Raspbian OS will boot. By doing this we won't be needing the Keyboard, Mouse and LCD to be connected for configuring or executing the command. Note: This Step will not exclude the process of pairing the android device. Follow these steps to make the bootloader: 1. Open terminal and type the command sudo nano /etc/rc.local 2. There will be a lot of text written in that file. Locate the comment stating # write a path for the code to run here”. And enter this command sudo python /home/pi/ SRC.py & and press ctrl+x 3. The terminal window will ask to save the file, press Y for yes. After that terminal will ask to save this file on the same location where we have to press Enter key. 5. Unplug the cables and restart the Pi by typing the Reboot keyword within the terminal window. 6. Wait for the Pi to boot completely and you will notice the blue light is lit and the PI is. ready to connect with the paired mobile device using the Tech Tree Bumble Pi app. UA Eee eae TOW |. A single-board computer (SBC) is a complete computer built on a single circuit board, with microprocessor(s), memory, input/output (I/O), and other features required of a functional computer. The Raspberry Pi, which is a single board computer (SBC), is a small credit card sized computing device that can be used for a variety of purposes. . GPIO pins allow the Raspberry pi to be configured for different purposes; interact with different circuits, and work with several types of electronic components. |. A list is just an ordered collection of items which can be of any data type. . Del command is used to delete an item from list where as append() command is used to add an item at end of the list. In Python, a function is a group of related statements that perform a specific task . SONAR is an acronym of Sound Navigation & Ranging, It is used for measuring distance regardless of the shape colour and surface of the object. . Aservo motor is an electrical device that can push or rotate an object with great precision. 1. Bumble Pi is an educational robot kit specially designed for beginners to learn and get hands-on experience with mechanics, electronics, and computer science. My Notes!

You might also like