Skip to content

Week 4 Noah, Angel, Cooper, Elle

Overview

Name Assignment
Angel XIAO RP2040
Cooper XIAO ESP32-C3
Elle Arduino Uno
Noah ATtiny 412

RP2040 – Angel Fang

XIAO RP2040 with C++

Step 1: Wokwi Simulation

Since Wokwi does not have RP2040 as the chip, I used Raspberry Pi Pico instead because they are very similar. I used the pinout of Pi Pico to build the simulation. Then I asked ChatGPT to write the code for me.

C++ Code for RP2040:

const int buttonPin = D1;  // Button connected to pin D1
const int ledPin = D2;     // LED connected to pin D2

void setup() {
  pinMode(buttonPin, INPUT_PULLDOWN);  // Set the button pin as input with pull-down resistor
  pinMode(ledPin, OUTPUT);             // Set the LED pin as output
}

void loop() {
  if (digitalRead(buttonPin) == HIGH) {  // If button is pressed (HIGH due to pull-down resistor)
    digitalWrite(ledPin, HIGH);          // Turn LED on
  } else {
    digitalWrite(ledPin, LOW);           // Turn LED off
  }
  delay(100);  // Small delay to avoid excessive CPU usage
}

Then I got this:

Step 2: Development Flow for Arduino IDE

I used the same circuit as ESP32-C3. I just replace the C3 chip with RP2040.

I followed this tutorial to set up the board in Arduino.

I went to File –> Preference and copied the Board URL the tutorial provided me to the Additional Board Manager URL

Then, I went to Tool –> Boards –> Boards Manager and searched up RP2040. I downloaded the “Pi Pico/ RP2040” one since it included RP2040 while I can program Pi Pico using that board manager as well.

I selected RP2040 as my board.

Then I select the right port. Usually it is any port other than COM1

Notes: Never use COM1 as your port!

Then I copied the code into Arduino. However, I needed to chnage the pins in the code since I needed to use the pinout of RP2040 other than Pi Pico.

I uploaded the modified code and then my LED worked!

XIAO RP2040 with MicroPython

Step 1: Wokwi Simulation

I asked ChatGPT to generate the MicroPython code for me. Then I copied the code into Wokwi to check if the code worked. I still used Raspberry Pi Pico for the simulation

Micropython Code for RP2040

from machine import Pin
import time

buttonPin = Pin(3, Pin.IN, Pin.PULL_DOWN)  # Button connected to GPIO 15 with pull-down resistor
ledPin = Pin(5, Pin.OUT)  # LED connected to GPIO 14

while True:
    if buttonPin.value() == 1:  # Button is pressed (1 because of pull-down resistor)
        ledPin.value(1)  # Turn LED on
    else:
        ledPin.value(0)  # Turn LED off
    time.sleep(0.1)  # Small delay to avoid excessive CPU usage

Step 2: Development Flow for Thonny

I used the same circuit as ESP32-C3

Then I started to set up Thonny using this tutorial.

Fisrt, I went to Tools –> Options –> Inerpreter and then selected the correct interpreter and port

Next, I connected RP2040 with USB C cable. Be sure to hold the “B” button on RP2040 to make it in Bootloader mode.

Then, I went to “Install or update MicroPython” and then select the folowing options.

After clicking “Install”, I copied the MicroPython code into Thonny and then click the green button on the top (“Run” Button)

Then I got this!

Toolchain for Rp 2040

Toolchain used to be a really important part for coding. Nowadays, we have so many well-developed softwares like Arduino IDE and Thonny that we don’t actually need a toolchain anymore.

But I can still say my toolchain for programming rp2040 with C++ code is : Arduino IDE –> Board: Seeed XIAO RP2040 –> Port: COM5

My toolchain for RP2040 with MicroPython is : Thonny –> Interpreter: MicroPython (Raspberry Pi Pico) –> Port: COM5 –> Target Volume: RPI-RP2 (E:) –> MicroPython variant: Raspberry Pi Pico/ Pico H

ATTiny412 - Noah Smith

Step 1: Wokwi Simulation

while wokwi doesn’t display the fact that it supports an attiny chip, a google search reveals that it has simulator using an ATTiny85 chip. While this chip is not the same as the one im going in depth on, it has the same pins and therefore can be used as a rough simulation in wokwi. In a simulator, the ATTiny is very easy to work with, however in real life that isn’t the case.

Development flow with arduino

If you actually want to do this, please check out Teddy Warner’s documentation on it, but im going to give a very summarized explanation of the first upload to an attiny Attinypinout


If you look at the attiny, you can see that it has 8 pins, and 2 are required for power. the ATTiny is special in that it uses UDPI to upload, instead of a simple usb to serial converter like the other three microcontrollers here. this means that it only needs one wire for communication (yay) but requires a much more complicated uploading process (boo)

Again, look at Teddy Warners documentation for how to actually do this, but here is a very generalized workflow

  1. Install MegaTinyCore. just like esp32 core or the pico-sdk it is what allows the attiny to be coded using c++ instead of straight assembly.
  2. Upload the JTAG2UDPI sketch to a supporting device. In our testing, we used an Arduino uno, but it just has to be any board that supports UDPI physically.
  3. Wire the board with the JTAG2UDPI to the ATTiny. this means connecting their ground and vcc, and then connecting pin 6 to UDPI, which is the pin two spaces away from the GND pin

Comparison with the others

compared to the other boards in this page, the ATTiny is the slowest, most annoying to work with, and smallest chip.

Pros:

  • low power, around 11 ma when running full speed
  • small, its limited io also allows it to be very compact
  • cheap, around 50 cents per chip

Cons:

  • slow, only 20mhz, nothing compared to the over 200’s that the newest esp32 and pico chips can get
  • really annoying to work with
  • 4 gpio pins
  • limited connectivity, only supports i2c, spi, uart
  • limited storage, 2kb of program memory, 128 bytes of flash

Overall, the ATTiny is perfect for small projects that require the smallest amount of logic or special peripherals

Micropython with the ATTiny

While the rp2040 and esp32-c3 support micropython, the arduino uno and ATTiny do not. This is due to the fact that micropython is about 400kb to just have the basic commands with no actual program, and the both chips have way less then 400kb of program memory

ESP32C3 - Cooper Cumbus

Arduino

  1. Write your code in Arduino in the code language CC+ and plug in the ESP into the computer

  2. Click on the tools tab and if need go to library manager to add the nessicary libraies for the code. Afterwards select the board tab. If you don’t have the esp board tab go to the board manager and type into the search board ESP. For the XIAO ESP32C3 it is closer to the bottom compared to the top so it will take a while to find.

  3. While under the tool tab go over to the port tab and find the port that the ESP is plugged into. For a mac make sure its not either of the bluetooth ports and for a desktop computer make sure it isnt com 1.

  4. Once all that is done under the tools tab you can either verify the code or imideatly upload it since the upload also verifies the code.

MicroPython

  1. The first thing you have to do is download the latest firmware for the ESP32C3 on the Micro Python website.

  2. After you do that you nedd to make sure you have esptool installed through python. This requires the downloading of python to do so. This is required so that your able to flash the firmware directly to the ESP32C3.

  3. Once you have that done check the port that your ESP is plugged into using the command: ls /dev/cu.*
  4. With this command you can erase the flash memory of the ESP if nessicary with this command: esptool.py –chip esp32c3 –port /dev/cu.usbmodem14201 erase_flash (Its nessicary when you have already uploaded code to the ESP already in any way.)
  5. Once that is done you can flash the firmware to the ESP with this command: esptool.py –chip esp32c3 –port /dev/cu.usbmodem14401 –baud 460800 write_flash -z 0x1000 ESP32_GENERIC_C3-20241129-v1.24.1.bin

Arduino Uno - Elle Hahn

This is a basic pinout for an Arduino Uno and the one I used to build my circuit.

Arduino

For the Arduino Uno I followed the same steps as the Seeed Esp32C3 and used simular code. For the Esp32C3 I had to change the code a little bit from the TinkerCad code but when I went back to tinkerCad for the Ardunio Uno, I noticed that the simulator was alreay using an Arduino Uno. This meant that I could copy and paste the coded exacly.

One thing I noticed I did need to change is that the code provided used the built in LED on the board. I didnt want to use that LED, and I wanted to use an actual LED, therefore I added an LED to the breadboard. Then I pinned it to number 3 on the board and changed that in the code. After that I had to fugure out my port. I wasn’t sure what COM I was using so I tested all the choices until I figured out I was using COM 7. Once I had that set, I uploaded it and it worked.

// Define the pin number (change this according to your setup)

int buttonState = 0;

void setup()
{
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
}

void loop()
{
  // read the state of the pushbutton value
  buttonState = digitalRead(2);
  // check if pushbutton is pressed.  if it is, the
  // buttonState is HIGH
  if (buttonState == HIGH) {
    // turn LED on
    digitalWrite(3, HIGH);
  } else {
    // turn LED off
    digitalWrite(3, LOW);
  }
  delay(10); // Delay a little bit to improve simulation performance
}

Code for Arduino Uno

Comparison with the others

Compared to the other boards, the Arduino Uno is the most popular one for beginners because its eazy to use.

Pros:

  • Easy to use and beginner-friendly
  • Affordable & Widly Available
  • Reliable and Stable compatible with a wide range of sensors and modules

Cons:

  • Limited Prossesing Power
  • Limited Analog and Digital Pins: 14 digital I/O pins and 6 analog inputs
  • Power Limitations: Runs on 5V
  • slower than ESP32 or Raspberry Pi

Last update: February 19, 2025