4. Embedded Programming¶
Assignment¶
-
Group assignment:
-
Demonstrate and compare the toolchains and development workflows for available embedded architectures
- Document your work to the group work page and reflect on your individual page what you learned
-
Individual assignment:
-
Browse through the datasheet 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 connection)
Research¶
In this week assignment i started the research by looking at the ATTiny 412 and how to procram and simulate little circuit with it. I did research on how to program ATtiny with arduino IDE using C++ language. I also did try to find out what kind of assignment you can use ATtiny for.
Then i studydatasheet for XIAO RP2040 trying to figure out what is it strength and weekness. I will document the outcome further on this site.
Studying datasheet for RP-2040¶
I found the datasheet here, then the seeed studio page leed me to this wiki studio page that wiki page is very good to learn about there products.
I made an comparision table for RP2040 and ESP32-C3 from informasion i fond on the Seeed studio wiki page
Item | Seeed studio XIAO-RP2040 | Seeed studio XIAO ESP32C3 |
---|---|---|
processor | RP2040 Daul-core M0+@133Mhz | ESP32-C3 32-bit RISC-V@160Mhz |
Wireless Connectivity | N/A | WiFi and Bluetooth 5(le) |
Memory | 264KB SRAM, 2MB onboard Flash | 400KB SRAM, 4MB onboard Flash |
Built-in Sensors | N/A | N/A |
Interfaces | 12C/UART/SPI | 12C/UART/SPI/125 |
PWM/Analog Pins | 11/4 | 11/4 |
Onboard Buttons | Reset/Boot Button | Reset/Boot Button |
Onboard LEDs | Full-color RGB/ 3-in-one | Charge LED |
Battery Charge Chip | N/A | Built-in |
Programing Languages | Arduino/ MicroPython/ CircuitPython | Arduino |



Programming ATtiny412 with Arduino IDE¶
With a good help frm my friend Chat gpt.
i did ask mister Chat gpt if he could help me finding the best way to program ATtiny with arduino and the way is almost the same as i have always done this. i have programed few Attiny before.
In my work we do use Arduino IDE in few classes so i had that program already installed in my computer, i also use ATTiny 412 in one assignment in my class were my students need to make an electronig circut with ATTiny. led. capasitor, resistor and button. and they have to upload a program to ATtiny that will work like when you press the button once the led blinks once, when u press the button seccond time the led blinks twise, and then three times and in the end four times then it starts over. like said before this describsion of how to program ATTiny is done with great help from Chat gpt but i did go trugh this text and add to it how i do different when i have done it may self and added som pictures.
What You Need:¶
- ATtiny412 microcontroller
- UPDI programmer (or an Arduino acting as a UPDI programmer)
- Arduino IDE (latest version)
- 1K ohm resistor (if using an Arduino as the UPDI programmer)
- Breadboard and jumper wires
Step 1: Set Up Support for ATtiny 1-Series in Arduino IDE¶
- Open the Arduino IDE.
- Go to File > Preferences.
-
In the “Additional Boards Manager URLs” field, add the following URL: Json file for arduino
-
Click OK to save.
- Go to Tools > Board > Boards Manager.
- Search for megaTinyCore and install it. This core supports ATtiny 0/1-series chips, including the ATtiny412.
Step 2: Setting Up the UPDI Programmer¶
The ATtiny412 uses the UPDI (Unified Program and Debug Interface) for programming. You have two options:
Option 1: Use an External UPDI Programmer¶
If you have a dedicated UPDI programmer (e.g., a USB UPDI programmer), connect it to the ATtiny412 as follows: - UPDI connection: Connect the UPDI pin of the programmer to Pin 2 (UPDI) on the ATtiny412. - Connect VCC and GND from the programmer to the VCC and GND pins of the ATtiny412.
Option 2: Use an Arduino as the UPDI Programmer¶
If you don’t have a dedicated UPDI programmer, you can use an Arduino.
- Wiring the Arduino as a UPDI Programmer:
- Connect Digital Pin 6 on the Arduino to one end of a 1K ohm resistor.
- Connect the other end of the resistor to the UPDI pin (Pin 2) on the ATtiny412.
-
Connect GND and 5V from the Arduino to the corresponding pins on the ATtiny412.
-
Install the jtag2updi Sketch on Arduino:
- Download the jtag2updi sketch from GitHub.
- Open the sketch in Arduino IDE and upload it to your Arduino. This will configure the Arduino as a UPDI programmer.
Step 3: Connect the ATtiny412 to the Programmer¶
Here’s how to wire the ATtiny412:
ATtiny412 Pin | Function | Connection |
---|---|---|
Pin 1 (VCC) | VCC | 5V |
Pin 2 (UPDI) | UPDI | Arduino Digital Pin 6 (via 1K resistor) or external UPDI programmer |
Pin 3 (GND) | GND | GND |
Step 4: Configure Arduino IDE for ATtiny412¶
- Go to Tools > Board and select ATtiny412/402/212/202 (no bootloader) under megaTinyCore.
- Set the following configurations:
- Chip: ATtiny412
- Clock: 20 MHz Internal (or choose another clock as needed)
- Programmer: Select “jtag2updi (megaTinyCore)” if using an Arduino as the UPDI programmer, or choose the appropriate option for your UPDI programmer.
Step 5: Burn the Bootloader¶
Although the ATtiny412 does not require a bootloader for normal operation, burning the “bootloader” configures the fuses (e.g., clock settings) correctly.
- Go to Tools > Burn Bootloader.
- This step sets the proper fuse settings for the ATtiny412.
Step 6: Upload Your Sketch¶
Now you can write your code and upload it to the ATtiny412. For example, here’s a simple Blink sketch:
c++
void setup() {
pinMode(0, OUTPUT); // ATtiny412 pin 0 corresponds to PA6
}
void loop() {
digitalWrite(0, HIGH);
delay(1000);
digitalWrite(0, LOW);
delay(1000);
}
Then Choose Sketch > Upload Using Programmer to upload your code to the ATtiny412.
Useful links¶
Code Example¶
Use the three backticks to separate code.
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}