Skip to main content

Week 2: Embedded Programming and Microcontrollers

·212 words·1 min
Sophie Fan
Author
Sophie Fan

Can I Write Assembly? At All?
#

Group Lesson
#

For our group lesson, we went over three different microcontrollers: the ATtiny (Tiny412), esp32, and the rp2040.

Some differences noted:

ATtiny:

  • needs external bootloader
  • can code with Arduino IDE
  • no micropython (easy way)

esp32:

  • wifi and bluetooth
  • has its own bootloader
  • can code with Arduino IDE
  • support for micropython!

rp2040:

  • has its own bootloader
  • can code with Arduino IDE
  • support for micropython!
Capacitance Sensors on esp32 Configuring ATtiny chip in Arduino IDE
Photo credits from Michelle

Individual Assignment
#

For this week’s assignment, I wanted to try to write something in micropython, and also Assembly (channel my inner Neil??) I feel pretty comfortable with python and C++, but I wanted to challenge myself and try something low level.

First I wanted to warm-up with micropython. After reading some documentation on the PWM library, I have wanted to try using PWM to control a servo:

from utime import sleep
from servo import Servo

pwm = PWM(Pin(15))
pwm.freq(50)

while True:
    
    pwm.duty(26)
    time.sleep(1)
    pwm.duty(120)
    time.sleep(1)

Here, using wokwi to simulate:

I used a 50 frequency and different duty cycles to try controlling the servo.

I also wanted to try simulating it with micropython so I used an IDE called Thonny.

Here it is on Thonny:

alt text