4 - Embedded Programming

This week the following activities were carried out

Group Assignment:
  • Browse through the datasheet for your microcontroller.
  • Compare the performance and development workflows for other architectures.
  • Document your work to the group work page.
  • Reflect on your individual page what you learned.
  • Individual Assignments:
  • Write a program for a microcontroller development board to interact (with local input &/or output devices) and communicate (with remote wired or wireless devices).

  • PCB production process

    This week, I discovered a hidden talent for soldering SMD components, but the most rewarding part was developing a PCB from scratch. This time, I have to thank my friend Adrian Torres. It was during a visit to the Fab Lab in León where he gifted me a XIAO-RP2040. Perhaps he didn't realize it, but it was a very nice and significant gesture. Now, all my peers use the microcontroller he gave me because it was impossible to find it in Peru.

    So, this week comes with a special gratitude towards my friend Adrian, the man who documents everything.

    Note: This is the most epic shot, because I got very excited when they turned on the 3 LEDs.



    Group assignment

  • To have a broader understanding of the various microcontrollers that we could use, we have divided the research for each of them into teams of 2 people. Then, we had a meeting to present the findings so that everyone can learn about the microcontrollers.
  • My team consists of Silvana Espinoza and me, and we have been assigned the research on the Attiny412. The comparison of the microcontrollers in a group can be found in the button above.
  • During this week, we have worked with the Xiao-RP2040 microcontroller. Before using it, it is important that you are familiar with its most relevant characteristics. This will help you understand which projects you can involve it in.

  • XIAO - RP2040

    Microcontroller Specifications

    Item Value
    CPU Dual-core ARM Cortex M0+ processor up to 133MHz
    Flash Memory 2MB
    SRAM 264KB
    Digital I/O Pins 11
    Analog I/O Pins 4
    PWM Pins 11
    I2C interface 1
    SPI interface 1
    UART interface 1
    Power supply and downloading interface Type-C
    Power 3.3V/5V DC
    Dimensions 20*17.5*3.5mm

    ¡Attention!

    ▲ CAUTION

  • For general I/O pins: Working voltage of MCU is 3.3V . Voltage input connected to general I/O pins may cause chip damage if it' higher than 3.3V .
  • For power supply pins: The built-in DC-DC converter circuit able to change 5V voltage into 3.3V allows to power the device with a 5V supply via VIN-PIN and 5V-PIN.
  • XIAO RP2040 currently only supports battery power supply and cannot connect to Type-C while a battery is connected, as it may pose a safety risk.
  • Please pay attention to use, do not lift the shield cover.

  • Odious comparisons

  • These were the teams that were formed for the investigation of various microcontrollers.

  • Investigators Microcontroller
    Cristian / Grace XIAO RP2040
    Ronal / Franco ATTINY1624
    Silvana / Jesús Attiny412
    Wilber / Renso / María Angela ESP32-C3
    Maryori / Hans SAMD11C
    Board XIAO ESP32-C3 XIAO SAMD21 XIAO RP2040 ATTINY1624 ATTINY412
    Processor ESP32-C3 32-bit RISC-V @160MHz SAMD21 M0+@48MHz RP2040 Dual-core M0+@133MHz ATTINY1624 8-bit AVR @20MHz ATTINY412 8-bit AVR @20MHz
    Wireless Connectivity WiFi and Bluetooth 5 (LE) N/A N/A N/A N/A
    Memory 400KB SRAM, 4MB onboard Flash 32KB SRAM 256KB FLASH 264KB SRAM 2MB onboard Flash 1KB SRAM 16KB Flash 1KB SRAM 4KB Flash
    Built-in Sensors N/A N/A N/A N/A N/A
    Interfaces I2C/UART/SPI/I2S I2C/UART/SPI I2C/UART/SPI I2C/UART/SPI I2C/UART/SPI
    PWM/Analog Pins 11/4 11/11 11/4 6/10 6/10
    Onboard Buttons Reset/ Boot Button N/A Reset/ Boot Button N/A N/A
    Onboard LEDs Charge LED N/A Full-color RGB/ 3-in-one LED N/A N/A
    Battery Charge Chip Built-in N/A N/A N/A N/A
    Programming Languages Arduino Arduino/ CircuitPython Arduino/ MicroPython/ CircuitPython Arduino Arduino

    Feature Analysis Among Microcontrollers

    1. Processors and Performance:
      • XIAO ESP32-C3 uses an ESP32-C3 32-bit RISC-V processor, providing solid performance.
      • XIAO SAMD21 uses a SAMD21 M0+ processor at 48MHz, while XIAO RP2040 has a Dual-core RP2040 M0+ processor at 133MHz.
      • ATTINY1624 and ATTINY412 microcontrollers use 8-bit AVR processors at 20MHz. They are simpler options in terms of performance compared to XIAO microcontrollers.
    2. Wireless Connectivity:
      • Only XIAO ESP32-C3 incorporates wireless connectivity with WiFi and Bluetooth 5 (LE), offering advanced communication options.
      • The other microcontrollers (XIAO SAMD21, XIAO RP2040, ATTINY1624, ATTINY412) do not include integrated wireless capabilities.
    3. Memory:
      • XIAO ESP32-C3 stands out with 400KB of SRAM and 4MB of flash memory, providing ample space for storage and data manipulation.
      • XIAO RP2040 also offers significant memory, with 264KB of SRAM and 2MB of flash memory.
      • ATTINY1624 and ATTINY412 microcontrollers have more limited memory, with 1KB of SRAM and different flash memory capacities.
    4. Interfaces and Pins:
      • All microcontrollers share common interfaces such as I2C, UART, and SPI, providing flexibility for connection with other devices.
      • PWM and analog pins vary, being more abundant in XIAO, while ATTINY offers a more limited quantity.
    5. Programming:
      • All microcontrollers support programming through the Arduino development environment. Additionally, some (XIAO SAMD21 and XIAO RP2040) support CircuitPython and MicroPython, expanding development options.
    6. Sensors and Additional Features:
      • None of the mentioned microcontrollers includes integrated sensors. Additional features such as LEDs and buttons vary depending on the model.

    Conclusions

  • After our tedious but necessary comparison among these 5 microcontrollers, we can determine that the decisive factor for selecting one of them will be the project specifications. We will take into account the required connectivity and interfaces. While it is true that the XIAO stands out for its more advanced features, the ATTINY remains the best option for simpler projects.

  • Individual assignment

  • For this individual task, I used Arduino IDE. I also employed MicroPython through Thonny.

  • Arduino IDE

  • Arduino seems to me a more familiar environment; its installation on the PC is simpler and quite intuitive. You just need to go to https://www.arduino.cc/ and select the operating system you are using. I have chosen version 2.3.2 of the Arduino IDE, and I can say that its interface has improved significantly. It now features autocomplete, code navigation, and even a live debugger.
  • After installing the IDE, we need to add some libraries and boards. To add the XIAO RP2040, that's why we will add the URL for additional boards that you can find here. We will also need the Arduino-Pico from Earlephilhower.
  • When everything is correct, finally, you will be given the option to choose the Seed XIAO -RP2040 board.

  • Now that I have Arduino installed, let's run it, and the first thing to do is a fairly basic exercise where I'll make an LED blink. It will be the integrated LED of the XIAO RP2040.
  • You can find the blink example in the Arduino IDE at Files > Examples > Basic > Blink.

  • After uploading the code, it looks like this:

  • After uploading the code, it looks like this:

  • Now, I will try to turn on and off an LED for one second, but this time it will be an onboard LED connected to the XIAO-RP2040. It's worth mentioning that this board was Adrian's idea, my friend. I will test the following command to confirm that the milled circuit and the soldering of my SMD components have been successful.

  • Here is the code:

  • 
    int pinled = 0;						
    void setup() {   
    pinMode(pinled, OUTPUT);  
    }							
    void loop() {
    digitalWrite(pinled, HIGH);  // turn the LED on (HIGH is the voltage level)
    delay(1000);                  // wait for a second
    digitalWrite(pinled, LOW);   // turn the LED off by making the voltage LOW
    delay(1000);                  // wait for a second
    }
    									



    THONNY, Python IDE for beginners

  • I had never heard or used Thonny before, so from what I've researched, Thonny is an integrated development environment (IDE) for Python designed for beginners. It was created by Aivar Annamaa, an Estonian programmer.
  • To do that, first, we download it from its main page and start the installation process.

  • After conducting tests with Arduino, we will now attempt a similar task using the Thonny Integrated Development Environment (IDE).
  • First, I will try to make the integrated LED blink using MicroPython.
  • To start, we need to configure Thonny for the XIAO RP2040. You can follow this Seed Studio XIAO RP2040 with MicroPython tutorial for guidance.
  • After configuring the board, we will implement the following code:

  • 
    from machine import Pin, Timer
    led = Pin(25, Pin.OUT)
    Counter = 0
    Fun_Num = 0
    
    def fun(tim):
        global Counter
        Counter = Counter + 1
        print(Counter)
        led.value(Counter%2)
    
    tim = Timer(-1)
    tim.init(period=1000, mode=Timer.PERIODIC, callback=fun)
    								
  • Within the tutorial, I also found how we can activate the RGB LED of the XIAO - RP2040. To do this, we will use the following code:

  • 
    from ws2812 import WS2812
    import utime
    import machine
    power = machine.Pin(11,machine.Pin.OUT)
    power.value(1)
    BLACK = (0, 0, 0)
    RED = (255, 0, 0)
    YELLOW = (255, 150, 0)
    GREEN = (0, 255, 0)
    CYAN = (0, 255, 255)
    BLUE = (0, 0, 255)
    PURPLE = (180, 0, 255)
    WHITE = (255, 255, 255)
    COLORS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE)
    									
    led = WS2812(12,1)#WS2812(pin_num,led_count)
    									
    while True:
    	print("Beautiful color")
    	for color in COLORS: 
    		led.pixels_fill(color)
    		led.pixels_show()
    		utime.sleep(0.2)