Skip to content

5. Embedded Programming

Coding the Esp32-C3

We used the Xiao Esp32-C3 for this week. I find that the Xiao chips are really simple to use after you have a good look at the pinouts first.

Wokwi

Before we used the real chips, we used Wokwi to simulate them on the computer to make sure everything was going to work.

This is the code we used:

const int buttonPin = D0;     // the number of the pushbutton pin
const int ledPin =  D1;      // the number of the LED pin

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED off:
    digitalWrite(ledPin, HIGH);
  } else {
    // turn LED on:
    digitalWrite(ledPin, LOW);
  }
}

This part went pretty smoothly, I only struggled with the wiring, which was then fixed after some trial and error.

Coding in C++

I’ve coded Xiao Esp32s in real life when I was in an Electrical Engineering class trying to make a remote control car.

The code for this was fairly simple. All I had to do was copy and paste the code from Wokwi

Picture of code:

Coding in MicroPython

MicroPython was a really interesting experience. All of the frustration I had was with downloading the libraries, but when it came to actually coding I found it really easy.

I used these tutorials to get everything downloaded and set up. Once I did that I pasted my C++ code into ChatGPT and used it to change it into MicroPython code.

I found that the code refused to go to the C3. So I had to reflash it, which then let me insert my code to the chip.

Video of it working (Looks the exact same in C++):

Coding the RP2040

We used the Xiao RP2040 for part this assignment. I’ve used this chip before in an engineering course I took last year.

Since the pinout is the exact same as the Esp32-C3 I could just replace the chip on the bread board instead of changing the jumper wire location.

Coding in C++

Coding in C++ was very straight forward and simple, as I have done it before. I followed these tutorials step by step to get the library onto my computer which was really simple.

I had no issues getting the code to work, and was suprised when everythign worked first try. I immediatley took a video of it because I didn’t want to give it a chance to break before I got proof it works.

Picture of code:

Coding in MicroPython

MicroPython was a really interesting experience. All of the frustration I had was with downloading the libraries, but when it came to actually coding I found it really easy.

I followed these tutorials step by step which was really simple. After I setup my interpreter, I relized that the Xiao RP2040 uses the exact same pins as the Xiao Esp32-C3 and I skipped the ChatGPT step I used with the last controller and it almost worked flawlessly.

The only major issue I faced this unit was when I tried to use the Thonny interpreter to flash my RP2040 I was not letting me install it. To fix this I pressed boot on the RP2040, and reopened thonny, which resolved my issues.

Picture of code:

Video of it working (Looks the exact same in C++):

Coding the Arduino

Arduino was probably the easiest microcontroller to code. While the Xiao chips also run on C++, the Arduino UNO has its own IDE which means that you don’t have to download anylibraries to get started. Plus the labeling on the pins make it very convinient to use, as I’m not looking through a pinout sheet while wiring up or coding the board.

I just used the Arduino IDE and wrote the code in C++ before checking the for the correct COM port and then uploading it.

Video of it working:

Coding the ATtiny 412

Looking Through the Datasheet

The data sheet I looked at was the one for the RP2040. Looking through the data sheet I found out some information.

  1. What Chip?

    The chip is the Rp 2040.

  2. What speed?(Indicated in MHz)

    The speed of the RP2040 runs up to 133 MHz.

  3. What flash/SRAM memory (for storing programs)?

    SRAM: 264kB on chip, divided into six banks. Flash: Supports up to 16MB of off-chip flash memory via a dedicated QSPI bus.

  4. How many GPIO pins?

    There are 30 GPIO pins.

  5. How many analog pins?

    There are 4 analog inputs.

  6. What communication protocols does the board “speak” (UART, ISP, SPI, I2C, 12S, ect.)?

    2 UARTs, 2 SPI controllers, 2 I2C controllers, USB 1.1 controller and PHY, with host and device support.

  7. Does it have an ADC?

    Yes, it does.

Software Used

Datasheet

Tutorials Used

People who Have Helped me

Here


Last update: February 19, 2025