This week I learned what embedded programming constitutes.
Group assignment: demonstrate and compare the toolchains and development workflows for available embedded
architectures
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)
extra credit: test it on a development board extra credit: try different languages &/or development
environments
RP2040 is a low-cost, high-performance microcontroller device with flexible digital interfaces. Key features:
This diagram shows the system overview of the RP2040 Microcontroller
Some of the features of rp2040 include:
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
Pinout Diagram
A "pinout diagram" is a diagram or list that shows the arrangement and function of the pins (or terminals) on an
electronic component or connector,
helping users understand how to connect and interact with the device.
Shown below is the pinout diagram of a xiao rp2040 microcontroller.
XiaoRP2040-pinout
Understanding Arduino IDE and Micropython
Micropython
MicroPython is a lightweight version of Python designed for microcontrollers, while Arduino IDE is a
platform for writing and uploading code to Arduino boards, typically using C/C++.Allows for easy interaction with
hardware through GPIO pins,
sensors, and actuators.
Arduino IDE
It is a software environment for programming Arduino microcontroller boards.
Arduin IDE provides an easy-to-use interface for writing, compiling, and uploading code to the board.
It is widely used in hobbyist, DIY, and educational projects for electronics and robotics.
It includes very helpful libraries and built-in functions to get started with a program and simplifies hardware
interaction.
Programming
This week i tried to learn how to program a microcontroller using Arduino IDE (C/C++) and Thonny
(MicroPython).
To understand how to write the code we tried write simple code to function an LED.
Trying out WOKWI
WOKWI is an online simulator for microcontrollers, allowing users to test and
debug embedded systems without needing physical hardware.
It supports various microcontrollers, including the Raspberry Pi Pico, Arduino boards, and ESP32,
along with virtual peripherals like LEDs, buttons, sensors, and serial monitors. i tried to simulate and learn
basic codes to work a circuit.
. Open Wokwi and make an account for yourself and add a new project
Select Pico as Microcontroller. Also select the language as Micropython.
A templete with the raspberry pi board will appear on the screen along with a window on the left for writing
the code.
Now we can add components and write codes to simulate an action. Since this was the the first time i was doing
this i went with a simple circuit
containing a LED that will turn on with a push button switch.
So i placed an LED on to the board and connected its ends to a ground pin and another available pin. You can
customize the colours of the LED too.
Similarly add a push button switch to the circuit
Now that the components are set up we need to write the code to make it work the way we need it to.
First i tried to write the code using micropython.
we need to import the required libraries into the code using the import command. in this circuit we we need to
import pin and time.The Pin
function lets us use the GPIO pins from our microcontroller.The sleep functionis imported to add a delay to the
program.
Now we have to set up the pins and name the variable. Here we need to define that the Led is an Output.We also
define the button as an input.
Trying out Thonny
i was taught how to use thonny as it was my first time using it. Since it works on Micropython the commands were similar to how it was in Wokwi.
I had to install thonny to my laptop first. I used the PCB that i made during the Elecronics Week to make the test code to make the Led blink with a switch.
from machine import Pin
from utime import sleep
print("Hello, Pi Pico!")
led1 = Pin(3, Pin.OUT)
led2 = Pin(29,Pin.OUT)
button = Pin(2,Pin.IN)
while True:
if button.value() == 1:
print ("button on")
led1.value (1)
led2.value(1)
sleep(0.1)
led1.value (0)
led2.value(0)
sleep(0.1)
else :
led1.value(0)
led2.value(0)
Here i first imported the Pin function from the machine library and the sleep function from the utime library. The rest of the code was done similar to how i wrote it in WOKWI.
I set the led variable to their corresponding GPIO pins. In this case the pin for led1 was 3 and for led2 was 29.
Then using the while loop if conditions were set for the led to blink. Whenever the button value is 1 (i.e switched On) the led will turn on and then goes to sleep(by setting the sleep function to 1millisecond) for a 0.1 s and turns back on.This will keep happening in a loop when the button is pressed.
Using Arduino IDE
I had to install Arduino IDE first as this was my first time using it.
I felt like the interface of this software was quite easy to follow and there was a lot of refrence libraries and example codes to use and follow.
I used an Arduino Uno board and attached a power led to it used a example code to blink the LED.To get the example code first go to file >> Examples >> Blink
We need to setup the New sketch according to the board that needs to be programmed. Go to tools >> select board >> choose the board you will be programming (in this case Arduino Uno).
Next choose the port to which the board is connected.
We also need to set the programmer . Then we click on burn bootloader.
Now you can compile the sketch to check for any errors made while writing code (such as missing a library or missing out on putting the';" after a declaration ).Then we can upload the code to the board.
We can see the output on the serial monitor so that we can observe how the board responds to the code.