Skip to content

week4. Embedded Programming

Assignment

Group assignment

  • demonstrate and compare the toolchains and development workflows for available embedded architectures

Individual assignment

  • browse through the data sheet for your microcontroller
  • write a program for a microcontroller, and simulate its operation, to interact (with local input &/or output devices) and communicate (with remote wired or wireless connections)
  • extra credit: test it on a development board
  • extra credit: try different languages &/or development environments

Group assignment

For more information about group projects, please see the group project page on the FabLab Kannai website.
Group assignment page is here

Microcontroller RP2040 datasheet

I read the RP2040 datasheet while considering the specifications of the microcontroller needed for the [Golgo 13 Machine] (../final-project.md) that I will create for my final project.

Data Sheet Overview

1. Overview

  • Processor core: Dual-core ARM Cortex-M0+
  • Clock frequency: Up to 133 MHz
  • On-chip memory: 264 KB SRAM
  • External memory: QSPI flash (up to 16 MB)

2. Power Management

  • Operating voltage: 1.8V to 3.3V
  • Low-power modes: Supports multiple power-saving modes

3. Input/output (I/O)

  • GPIO pins: 30 digital I/O pins
  • PWM channels: 16 channels
  • ADC: 3 channels of 12-bit ADC
  • I2C: 2 I2C controllers
  • SPI: 2 SPI controllers
  • UART: 2 UART interfaces

4. Clocks and Timers

  • Internal clock: 12 MHz RC oscillator
  • External clock: External crystal or clock input (max. 24 MHz)
  • Timers: 4 multi-channel timers

5. Debugging and Programming

  • Debug interface: SWD (Serial Wire Debug)
  • Programming interface: Bootloader via USB or UART

6. Peripherals

  • PIO (Programmable I/O): Two independent PIO blocks, each block with four state machines

7. Power consumption

  • Operating voltage: 1.8V to 3.3V
  • Power saving mode: Supports multiple power saving modes

RP2040 Performance Assessment

The Golgo 13 Machine I am creating for my final project will receive information from the millimeter wave radar using the RP2040 and transmit it to a smartphone via WiFi. In conclusion, I found that the performance of the RP2040 is sufficient for transmitting information from the millimeter wave radar via WiFi. The details are as follows.

  1. Dual-core processor:

    • The RP2040 is equipped with a dual-core ARM Cortex-M0+ processor that operates at a maximum of 133 MHz. This high-performance processor has sufficient processing power to simultaneously process data from the millimeter-wave radar and perform WiFi communication.
  2. Memory:

    • The RP2040 has 264 KB of on-chip SRAM, which is sufficient capacity for temporary storage and processing of data. This allows the data from the millimeter wave radar to be processed efficiently and sent to the smartphone via WiFi.
  3. Support for WiFi modules:

    • The RP2040 itself does not have built-in WiFi functionality, but it is possible to use WiFi communication by connecting an external WiFi module (for example, an ESP8266 or ESP32 module). This makes it possible to send data from the millimeter wave radar to a smartphone.

Microcontroller programming

I used WOKWI, an online simulator for electronic work, to simulate it.

pico1.jpg


#include <LiquidCrystal.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

const char* ssid = "Wokwi-GUEST";
const char* password = "";
const String url = "https://v2.jokeapi.dev/joke/Programming";

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
#define BTN_PIN 16    // GPIO 15

void setup() {
  Serial1.begin(115200);
  pinMode(BTN_PIN, INPUT_PULLUP);
  WiFi.begin(ssid, password);
  lcd.begin(16, 2);
  lcd.print("Hello World!");

  lcd.setCursor(2, 1);
  lcd.print("> Pi Pico <");
  delay(1000);
  lcd.clear();
  lcd.print("Connecting to WiFi");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    lcd.print(".");
  }
  lcd.clear();
  lcd.print("\nOK! IP=");
  lcd.println(WiFi.localIP());
  delay(1000);
  lcd.clear();

  nextJoke();
}

String getJoke() {
  HTTPClient http;
  http.useHTTP10(true);
  http.begin(url);
  int httpCode = http.GET();
  
  if (httpCode != HTTP_CODE_OK) {
    Serial1.print("HTTP error code: ");
    Serial1.println(httpCode);
    return "<error>";
  }

  String result = http.getString();

  if (result.length() == 0) {
    Serial1.println("Empty response received.");
    return "<error>";
  }

  DynamicJsonDocument doc(2048);
  DeserializationError error = deserializeJson(doc, result);
  // Test if parsing succeeds.
  if (error) {
    Serial1.print("deserializeJson() failed: ");
    Serial1.println(error.c_str());
    serializeJsonPretty(doc, Serial1); 
    return "<error>";
  }
  serializeJsonPretty(doc, Serial1); 
  String type = doc["type"].as<String>();
  String joke = doc["joke"].as<String>();
  String setup = doc["setup"].as<String>();
  String delivery = doc["delivery"].as<String>();
  http.end();
  return type.equals("single") ? joke : setup + "  " + delivery;
}

void nextJoke() {
  lcd.println("\nLoading joke...");
  String joke = getJoke();
  Serial1.println(joke);
  lcd.clear();
  lcd.println(joke);
}

void loop() {
  if (digitalRead(BTN_PIN) == LOW) {
    delay(100);  // debounce processing
    lcd.clear();
    nextJoke();
  }
  delay(100);
}