Week 4: Embedded Programming¶
Week 4: Embedded Programming¶
Task: Embedded Programming
Group assignment:
Demonstrate and compare the toolchains and development workflows for available embedded architectures
Document your work to the group work page and reflect on your individual page what you learned
Individual assignment:
Browse through the datasheet for a microcontroller
Write and test a program for an embedded system using a microcontroller to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)
Hello and welcome to week 4! This week we are learning Embedded Programming. My goal was to write a program that can turn a light on or off with the push of a button.
This is my ver first foray into programming! I don’t know that most of the words people are using mean!
To start off, lets get some basic anatomy and definitions here.
microchip microcontroller pins soldering RAM Devboard Syntax Arduino
The microcontroller that I am using is called “RP2040 Zero”. You can view its datasheet here.
First you must download an IDE,Integrated Development Environment, that allows you to program a microcontroller. I used Thonny which is an IDE that uses the programming language Python.
At thie core, computers are very dumb. Their language is composed of only 0’s and 1’s. A computer and computer program will only do exactly what it is told. It is up to you, the programmer, to figure out how to communicate to the CPU.
Luckily, someone much smarter had gone through the process of creating a Programming Language, this allows you to type using a certain syntax or patter, that then get interpreted into those 1’s and 0’s. We are so blesed to have access to this cumulative knowledge, and for FREE!
So download thonny.

Next, plug in your rp2040. Hold down the reset button, then the boot button. Then release the reset button and the boot button in that order.
next in the bottom right corner click the button that says “no backend”

There are 2 drop down boxes. Select “MicroPython (RP2040)” and “Try to detect port automatically”
Then on the BOTTOM RIGHT corner, DO NOT hit “OK”. Instead, click “Install or update MicroPython”

There’s a few more dropdowns. Select “RPI-RP2” and “RP2” and “Raspberry Pi Pico/Pico H” and “1.27.0”
Then click Install

On Thonny, there are 2 main areas to type in. The upper part is where you write code. The lower part, the Shell, works as a terminal and also give you handy info if something in your code is not working.
Test to see if your mircocontroller is working by typing EXACTLY
- print (“Hello Friend”)
and hitting enter. You should get a response right below is with the words “Hello Friend”
Python is a Case sensitive language. This means letters that are uppercase and lowercase are read as seperate characters. “machine.Pin” and “machine.pin” will be read as two entirely seperate things.

Alright it’s working! IDK how to fix it if it isn’t so good luck.
Next we are going import some libraries! Libraries are pieces of code that have already been written. This makes the process of coding much faster as some of it has already been done for us.
!Fun Tip! You can access the libraries by ctrl + click on them!
For those of you that are low vision (me). I will write out the grey text in the photo above. Some words will be changed. Notice how different parts of code are in different colors! If you want to write a comment that doesn’t affect your code, simply type a # in the front. import machine #give us access to control pins import neopixel #give us access neopixel objects, the LED on the rp2040 is a neopixel *import time #gives us access to the time.sleep function.
“import” is the command we are giving. “machine”, “neopixel”, and “time.sleep” are the names of the libraries we are importing.
You may notice the words “neopixel objects” in the above explination. An “object” is something that we can assign and refer to in code that will always follow the same rules.
Net up is this fancy line of code. I will break this down piece by piece.
*Pixel_pin = machine.Pin(16, machine.Pin.OUT)
Pixel_pin is the name of an object
the symbol = means that we are asigning meaning to that object.
machine.Pin means we are refferring to the machine library to access a pin.
(16, machine.Pin.OUT) is us telling information about what we want the pin we are accessing to do. the 16 is the pin number. The LED we want to control is on pin 16. we know this by accessing the datasheet. machine.Pin.OUT mean that we are saying that the pin will be outputting information.
PLEASE keep in mind that CAPITALIZATION MATTERS!

next is * num_pixels = 1
num stands for number, and we are saying that there is only 1 led.
now let’s get real fancy
*np = neopixel.NeoPixel(pixel_pin, num_pixels)
“np =” we are defining what the letter np mean
“neopixel.NeoPiexel” we are accessing the neopixel library and using the object called “Neo.Pixel”. Notice how the capitilazations of their letters makes them different inputs.
“(pixe_pin, num_pixels)” The object NeoPixel needs to have defined the LED’s pin, if its an output, and how many of them there are. Notice how we are using the term we have already assigned!

The goal is to create a blinking light. I use this bit of code.
“while True: “is how we start a loop! please keep in min that only the T is capitalized and you need a colon. Also, formatting matters! you hit “tab” to indent the next few line of code
the 0 in np[0] is the LED. There is only 1, but we start with the number 0. It is the first in the chain of 1.
Next you see 3 numbers. these represent the Red, Green, and Blue, or RGB Values. Inside the LED there are 3 tiny lights, red, green and blue. These lights can change in intensity from the numbers 0-255. Please keep in mind we are using Additive Colors, so if the values of all 3 are the same, they make white.
np.write() means that we are saving the values
time.sleep(1) DOES NOT determine how long the light stays off, but how long it will stay on. The datasheet says the rp2040 measures in seconds.
I repeat these three lines and play with the values to get different colors.
If you typed in all the code correctly, it should work! if it doesn’t:
check your spelling check the capitalization check the indentations check that you used the correcr punctation
Usually the shell will give and error and a hint to what line may be wrong. How helpful :)
programming a button¶
ALRIGHT BABY ITS TIME TO TRY CONTROL A LIGHT WITH A BUTTON

First, you connect your RP2040 to a breadboard.
Next I plugged it into my computer.
Let’s test and see if the breadboard is getting power!
I ued this circut and BURNED OUT my LED. It made a hissing sound, was glowing red in the center, and smelled like plastic. All bad signs.
I contacted my instructor to ee what I did wrong. I thought I had short-circuted the poor thing.
Turns out my circute was fine! I just needed a resistor. I was giving the LED WAY too much power and that’s why it burned out.
we used the equation V = I * R
If I understood it better I wwould explain it. but I don’t. I know how to use it but I till haven’t figured out what it means. I think my brain just needs time to process.
Just know the RP2040 outputs 5V and that LED’s use 2V and I used a 330Omega resistor.

I also wired a button to Pin 7! It is seperate from the wiring used for the LED. We want these circuts to be seperate.
import machine import neopixel import time
pixel_pin = machine.Pin(16, machine.Pin.OUT) Num_pixels = 1
button_pin = machine.Pin(10,machine.Pin.IN, machine.Pin.PULL_UP) #new line creating button pin input object
np = neopixel = neopixel.NeoPixel(pixel_pin, Num_pixels)
color = 0
while True: while button_pin.value: color = color + 1 np[0] = (255, color, 0) np.write() time.sleep(.001)
np[0] = (0,0,0)
np.write()
using the code made perviously as a base, we changed and added some values
first we need to define the pin that controls the button
next we need to know if the button was pressed, we use the code
As of right now, we did not get this to work. Here’s where we left off. I swear we are about 3 line of code away from figuring it out.
Files¶
Copyright 2026
Source code hosted at gitlab.fabcloud.org