Week 4: Embedded Programming


Group Work: compare workflows for available embedded architectures


RP2040 DataSheet

The RP2040 Datasheet gives full information about the RP2040 Microcontroller. Here's some relevant information gleaned:

Here's information about the name "RP2040"

Here's a detailed overview of the chip:

Many things here I don't know what they are, for example:



Here's the pinout of the RP2040. Note that specific development boards can use more or less of the pins.

The Xiao-RP2040 has fewer GPIO than the Raspberry Pi Pico, though they both use the same Microcontroller!

In summary the chip, the microcontroller is amazing. So much packed into such small size. I'm learning a lot.

Some additional questions worth asking:



Programming SEED RP2040 with Thonny:

Thonny is a Python IDE. Search for, download and install that is easy.

As a group in Kochi we read and followed this documentation. which was extremely helpful.

We made some simple programs like the following, mainly using the built-in LEDs.

There were some difficulties, most important to note is that the MicroPython interpreter needs to be installed on the RP2040.

You will need to do it again if the same microcontroller is used with Arduino code, since it compiles and sends there hex code.



Programming simulated Arduino (WOKWI):

Here is a simple program, goal being to understand "INPUT_PULLUP" and its importance:

Basically pullup is a directive to internally connect the pin to power through a resistor.

In this follow-up program, the LED is toggled by the 2nd button, but it's not possible by the first button because it is not "pulled-up" and hence unstable.

We as a group in Kochi stopped using Arduino in Wokwi because it would often fail to run.



Programming simulated Raspberry Pi PICO (WOKWI):

Here is a first simple simulation. Started with the LED program, and added a switch:

And here's the simple code. If you flip the switch the light goes out:



A better simulation project with Raspberry Pi Pico

We will need a more complicated and interesting project. Let us choose the following input and output:

INPUT: Ultrasonic

OUTPUT: OLED and Step-Motor


Getting Started

We will start with an empty project, then search and import needed code. All we did is rotate the board by pressing 'R'


Ultrasonic:

Let's start with Ultrasonic. We import libraries, define pins, and wire the ultrasonic to the board.

Now we import and test a function for the ultrasonic we found from Tom's Hardware. It works!


OLED:

Then we connect the OLED, and include a library "ssd1306.py" which we copied from another OLED program on Wokwi.

From there we additionally must include a function for the communication protocol which is difficult to understand.

We add lines to the Ultra function to print to the OLED. We also define SDA/SCL pins. And it works alhamdulillah!


Stepper Motor:

We wire up the Stepper Motor, however our example code is only in Arduino, so we must research how it can work in Micropython.

With some difficulty, research and help from perplexity.ai, we got the code working just for the single step motor to work.


Final stage - bringing it home.

Final step is to bring this separate code for the stepper motor into our main program with the ultrasonic and OLED screen:

Everything seemed to be fine, but the stepper motor didn't move! Turns out we forgot the reset-sleep connection on the driver.

After we fixed that connection on the motor driver, everything worked fine. Let's end with a diagram of the driver to understand it better:


When I prepared to make a video, there were a couple imperfections, namely that the motor didn't reverse and part of the OLED display did not clear, but I was able to fix these coding issues and then make a screen recording: