Fab Academy 2024 Website

  • Home
  • About
  • WEEK1 Project Management / Principles and Practices
  • WEEK2 Computer Aided Design
  • WEEK3 Computer-controlled cutting
  • WEEK4 Electronics production
  • WEEK5 3D scanning and printing
  • WEEK6 Embedded programming
  • WEEK7 Computer-controlled machining
  • WEEK8 Electronics design
  • WEEK9 Output devices
  • WEEK10 Mechanical design, Machine design
  • WEEK11 Input devices
  • WEEK12 Molding and casting
  • WEEK13 Networking and communications
  • WEEK14 Interface and application programming
  • WEEK15 Wildcard week
  • WEEK16 System integration
  • WEEK17 Applications and implications, project development
  • WEEK18 Invention, intellectual property, and income
  • Final
目次
  • WEEK6 Embedded programming
    • Group Assignment
    • Individual Assignment
      • About Seeed Studio XIAO RP2040
      • Setup
        • Assignment 1
          • Turns an LED on by pressing the button.
        • Assignment 2-1
          • Using an internal temperature sensor
        • Assignment 2-2
          • Setting and printing the current time

WEEK6 Embedded programming

  1. Fab Academy 2024 Website
  2. WEEK6 Embedded programming
hito |


WEEK6 Embedded programming

Group Assignment

compare the performance and development workflows for other architectures
Group assignment Page

Individual Assignment

write a program for a microcontroller development board to interact (with local input &/or output devices) and communicate (with remote wired or wireless devices)

About Seeed Studio XIAO RP2040

alt text

Feature Details
Microcontroller RP2040, Dual ARM Cortex-M0+ @ 133MHz
RAM 264KB
Onboard Flash Memory 2MB
GPIO Pins 11 programmable pins
Analog Input Pins 4 pins
USB USB Type-C connector, USB 1.1 Host/Device capability
Power Supply Via USB or external source (3.3V to 5V)
Serial Communication UART, I2C, SPI
PWM Outputs Supported
ADC 4 channels, 12-bit ADC
RTC Real-Time Clock functionality
Size 21.0mm x 17.5mm
Other Features SWD interface, RGB LED, Reset button

The Seeed Studio XIAO RP2040 offers a powerful performance and a variety of functions despite its compact size. It's ideal for wearable devices, prototyping, and small projects, featuring a USB Type-C connection, multiple communication interfaces, and programmable GPIO pins, catering to a wide range of development needs.

Setup

For this assignment, we will be using the Quentorres board that was made in Week 4.
alt text alt text
The setup for programming the XR2040 board with the Arduino IDE was completed in Week 4.
The simple setup steps are as follows.

  1. Download and install the Arduino IDE from the official Arduino website.
  2. Open the Arduino IDE and go to File > Preferences.
  3. Enter the URL for the XR2040 board's package in the "Additional Board Manager URLs" field.
  4. Open Tools > Board > Boards Manager, search for the XR2040 board package, and install it.
  5. Select the XR2040 board from Tools > Board.
  6. Choose the correct port under Tools > Port.

Assignment 1

Turns an LED on by pressing the button.

I downloaded the code from here and changed the buttonPin and ledPin numbers.

const int buttonPin = 27;  //Originally D0
const int ledPin = 26;     //Originally 25

int buttonState = 0;

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
}

// the loop function runs over and over again forever
void loop() {

  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);  // turn the LED on (HIGH is the voltage level)
  } else {
    digitalWrite(ledPin, LOW);
  }
}
Results:

Assignment 2-1

Using an internal temperature sensor

The Arduino IDE contains many example codes. You can find the code under 'File > Examples > rp2040 > Temperature.ino'.I added code to display the elapsed time.

unsigned long startTime;

void setup() {
  Serial.begin(115200);
  startTime = millis();
  delay(5000);
}

void loop() {
  unsigned long currentTime = millis();
  unsigned long elapsedTime = currentTime - startTime; 
  Serial.printf("Elapsed time: %lu ms  ", elapsedTime);
  Serial.printf("Core temperature: %2.1fC\n", analogReadTemp());
  delay(1000);
}
Wrapping my hand around the sensor can affect its readings by transferring heat to the sensor.
alt text
The results can be viewed in the IDE's Serial Monitor.
alt text

Assignment 2-2

Setting and printing the current time

You can find the code under 'File > Examples > rp2040 > Time.ino'. I have added code to adjust to EST.

#include <time.h>
#include <sys/time.h>

void setup() {
  Serial.begin(115200);
  delay(5000);
  struct timeval tv;

  tv.tv_sec = 1709524870 + (9 * 3600);  // Adjusting for a 9-hour time difference
  tv.tv_usec = 0;
  settimeofday(&tv, nullptr);
}

void loop() {
  time_t now;
  char buff[80];

  time(&now);
  strftime(buff, sizeof(buff), "%c", localtime(&now));
  Serial.println(buff);
  delay(1000);
}
The results can be viewed in the IDE's Serial Monitor.
alt text
There is the blinking LEDs randomly code with MicroPython. The code is generated by ChatGPT. Please see our Group assignment Page.

Copyright 2024 Hajime Ito - Creative Commons Attribution Non Commercial

検索
キーワードを入力して検索を始めましょう