Raspberry Pi

Aus HSHL Mechatronik
Zur Navigation springen Zur Suche springen

Autoren: Fawad Murad
Betreuer: Prof. Schneider
Art: Praxissemester
Projektlaufzeit: 02.11.2021-20.02.2022

Abb.1 Raspberry Pi 4


Introduction

The Raspberry Pi is a single computer the size of a credit card. It features an ARM/Broadcom SoC with a GPU, RAM, and wireless and cable communication options. In some ways, it's that straightforward: the Raspberry Pi is just a small computer. However, it is not so straightforward in another manner. The Raspberry Pi is a very adaptable platform that allows you to build whatever you desire.

Initially, we got the AlphaBot with an Arduino attached to it and then we replaced Arduino with a Raspberry Pi 4 and used or programmed it accordingly. In this article, the idea of using Raspberry Pi 4 instead of Arduino IDE with Alphabot is introduced. Like, how different tools make the Raspberry Pi 4 to control and work with Alphabot. Before we go further, let us take a closer look at the difference between these two boards, Arduino IDE and Raspberry Pi. Then, I will discuss on the installation of required softwares and role of GPIO pins to control the hardware.

Arduino

Abb.2


Arduino is a development board that uses a microcontroller. Arduino UNO uses the ATmega328P microcontroller, which is based on Atmel microcontrollers. The Processor, RAM, and ROM are all contained in the Microcontroller on the Arduino Board (such as the ATmega328P). Supporting hardware (for power and data) and GPIO pins are included on the board. Arduino was built from the ground up as open-source hardware and software. The hardware and software of Arduino are both easily accessible. There is no need for an operating system because it is a Microcontroller. To connect to the internet using Arduino, you'll need an extra module or shield. In the case of Arduino, there is no wireless connectivity (at least on board). C or C++ programming languages can be used to programme Arduino.


Raspberry Pi

Abb.3


The Raspberry Pi is an SBC (Single Board Computer). It's built around a Broadcom SoC, which is an ARM Cortex A Series microprocessor. The Raspberry Pi Board contains all of the necessary components, such as the processor, RAM, storage, connectors, and GPIO pins. Raspberry Pi's hardware and firmware are both closed-source, which means they are not available for general usage. To boot the Raspberry Pi, you'll need a Debian-based Linux distribution called Raspberry Pi OS. Using Wi-Fi or Ethernet, you may effortlessly connect to the internet. The Raspberry Pi includes Bluetooth and Wi-Fi technology. Python, Scratch, Ruby, C, and C++ are the most popular programming languages for Raspberry Pi application development.


Using the Raspberry Pi’s GPIO to control hardware components

The Raspberry Pi's row of GPIO pins along the top edge of the board is a powerful feature. General-Purpose Input/Output is an acronym for GPIO. These pins are the Raspberry Pi's physical interface to the outside world. You can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output) at the most basic level (output). The Raspberry Pi's GPIO pins link to electronic circuits and allow it to control and monitor the outside world. The Raspberry Pi can control LEDs, switch them on and off, and run motors, among other things. It can also tell if a switch has been pressed, the temperature, and the amount of light. This is referred to as physical computing.

Abb 4: GPIO Pin Label

The Raspberry Pi has 40 pins (26 pins on early variants), each of which serves a different purpose. If you have a RPi pin label, you can use it to assist you figure out what each pin is for. Make that the keyring hole on your pin label is facing outwards, away from the USB ports.


1. GND: Zero volts is a voltage that is used to complete a circuit.

2. GP2: These pins can be used for a variety of purposes and can be set up as input or output pins.

3. 5V: Anything that is attached to these pins will always receive 5 volts of power.

4. 3V3: Anything attached to these pins will receive 3.3V power at all times.

5. ID_SC/ID_SD/DNC: pins with a specific purpose.


TIP: Playing with the GPIO pins is safe and enjoyable if you follow the instructions. Randomly putting wires and power sources into a Pi, on the other hand, may cause it to fail, especially if the 5V pins are used. If you try to connect devices to a Pi that use a lot of power, bad things can happen.


An ultrasonic distance sensor emits ultrasound pulses that are undetectable by humans and detects the echo that is returned when the sound bounces off a nearby object. The distance from that thing is then calculated using the speed of sound.

Two GPIO pins (one for echo, one for trigger), the ground pin, and a 5V pin are connected to the circuit. You must know which GPIO pins the echo and trigger are attached to in order to use the ultrasonic distance sensor in Python. First, we initialize the GPIO pins in our program.

Here,

  • the echo is connected to pin '5'
  • the trigger is connected to pin '17'
  • the servo to pin '27'.
Abb 5


GPIO.setmode(GPIO.BCM) = set up GPIO Broadcom chip-specific pin numbering
self.p = GPIO.PWM(servo, 50) = When RPi configured for software pulse-width modulation, each pin generates a square waveform with a configurable duty cycle and frequency
self.PWMA.start ( ) = hints left wheel speed
self.PWMB.start ( ) = hints right wheel speed
Abb 6


Documentation

Summary

This whole article conveys the information related to one specific part of this project. From the name "Raspberry Pi and ROS2", we can get an insight of what can be included in this section. In this article, I discussed on difference between Raspberry Pi and Arduino, Ubuntu as an operating system on our microprocessor, how we can begin with ROS2, why we need it, how it helps us and using Raspberry Pi GPIO pins to control the hardware.

Since, the above mentioned things are not the only ones what I participated in doing. We worked as a team on this project and achieved the overall result together. Along with above mentioned sections, I was also able to work and sharpen my skill of programming in Python and C++ language by programming Raspberry Pi 4 using ROS2 and the simulation on Webots .


Self-reflection

First, each of us was obliged to practise the tutorials of ROS2 and Webots in order to have a good command on these two tools. After walking through the tutorials, I was able to build a similar robot like Alphabot on Webots that I integrated with ROS2 later. We can also control the robot using Keyboard along with allowing it to drive autonomously on Webots. Then, I started programming Raspberry Pi 4 with the integration of ROS2 in order to make our AlphaBot to be able to detect obstacles and drive autonomously.

In short, I got a good grip on following tools by working on this project:

  • Ubuntu, family member of Linux OS
  • Credit-card sized computer: Raspberry Pi 4
  • Robot Operating System
  • Programming in object-oriented language, Python and C++


Outlook

Every day, technology evolves and expands. It's also affecting how individuals conduct their jobs. Robotics is one of the technologies that is transforming the global industrial landscape. Patience, the courage to work through mistakes, and problem-solving skills are all required to thrive in robotics. And I was privileged to work under the supervision of the professors in order to get into this world, explore my abilities, realize my mistakes and improve them. Internship is the point where we get a chance to implement all of our skills that we learnt previously in a real and professional world. Around the world, robotics is forging new ground in learning approaches. It is imperative that we prepare ourselves for the changes that will occur in the future in all facets of our lives, whether personal, educational, or professional. And I am looking very forward to playing my part in it in near future.

Weiterführende Links