Embeded Programming

Embedded programming is a specialized type of programming specific to embedded systems. These systems are computer systems with a dedicated function within a larger mechanical or electrical system. They are typically designed to perform a dedicated function or functions. Embedded programming involves writing code for the microcontrollers and processors that control these systems. See our group assignment and learn about the performance and development workflow for different architectures and look into the differente datasheets of the microcontrollers found at FabLab Puebla.

Features RP2040
CPU Dual-core ARM Cortex-M0+
Clock speed Up to 133 MHz
Bit depth 32-bit
Storage 264KB of SRAM, and 2MB of on-board Flash memory
I/O pins 30 GPIO pins
Power 1.8V - 5.5V
Dimensions 20x17.5x3.5 mm
Bluetooth No
WiFi No
How to program USB mass-storage boot mode, drag-and-drop programming
Special Functions USB 1.1 Host/Device, 8 Programmable I/O (PIO) state machines

I will use for every different code a version in Arduino and a version on Micro-python using the Thonny terminal, Python IDE for beginners. It is important to note that only one Operative system can be used at a time, and to change our XIAO RP2040 we need to make sure that the microcontroller is in bootable mode. To achieve this, we will press the button on the upper left side and then connect our microcontroller via USB to our computer. We will see our controller as a portable USB popping out on our explorer and then we can upload our UF2 file (a bootloader which is a small piece of code that looks at the programming port (in this case USB) to see if there is new code coming in)

I will use for every different code a version in Arduino and a version on Micro-Python using the Thonny terminal. For all this assignment it is important to keep in mind the following layout for my PCB, otherwise I may use an incorrect pin while coding.


To start the journey on programing, I will start by simply blinking a LED that is located on the Pin 0. This blinking will happen every second and will only turn on and off the LED


To start using a local input, we can use the button on the pin 27 to create a binary status based reading. If the button is pressed it will be read as 1 (HIGH) or 0 (LOW) if not pressed. In this case, if our button is pressed, the LED will be on, else will be turned off.

To create a communication between our microcontroller and the computer, we can use the serial terminal to execute and read prints that could be send from our microcontroller. For example, let’s create a counter where we read how many times we push a button. If we get to 3, let’s print “Hello World” and start the counter back to 0.

Finally, lets create a binary counter using the three LED’s that are located on our board. To do this, First we will need to initialize all 3 LED’s as output pins and create a loop to count from 0 to 7 (3 bits). Then we will use a conditional to turn on the corresponding led. We will use the bin() function to convert from a integer to a binary number.

It’s been a while since I last program a microcontroller and I’m Really happy to finally got back to it and remember what I liked the most about it. At the beginning I was worried I wouldn’t remember all of it, but I most say it was really exciting to do so. This was the first time I used Micro-Python but is really easy and the most challenging part was the last exercise to get to the idea to use the string’s character position as the indicator to turn on or off the LED.

Comparing Python and C

This is the first time that I am programming in Python, although I’ve used it before for different applications it was a new experience. At the beginning I felt weird as I am more experienced in C and have used other languages like Matlab. However, I felt that python could be really easy to use and debug as I felt that is easier to understand the syntax and overall structure.

C Programming Python Programming
Pros
  • Efficient memory usage
  • Fast execution speed
  • Widely used in embedded systems
  • More forums on the web
  • Direct hardware access
  • Simple syntax and readability
  • Rapid prototyping
  • Big library support
  • Easy to learn and use
Cons
  • Difficult learning curve
  • Manual memory management
  • More verbose syntax
  • Less flexibility for high-level tasks
  • Slower execution speed
  • Higher memory usage
  • Limited support for low-level hardware access
  • Dependency on runtime environment
  • My first time using python for this