Steps of Robotic Coding: Which Hardware and Software Take the Spotlight?
Robotic coding consists of three main components: software, electronics (hardware), and mechanics. Software is divided into two categories: text-based and block-based programming. In this article, we will explore these programming types in detail. Text-based programming involves using programming languages like C, Python, etc. On the other hand, block-based programming allows you to create algorithms visually by dragging and dropping code blocks with a mouse. This approach simplifies the process, enabling you to design algorithms easily.
Electronics (hardware) is the phase where sensors needed for your project are connected to the microcontroller via cables and other connectors. Mechanics involves placing the input and output sensors into the robot's skeleton parts, made of materials like wood or metal, and assembling these parts properly.
With the rapid advancement of technology, robotic coding has found its way into various industries. This expansion has created many new professions and increased demand for engineering degrees. As a result, educational institutions have started including courses like "Robotic Coding" and "Physical Programming" in their curricula for all age groups. Moreover, the widespread popularity of robotic coding has led to an increase in hobbyists developing personal projects.
The rise of robotic coding has also increased the number of robotic coding tools and platforms. In terms of electronics, robotic coding tools primarily consist of development boards and sensors.
Development Boards
In robotic coding, the project codes we write in various programming languages are uploaded to microcontrollers. To facilitate easier use of these microcontrollers with input-output sensors, development boards have been introduced.
The most commonly used development boards in robotic coding are:
Arduino
Arduino offers a variety of development boards of different sizes and purposes, all based on the ATmega microcontroller. For example, Arduino UNO, Arduino NANO, and Arduino Leonardo are part of the Arduino family.
Click here to access Arduino sets.
Raspberry Pi
Raspberry Pi is a community initially aimed at making coding and electronics enjoyable for children. It produces various development boards and microcontrollers in different sizes for different purposes. Raspberry Pi, Raspberry Pi Pico, and Raspberry Pi Pico W are part of the Raspberry Pi family.
Raspberry Pi is classified as a Single Board Computer (SBC), a credit card-sized computer. To learn more, check out our blog post What is Raspberry Pi? Models and What You Can Do with Them? #1.
Click here to access Raspberry Pi sets.
PicoBricks
PicoBricks is a development board with 12 modules. It uses the Raspberry Pi Pico microcontroller and features over 12 sensor modules. Thanks to its data pathways, PicoBricks allows communication between the modules and the Raspberry Pi Pico without requiring cables or altering the board’s integrity. Additionally, its breakable design enables users to separate modules for individual use and connect them easily with wires.
PicoBricks also offers project development boards for users of various skill levels, such as PicoBricks for Raspberry Pi Pico, PicoBricks for micro:bit, and BerryBot.
Click here to access PicoBricks products.
Micro:bit
Micro:bit is a microcontroller developed by the BBC, featuring a 5x5 LED matrix, two buttons, an accelerometer, a compass, a speaker, and a microphone on its front. Its pin points on the back allow users to connect additional sensors.
Click here to access micro:bit products.
Coding Platforms
Various editors have been developed to program the boards mentioned above. Some of these editors are provided by the board manufacturers, while others are designed by third parties.
To communicate the written code with sensors, it must be loaded into microcontrollers. The editor used depends on the microcontroller you are working with.
Commonly used editors in robotic coding include:
Arduino IDE
Arduino IDE is a text-based editor that allows coding development boards like Arduino, Raspberry Pi, and ESP32 using the C programming language.
Example Circuit
#define Button 8
#define Led 10
void setup() {
pinMode(Button, INPUT);
pinMode(Led, OUTPUT);
}
void loop() {
if (digitalRead(Button) == 1)
digitalWrite(Led,HIGH);
else
digitalWrite(Led,LOW);
}
Thonny IDE
Thonny IDE is a text-based editor for coding development boards like Raspberry Pi, Raspberry Pi Pico, Arduino, and micro:bit using the Python programming language.
Example Circuit
import gpiod
import time
LED_PIN_G = 17
LED_PIN_Y = 27
LED_PIN_R = 22
chip = gpiod.Chip('gpiochip4')
led_lineG = chip.get_line(LED_PIN_G)
led_lineG.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)
led_lineY = chip.get_line(LED_PIN_Y)
led_lineY.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)
led_lineR = chip.get_line(LED_PIN_R)
led_lineR.request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT)
while True:
led_lineG.set_value(0)
led_lineY.set_value(0)
led_lineR.set_value(1)
time.sleep(3)
led_lineG.set_value(0)
led_lineY.set_value(1)
led_lineR.set_value(0)
time.sleep(0.5)
led_lineG.set_value(1)
led_lineY.set_value(0)
led_lineR.set_value(0)
time.sleep(2)
Scratch
Scratch, developed by MIT, is a block-based editor. It allows you to drag and drop blocks to program development boards or create animations, games, and visual projects using characters and costumes from the Scratch platform.
Example Scratch IDE Code
PicoBricks IDE
PicoBricks IDE is an online editor accessible via a web browser without requiring any downloads. It supports both block-based programming and text-based programming in MicroPython, enabling users to code PicoBricks for Raspberry Pi Pico and BerryBot.
MicroBlocks
MicroBlocks is a block-based editor compatible with many development boards, such as Raspberry Pi Pico, micro:bit, ESP32, PicoBricks, and REX Robot Kits. Its standout feature is its support for parallel code execution, allowing multiple loops to run simultaneously.
Example MicroBlocks IDE Code
MakeBlocks IDE
Initially developed for MakeBlocks boards, this block-based editor is now compatible with a wide range of sensors and microcontrollers, including Arduino and Raspberry Pi.
Example MakeBlocks IDE Code
MakeCode IDE
MakeCode IDE is a block-based programming editor, primarily for micro:bit and other microcontrollers. It includes a simulator that displays real-time output of your code, allowing you to identify and fix errors before uploading the code to your device.
Example MakeCode IDE Code
Common Errors in Robotic Coding
Robotic coding involves three main phases: electronics, software, and mechanics, each of which presents unique challenges.
Electronics Errors
-
Cable Clutter: Connecting sensors to microcontrollers often requires multiple cables, leading to clutter as the number of sensors increases. This clutter makes debugging more time-consuming and can discourage students in educational settings. Development boards like PicoBricks and BerryBot address this issue.
-
Soldering Risks: Using soldering for connections can pose safety hazards, such as harmful fumes and accidental burns. Boards like PicoBricks eliminate the need for soldering.
Software Errors
-
Syntax Errors: Text-based programming languages often require precise syntax. A missing semicolon in C can cause an otherwise correct code to fail, especially in larger projects. Block-based programming languages were developed to reduce such errors.
-
Learning Curve: Transitioning to a new programming language can be challenging. For instance, while "else if" in C and "elif" in Python serve the same purpose, their syntax differs.
Mechanical Errors
-
Assembly Complexity: Complex robotic systems with many mechanical parts can have confusing assembly steps. Products like PicoBricks and mBot include detailed assembly guides to simplify the process.
-
Part Loss: Systems with numerous components are prone to part loss if not organized properly. Using storage organizers can help mitigate this issue.
Importance of Robotic Coding in Education
Robotic coding helps students develop computational thinking skills and is therefore included in educational curricula. It is often integrated with approaches like STEM, which combines coding with other subjects. During the software phase, students enhance problem-solving and algorithmic thinking skills, while the electronics and mechanics phases improve hand-eye coordination and motor skills. Furthermore, group projects in robotic coding foster teamwork and social skills.