WEEK6 Embedded programming
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
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.
The setup for programming the XR2040 board with the Arduino IDE was completed in Week 4.
The simple setup steps are as follows.
- Download and install the Arduino IDE from the official Arduino website.
- Open the Arduino IDE and go to File > Preferences.
- Enter the URL for the XR2040 board's package in the "Additional Board Manager URLs" field.
- Open Tools > Board > Boards Manager, search for the XR2040 board package, and install it.
- Select the XR2040 board from Tools > Board.
- 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);
}
}
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);
}
The results can be viewed in the IDE's Serial Monitor.
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);
}
There is the blinking LEDs randomly code with MicroPython. The code is generated by ChatGPT. Please see our Group assignment Page.