Week 3 - Embedded Programming

Preparation and Final Project Considerations: #

This weeks lecture left me more confused that I’d hoped for and since I’m new to pretty much everything in class I wanted to prepare myself for the week ahead. As such, I’ve been talking with ChatGPT in order to use this week to plan for my final project. I’ve been asking questions like:

  • “okay so i want to build a street brick with embedded electronics. i think i want ot be able to communicate with the electronics so that they can display a message on an e-ink screen or pontially just light up some led lights. can you tell me which microcontroller i should use?”
  • “would one of these microcontrollers work well with a small solar panel or battery for this street brick?”
  • “im confused- how would i interact with the e-ink screen? would i just initially setitup with a program? what does it mean to set it up with a program and am i even saying this correcly? also what is BLE?”

From the AI responses I’ve received, and by browsing through websites from last year’s students, I’ve gathered that I will need to select a microcontroller with the capabilities necessary for my final project. It’s seeming like I should use either an nRF52840 or ESP32 microcontroller. The former allows for BLE (bluetooth low energy), has a 1-3 µA sleep current, updates with a gateway (like a phone), and would allow for a long battery life, while the latter is BLE and Wifi compatible, has a 10–150 µA sleep current, and would allow for a moderate battery life.

Embedded Programming #

This week, we were given a range of microcontrollers that we needed to solder. Being new to this process, I chose the simplest board, the QPAD21. Fortunately, I found the soldering process to be rather easy and didn’t bump into any issues of bridging. The one trouble I had was too much solder collecting on the iron, which I could have corrected by cleaning off the soldering tip more frequently. With two resistors, the XIAO RP2040, and an OLED graphic display successfully soldered, I was able to get some help understanding what all of this meant.

The first step in this process was downloading Arduino IDE, a free open-source software used to write and upload code to microcontrollers (according to Google a microcontroller is a self-contained computer on a single integrated circuit and combines a CPU, memory, and input/output peripherals). In the Preferences menu, I added this URL to the ‘additional boards manager URLs’ section on the bottom of the pages. From there I went to Sketch > Include Library > Manage Libraries and added the library for “Adafruit SSD1306,” which would allow my RP2040 to talk with the OLED screen’s display driver (SSD1306). This is essentially a bunch of C++ code known as a class. Under the ‘Select Board’ drop down menu, I typed in RP2040 and selected the Seeed Xiao RP2040 and chose the COM3 Serial Port (USB).

With all of this code installed, I navigated to a (Quentin Bolsee’s Github page)[https://gitlab.cba.mit.edu/quentinbolsee/qpad-xiao/-/tree/main/code/Arduino?ref_type=heads] because it had sample code that I could upload to my RP2040. I initially chose the “blink_RP2040” folder, downloaded the .ino link, and when I clicked on it, it opened up in Arduino. I then plugged in my device, pressed the upload arrow in Arduino, and after a few moments of ‘compiling sketch’ my board was blinking. Afterwards, I selected the test_display code and got that to successfully run as well.

Final Product

Development Workflow - Group Assignment Contribution: #

  1. Open Arduino IDE.
  2. Nagivate to FIle > Preferences then paste the following link into the “additional board managers URL” -> https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
  3. Navigate to Sketch > Include Library > Manage Libraries. Search for and add “Adafruit SSD1306.”
  4. Under the ‘Select Board’ drop down menu, search for and select “Seeed Xiao RP2040,” then choose the appropriate and port.
  5. Connect the QPad, and input code from the following link -> https://gitlab.cba.mit.edu/quentinbolsee/qpad-xiao/-/tree/main/code/Arduino?ref_type=heads
  6. Click the upload arrow.
  7. Observe changes and debug as necessary.
Vinyl 2 Vinyl 3

The Final Product: #

Snake C++ Code #

By referring to the display touch sample code, and by referring to Xiao RP2040 pinout diagram for the appropriate capacitive touch pins, I was able to guide ChatGPt through making a successful Snake game. My prompts included things like “based on this following code, build me a snake game for my RP2040,” “explain to me why the snake isn’t matching up with the food,” and “how do i make the snake slower and smaller.”

Given that coding is new to me, this process helped me to get a better sense of how more complex code is working. I was able to troubleshoot how to make the game slower, how to make the snake shorter, and how to ensure the touch pads matched up correctly on the QPad.

Snake

Download Snake Code for QPad/Seed Xiao RP2040

HID Keyboard #

I wanted to see what else is possible with the RP2040 microcontroller and found out that I can use it to communicate with my computer. In order to get a better sense of how to work with C++, I spent more time asking ChapGPT to explain the response to the prompt “write a code so that I can communicate with my computer. i want to be able to press one of the pads and type something in.”

Download HID Code for QPad/Seed Xiao RP2040

Notes: #

Office Hours Notes: #

void → return nothing

setup → special function that happens once

loops → function that happens over and over

pinMode → takes pin as input to function

pullup resistor → allows you to define if something is on or off

digitalwrite → sets a pin a high or low

associate pin name with a number

-this allows you to change the number later

// → comment

/* → block comment

if () → e.g. variable==true; number<6

→ e.g. if(PIN_RED==17){ do ___}

for() → e.g. (int i=0; i<17;i++){Serial.println(i); delay(10); }

while() → loop that i dont want to get out for a while until something interesting happens

—> i ++ = integer plus 1

  • use serial monitor on the top right corner to see what the monitor should be doing

Class Notes: #

Here are some notes from this weeks presentation.

Use https://wokwi.com/ to simulate boards

  • little tiny processors
    • registers → instructions
    • SRAM - fast
    • DRAM - big
    • EEPROM -

the order of the diagrams does not match what is there in reality!

ground = zero volts (because we’ve agreed that it is; its used as a baseline)

  • ground is not a physical thing its more of a concept

trace = strip of copper connecting things

components:

  • usb input
  • volt regulator → changes input to the voltage needed by the microcontroller
  • bypass capacitor → stores charge (like a little battery)
    • if you keep adding bypass capacitors or bigger ones the variance goes down, making the system more stable
    • filters out noise in voltage
    • Omhs are units of electrical resistance
  • resistor → slows down current
  • LED → light emitting diode
    • diode → one way valve for electrical current
    • data sheet provide forward voltage and forward current
  • header → place to plug things in
    • can talk to microcontroller i.e. telling mc how to speak USB
  • microcontroller
    • has pins that match up to different functions
  • buttons = not a good capacitor?
    • if you can change capacitance you can change rise time
    • what is capacitive sensing
  • Mosfets → turn on or off when input voltage is high (think of as digitally controlled switch)
    • type of transistor
    • allows microcontroller to control big power
    • like a water faucet for electricity:
      • The source is where the electrons come from.
      • The drain is where the electrons go.
      • The gate is like the faucet handle — you don’t touch the water directly, you just turn the handle to let water flow.

I = current in amps

R = omhs (resistance)

v = voltage

v= ir

oscilloscope → tool to measure voltage

  • shows variance and average

difference between voltage and current?

  • Voltage = the force that makes things want to move.
  • Current = the movement itself.