WEEK04. Embedded programming

This week concerned about the the electroincs design, for me was an intense week, due to no previous knowledge about the topic.

Assignments


Tomato Timer with Seeeduino Xiao RP2040

As individual project I projected a Pomodoro timer, in order to manage efficiently my work flow. I decide to organize my time in cycle of 50 minutes of work and 10 minutes of pause. This method help me to focus on my objectives.

It was my first time in programming microcontrollers, so I started with blinking the embedded RGB led. Connect the RP2040 to the computer using the USB-C cable, pressing the boot mode button.

To program a microcontroller it is used MicroPython, a lighter ptogramming language in term of weight. To code and interact with the embededd microprocessor it is used the Thonny IDE, it is possible to run the code from on your pc or upload it on the microprocessor. First of all you have to install the MicroPython interpreter on the microcontroller. Click on the Thonny preferences, in the interpreter window, select from the drop-down menĂ¹ the option MicroPython (Raspberry Pi Pico). Thonny options Then, click on install or update MicroPyrhon. In the just opened window select the options as in the picture below. Install MicroPython on the microprocessor with Thonny As PCB I used a Seeeduino Xiao RP2040, with some exposed pins as explained in the figure below. In particular, to program the pins you have to use the numbers in the gray boxes, because these are the numbers associated to each pin of the embedded microcontroller RP2040 in the Seeeduino Xiao PCB. Seeeduino Xiao RP2040 exposed pins Additionally to the exposed pins is it possible also to program the pins connected to the RGB led. Especially, the number of pins for the red channel is 17, for the green is 16 and for the blue is 25. The polarity of the RGB led is oriented through the positive pole, so to have potential difference, it is necessary to reverse the polarity using the function .toggle() or it is necessary to use the function that work on the potential difference, in the reversed way. It is useful and possible to know the initial state of the pins using the function .value(). As is it possible to see from the output in console the status of RGB led is 1. Print the initial status of the pins

Useful MicroPython libraries, class, functions and method

Infinite loop

Usually, the codes of a microcontroller has infinite loops that allow the system to run a code perpetually, and the system may change behaviour according to pre-programmed specific conditions. An initial way to implement an infinite loop might be to use an while True loop.

Blink the RGB embedded led

The following code allow to blink the RGB led. The number of seconds are setted inside the parenthesis. Blink the RBG embedded led

Implemented led

I started turning on a red led, implemented using the breadboard. Print the initial status of the pins Then, I make it blinking. Blink implemented led

Then, I add a button to controll the led. Then, at each press I programmed the led to be on or blinking, according to the pre-setted working and pause periods.

Pomodoro timer code

After some trials, my confidence in programming rises and I started to program a Tomato timer. I started sketching with pen and paper the flow, then I started to program in Thonny. Unfortunately, at today I was not able to finish it, due to my limited knowledge in Python. Start mode Programming mode

Arduino UNO

To code an Arduino UNO you have to code in Arduino, similar to C++, using the Arduino IDE that you can dowload freely on the offical web site. Moreover, on the official website you can find some intersting projects and educational materials. Since I prefer to code in Python, my goal is only to learn the Arduino IDE and the programming flow process. So, I programmed the Arduino UNO to blink the main led.

First of all you have to able Arduino IDE to interact with the board through the board manager options and install the necessary drivers.

Install the Arduino UNO port Start creating a new sketch to build the code; as default the code has a setup function, that is runned once at the beginning, then there is the main loop. Sketch in Arduino IDE In the picture below there is the code to blink the embedded yellow led. Note that in Arduino you have to make the casting of the variables and the sleeping time are expressed in milliseconds. Sketch in Arduino IDE Arduino UNO