Week 4 Embedded Programming

Hero

Summary

This week we tackled embedded programming. I found the topic a bit confusing especially reading the datasheet which contains a lot of terms I a completely unfammiliar with. I was able to run a program through simulation and also get the built in LED to blink on a Raspberry Pi Pico (RP2040) microcontroller. Time management was challenging this week as I was hosting a continuing education course at my workplace over the weekend.

Assignments

Group assignment: Demonstrate and compare the toolchains and development workflows for available embedded architectures von Neumann, Harvard, bugs RISC, CISC microprocessor, microcontroller multi-core GPU, embedded FPGA, TinyFPGA, IceStorm, Symbiflow SiliconCompiler spatial

Individual assignment: browse through the data sheet for your microcontroller write a program for a microcontroller, and simulate its operation, to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)

Assessment

Linked to the group assignment page

Browsed and documented some information from your microcontroller's datasheet

Programmed your simulated board to interact and communicate

Described the programming process(es) you used

Included your source code

Included ‘hero shot(s)’

Learning process

First step this week is to rewatch the programming and debugging recitation to see if I can get a little bit of a grasp on how this works. It makes slightly more sense than last time it seems either micropython or circuitpython would be the easiest programming languages to learn about.

I have installed the Thonny program that he recommends and a Wokwi embedded simulator for VSCODE

I am meeting with a instructor at 15 to better understand the mechanics of the deliverable for the individual assignment.

I am also getting started on the RP204 and will spend the next hour on this. 156 pages in it is fairly confusing what I am actually learning from this, I imagine that this is mostly useful to look up certain things that you may want the microcontroller to do and how to code for this so that it responds the way you want to. Here are a couple of insights from the datasheet.

Chapter 1 of the datasheet is the introduction

The summary of the RP204 is as follows RP2040 is a low-cost, high-performance microcontroller device with flexible digital interfaces. The Key features are • Dual Cortex M0+ processor cores, up to 133MHz • 264kB of embedded SRAM in 6 banks • 30 multifunction GPIO • 6 dedicated IO for SPI Flash (supporting XIP) • Dedicated hardware for commonly used peripherals • Programmable IO for extended peripheral support • 4 channel ADC with internal temperature sensor, 500ksps, 12-bit conversion • USB 1.1 Host/Device

It also describes pin locations and pin functions, I have difficutly comprehending what the actual meaning of most these descriptions are. For example GPIO means A GPIO (general-purpose input/output) port handles both incoming and outgoing digital signals. So the RP 2040 has 30 pins that can handle incoming and outgoing signals.

There are large tables in the datasheet describing the various pin functions also in language that I have difficulty comprehending.

Chapter 2 of the datasheet is the system descriptions it describes the RP2040 key system features including processor, memory, how blocks are connected,clocks, resets, power, and IO.

It goes through the "Bus" for the microcontroller which is a communication system that allows different components within the microcontroller to exchange data. It serves as a pathway for data transfer between the central processing unit (CPU), memory, input/output (I/O) peripherals, and other on-chip components.

Chapter 3 is PIO. Pio stands for PIO stands for programmable input/output. It's a feature that allows you to configure and control hardware pins or ports programmatically, rather than through fixed hardware configurations. It involves using software to configure specific input and output pins on a microcontroller or other digital device.

Chapter 4 is a list of the various peripherals available for the RP2040. I have heard of USB of course but there are multiple others I have not heard of before.

Chapter 5 is about electrical and mechanical features

Chapter 6 is the Appendix and the datasheet is a total of 637 pages long.

Programming the simulation

My first attempt at programmings was to set up a simulation following exactly what Nicolas did in the recitation with some modifications. I first added a LED light and connected it to the first slot on the Raspberry Pi Pico microcontroller and then added another connection through the resistor and into a ground slot per Svavars instructions.

Nicolas code from the recitation is like this in micropython

import machine
import time

# Set pin 25 (= blue led on XIAO RP2040, builtin led on RPi Pico) as an output
led = machine.Pin(25, machine.Pin.OUT)

# Infinite loop to blink the LED
while True:
    led.toggle()     # Change LED's status
    time.sleep(0.5)  # Wait for 0.5 seconds

I then changed to code to reflect that the simulator LED was connected to pin 1 and ran the same program with my change.

import machine
import time

# Set pin 1  as an output
led = machine.Pin(0, machine.Pin.OUT)

# Infinite loop to blink the LED
while True:
    led.toggle()     # Change LED's status
    time.sleep(0.5)  # Wait for 2 seconds

And then got the following result

My process was to use the micropython programms Now I want to learn how to connect a pushbutton and turn a motor on, have it run for a set time and then turn off. This is what I need for my final project, but I may need to come back to this later.

Group assignment

In the group assignment we each selected our own microcontroller to study and since I used the Raspberry Pi Pico in the individual assigment I also used it for the group assignment. I googled and browsed through the datasheet to find specifications that we put into a comparison table for the microcontrollers. I was then able to connect the Raspberry Pi Pico to my computer and turn on the built in LED by using the following program that I found here

from machine import Pin

led = Pin("LED", Pin.OUT)
led.on()

and then I changed the code in Thonny to have it turn on for 5 seconds, stay on and then turn off again.

code

The process is that you have to reboot it using a bootsled button which turns it into a USB memory device. You then can load micropython on to it and run programs as the one listed above to blink the built in LED in different ways.

The remainder of the group assignment is linked here