Week 06

Embedded Program

Brief Overview

In this week of FabAcademy, my individual assignment involved creating and implementing a program for a microcontroller development board that I made in Electronics production week. This program facilitates interaction with local input/output devices and communication with remote devices, utilizing both wired and wireless connections. As an extra credit endeavor, I incorporated different programming languages and development environments, and further expanded the project by connecting external components to the board. Concurrently, our group assignment revolved around an extensive exploration of the microcontroller's datasheet, allowing us to compare its performance and development workflows with other architectures. This comprehensive approach not only deepened my understanding of embedded programming but also provided valuable insights into the diverse landscape of microcontroller architectures and their applications, aligning seamlessly with the goals of FabAcademy.

My Heroshot for this Week







Embedded Programing

Embedded programming is a specialized field of software development focused on creating software for embedded systems—small, specialized computing devices designed for specific tasks. These systems can be found in a wide range of applications, from consumer electronics and medical devices to industrial machinery and automotive systems.


Embedded programming involves writing code that is typically executed directly on the microcontroller or microprocessor within the embedded system. Key aspects of embedded programming include understanding the hardware architecture, dealing with resource constraints such as limited memory and processing power, and optimizing code for real-time performance.


Common programming languages for embedded systems include C and C++, Python and the development process often involves using integrated development environments (IDEs) and debugging tools specific to the target hardware. The applications of embedded programming are diverse, playing a critical role in the functionality of everyday devices and complex industrial systems alike.


Architectures


Architecture in electronics chip design refers to the design and organization of components at various levels, from the overall system down to the individual transistors and logic gates. It involves making decisions about the arrangement, interconnection, and functionality of these components to achieve the desired performance, efficiency, and functionality of the electronic system.

Types of Architecture


There are two types of computer architecture: Von Neumann and Harvard architecture. The Von Neumann architecture mainly has one shared program and data memory while Harvard architecture has two separate memories where one is meant for program code and the other for data.


Von Neumann Architecture:

  • Unified Memory: Data and Instructions Share Memory
  • Single Bus System: Single Path for Data and Instructions
  • Stored Program Concept: Programs as Data
  • Flexibility: Dynamic Program Modification is possible

Harvard Architecture:

  • Separate Memory Spaces: Distinct Memory for Data and Instructions
  • Parallel Access: Simultaneous Fetching of Data and Instructions
  • Higher Bandwidth: Reduced Bus Contention, Potential for Increased Performance
  • Program and Data Isolation: Enhanced Security due to Separation

Comparison:

  • Flexibility: Von Neumann is more flexible, allowing dynamic program modification.
  • Bandwidth and Speed: Von Neumann may have lower bandwidth; Harvard may offer higher bandwidth.
  • Security: Von Neumann may be less secure; Harvard provides enhanced security due to separation.
  • Common Usage: Von Neumann is common in general-purpose computers; Harvard is often used in embedded systems.


Microprocessor v/s Microcontroller



Microprocessor vs Microcontroller


Difference between Microprocessor and Microcontroller


Microprocessors and microcontrollers are both integrated circuits (ICs) that contain a central processing unit (CPU). However, they have some key differences in their functionality and applications.

Functionality:

  • Microcontroller: A compact integrated circuit that includes a processor core, memory (RAM and/or ROM), input/output peripherals, timers, and sometimes additional features like analog-to-digital converters. Designed for specific applications in embedded systems.
  • Microprocessor: A central processing unit (CPU) that performs general-purpose processing tasks. Lacks built-in peripherals and is typically used in conjunction with external components like memory, input/output devices, and support chips. Found in devices requiring general-purpose computing capabilities.


Applications:

  • Microcontroller: Commonly used in embedded systems for specific applications, such as in consumer electronics (e.g., washing machines, microwave ovens), automotive control systems, industrial automation, and various electronic gadgets.
  • Microprocessor: Found in general-purpose computing devices, such as personal computers, servers, laptops, and workstations, where versatility and the ability to run a wide range of applications are crucial.


Feature Microprocessor Microcontroller
Components CPU only CPU, memory (RAM, ROM), and I/O peripherals
Integration Requires external components (memory, I/O) All components integrated on a single chip
Complexity More complex due to external connections Simpler due to integrated components
Cost Generally more expensive Generally less expensive
Power consumption Higher power consumption Lower power consumption
Applications Personal computers, laptops, smartphones Embedded systems (washing machines, toys, drones)

In summary, microprocessors are powerful and flexible general-purpose processors, while microcontrollers are self-contained, low-power devices designed for specific tasks in embedded systems.



Microcontroller


A microcontroller is a compact integrated circuit (IC) that combines a processor core (CPU), memory (RAM and/or ROM), and programmable input/output peripherals, all on a single chip. It is designed to execute specific tasks and control functions within embedded systems. Microcontrollers are commonly used in a variety of applications where precise control and real-time processing are essential, such as in consumer electronics, automotive control systems, medical devices, home appliances, and industrial automation.
Microcontrollers are programmed to perform specific tasks and are commonly used in systems where space, power consumption, and cost are critical considerations. They are a fundamental component of embedded systems, providing the intelligence and control necessary for the proper functioning of various electronic devices and applications.

This week there are two types of assignments, one group and one individual.



Group Assignment :-

  1. Browse through the data sheet for your microcontroller
  2. Compare the performance and development workflows for other architectures


Visit our Group assignment page here


Group Assignment Brief:

Understanding the datasheet of the XIAO RP2040 Development Board is imperative for gaining insights into its functionalities and specifications. By acquiring the latest information from Google, we ensure access to up-to-date details provided by the manufacturer. This comprehensive document encompasses intricate technical data, including electrical characteristics, pinout diagrams, communication protocols, and recommended operating conditions. Armed with this knowledge, we can adeptly design, program, and troubleshoot projects, harnessing the full potential of the board's features. The datasheet acts as a robust reference guide, enabling informed decision-making in hardware connections, firmware development, and optimization strategies.

In parallel, a crucial aspect of our group assignment involves comparing the performance and development workflows of the RP2040 with other microcontroller architectures. We meticulously evaluate various microcontrollers, considering key parameters such as Microcontroller type, Core specifications, Architecture, Operating voltage, and Digital pin count. This thorough analysis aids in understanding how the RP2040 distinguishes itself or aligns with other microcontroller options in the broader landscape. Our group assignment delves into the nuanced details of these comparisons, fostering a comprehensive understanding of the RP2040's position in the realm of microcontrollers.

Individual Assignment:

  1. Write a program for a microcontroller development board that you made, to interact (with local input &/or output devices) and communicate (with remote wired or wireless devices)
  2. Extra credit: use different languages &/or development environments
  3. Extra credit: connect external components to the board

Writing a Program for Microcontoller board

A program for a microcontroller is a set of instructions written in a programming language that is specific to the architecture and instruction set of the microcontroller. Microcontrollers are small, specialized computer systems embedded in various electronic devices to control their operation.

Steps to Create a Program for a Microcontroller


  1. Select a Programming Language:

    Choose a programming language suitable for the microcontroller (e.g., C, C++, assembly).

  2. Write the Code:

    Develop the program by writing the code that defines the logic and behavior.

  3. Compile the Code:

    Use a compiler or assembler to convert the code into machine language.

  4. Load the Program onto the Microcontroller:

    Transfer the compiled code onto the microcontroller using a programming tool.

  5. Debug and Test:

    Test the program on the microcontroller, check for errors, and make corrections.

  6. Optimize if Necessary:

    Optimize the code for performance and memory usage.

  7. Deploy the Microcontroller:

    Deploy the microcontroller to its intended application or device.

To write the code in embedded C language

C is a powerful and versatile programming language that was created in the early 1970s by Dennis Ritchie at Bell Labs. It has since become one of the most widely used and influential programming languages, forming the basis for many other languages and playing a crucial role in the development of operating systems. C has had a profound impact on the field of computer science and programming. It serves as an excellent language for system-level programming, embedded systems, game development, and many other applications where performance and efficiency are critical. Despite its age, C remains relevant and continues to be widely used in various industries.

Compiler for Code in C Language


A compiler for the C programming language is a software tool that translates human-readable C code into machine code or an intermediate code that can be executed by a computer's hardware. The compilation process involves several stages, and the compiler plays a crucial role in converting the source code written in C into an executable program.

Compiler I have used



Arduino IDE User Guide

Step 1: Download and Install Arduino IDE

  1. Visit the official Arduino website: Arduino Software
  2. Download the latest version of the Arduino IDE for your operating system.
  3. Follow the installation instructions provided for your specific operating system.


Step 2: Launch Arduino IDE



  1. After installation, open the Arduino IDE.

Step 3: Configure Arduino Board

  1. Connect your Arduino board to your computer using a USB cable.
  2. Then, navigate to File -> Preferences and paste the link below into Additional Board Manager URLs
  3. The link to copy and paste: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json


  4. Click “OK” to save these preferences.

  5. Then, go to Tools -> Board -> Board Manager and type pico into the search bar, and hit enter. Select Raspberry Pi Pico/RP2040 by Earle F. Philhower, III and press Install. Then press close and you should be all set to connect your RP2040.


Step 4: Select Port

  1. Go to "Tools" > "Port" and select the port to which your Arduino is connected.

Step 5: Write Your Code

  1. In the Arduino IDE, you will see a default sketch with `void setup()` and `void loop()` functions.
  2. Write your Arduino code in between these functions.

Step 6: Verify/Compile Code

  1. Click on the checkmark icon (or go to "Sketch" > "Verify/Compile") to check for any syntax errors in your code.

Step 7: Upload Code to Arduino Board

  1. Click on the right arrow icon (or go to "Sketch" > "Upload") to upload your code to the Arduino board.
  2. Wait for the compilation process to finish, and you should see "Done uploading" at the bottom of the IDE.

Step 8: Open Serial Monitor (Optional)

  1. If your code involves serial communication, you can open the Serial Monitor by clicking on the magnifying glass icon in the upper-right corner or going to "Tools" > "Serial Monitor."

Step 9: Live Testing



To write the code in MicroPython

MicroPython is a lightweight and efficient implementation of the Python 3 programming language tailored specifically for microcontrollers and constrained environments. Developed with the aim of bringing the versatility and ease of Python to resource-limited devices, MicroPython allows developers to write Python code that can run directly on microcontrollers, making it well-suited for embedded systems, IoT (Internet of Things) applications, and other projects with limited hardware capabilities. Despite its small footprint, MicroPython retains many of the familiar features of the standard Python language, enabling developers to leverage Python's simplicity and readability for rapid prototyping and development in the realm of embedded computing. Its adaptability and compatibility with various microcontroller platforms make MicroPython a popular choice for those looking to integrate the power of Python into the world of embedded and connected devices.

Compiler for Code in Micro Python


In the context of Python, a "compiler" typically refers to tools that facilitate the transformation of Python source code into bytecode or machine code, enabling improved performance or standalone executable creation. Unlike traditional compilers in languages like C or C++, Python compilers don't completely replace the interpreter; rather, they enhance certain aspects of Python code execution

Compiler I have used



Thonny IDE User Guide

Step 1: Download and Install Thonny IDE

  1. Visit the official Thonny website: Thonny IDE
  2. Download the latest version of Thonny IDE for your operating system.
  3. Follow the installation instructions provided for your specific operating system.


Step 2: Launch Thonny IDE

  1. After installation, open the Thonny IDE.

Step 3: Configure Python Interpreter

  1. If not automatically detected, set up the Python interpreter by selecting it in the top-right corner.
  2. Click "Tools-->Options" to open the settings



  3. Chose the "Interpreter" interface and select the device as "MicroPython(Raspberry Pi Pico)" and the port as "Try to detect prot automatically"



Step 4: Connect Seeed Studio XIAO RP2040 to the PC

  1. Press and hold the "BOOT" button and then connect the Seeed Studio XIAO RP2040 to the PC through the Type-C cable. If it works well, there is an "RPI-RP2" desk shown on the PC.

  2. Click on the Install button and close this page when the installation status says Done. The following information will be shown on the interface once the firmware is complete.


Step 5: Write Your Python Code

  1. Write your Python code in the editor.

Step 6: Save Your Python File

  1. Save your Python file using the "File" menu or keyboard shortcut (Ctrl + S).

Step 7: Run Your Python Code

  1. Click the "Run" button or use the "Run" option in the "Run" menu to execute your code.

Step 8: Debug Your Code (Optional)

  1. If needed, use the debugging tools provided by Thonny to identify and fix issues in your code.

Step 9: Live Testing



Reference Files

  1. To find code for C language click here
  2. To find code for Python click here