Skip to content

6. Embedded Programming

Group assignment:

  • Browse through the datasheet for your microcontroller

  • Compare the performance and development workflows for other architectures

  • Document your work to the group work page and reflect on your individual page what you learned

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)

Download Design Files

Click here to download my design files folder

Group Work Reflection

I talk about this more in my whole-week relfection, but the group work really showed me how important it is to communicate and identify weaknesses/strengths of members as to best achieve our goals together. Additionally, I realized through the group work how different microcontrollers (in our case the ATtiny412 and SAM D11C) can be more or less beneficial/effective/efficient with different uses. Primarily, the SAM D11C gave us a substantially harder time than the ATtiny412 did for other groups. As beginers to embedded programming and microcontrollers, the ATtiny412 was definetly a more suitale option for use that the SAM D11C.

Link to Group Work Page

Individual Work

Microcontroller Based Control

As I did in week 4, I demonstrated that I had a working microcontroller development board by first getting the LEDs to blink and then getting the LEDs to blink by using the button.

LED Blinking

Richard Shan wrote and shared a simple program to test the circuit board by blinking the 3 LEDs (the LEDs are connected to pins 0, 1, and 26)

Richard’s Code:

  void setup() {

  pinMode(1, OUTPUT); //bottom right LED

  pinMode(26, OUTPUT); //top left LED

  pinMode(0, OUTPUT); //bottom left LED

}


  void loop() {

  digitalWrite(1, HIGH); //turns bottom right LED on

  digitalWrite(26, HIGH); //turns top left LED on

  digitalWrite(0, HIGH); //turns bottom left LED on


  delay(1000); //waits for 1 second


  digitalWrite(1, LOW); //turns bottom right LED off

  digitalWrite(26, LOW); //turns top left LED off

  digitalWrite(0, LOW); //turns bottom left LED off


  delay(1000); //waits for 1 second

}

Button-Controlled LED Blinking

Next, I uploaded the following code so that the LEDs would light up when the button is pressed, and turn off when the button is not:

void setup() {


  pinMode(1, OUTPUT);

  pinMode(26, OUTPUT);

  pinMode(0, OUTPUT);


  pinMode(27, INPUT_PULLUP);

}


void loop() {

  int buttonState = digitalRead(27);

  if (buttonState == LOW) {

  digitalWrite(1, LOW);

  digitalWrite(26, LOW);

  digitalWrite(0, LOW);

  }

  else {

  digitalWrite(1, HIGH);

  digitalWrite(26, HIGH);

  digitalWrite(0, HIGH);

  }

}

SAMD11C Chip Programming

Creating the Boards

For the creation of the SAMD11C board I heavily relied on Adrian Torres’s SAMD11C work.

After milling the SAMDino board, I soldered it following the schematic and referencing the bill of materials on Adrian Torres’s website.

Schematic:

The milled board:

Next we milled and then I soldered this connector board. At first I wasn’t sure why we had actually done this, but, after talking with my partner Richard Shan, he explained that for us to program the chip from the XIAO RP2040 on the Quentorres board, a connector board to adapt the 2 x 5 pin cable to a 2 x 2 pin. This is neccessary due to the RP2040 outputting from 2 x 5 pins whereas the SAMDino inputs a 2 x 2 pin.

Schematic:

The milled and soldered board:

We then determined that the SAMD11C would be easier to use on the Hello Board than the SAMDino. So we milled and the soldered the Hello Board.

Schematic:

Milled and soldered board:

Programming

To use the Quentorres board I made in week 4 as a programmer for the SAMD11C chip and subsequent board I made for it, I first needed to turn the XIAO RP2040 on the Quentorres into a debugger. To do this, I uploaded the free_dap_rp2040.uf2 file (in my design files folder download) by first holding the bootloader button on the RP2040 to enter the bootloader mode. Once I did this, I selected “UF2 Board” as the port under the tools tab and uploaded the subsequent blinking LED code. I then got the error message “No monitor avaliable for the port protocol uf2conv. Could not connect to UF2_Board uf2conv port.” Then, “INFO_UF2” opened from the Notepad application.

Then, I uploaded the code again, got the same error message “No monitor avaliable for the port protocol uf2conv. Could not connect to UF2_Board uf2conv port,” BUT the PC said that it was “Setting up a device: We’re setting up ‘XIAO RP2040.’” Furthermore, in Arduino IDE’s output, it said:

“Converting to uf2, output size: 156672, start address: 0x2000

Scanning for RP2040 devices

Flashing D: (RPI-RP2)”

Next, I uploaded the code again and it said: “Wrote 156672 bytes to D:/NEW.UF2” in addition to the previous outputs and a folder labeled “RPI-RP2 (D:)” opening and showing files “INDEX,” “INFO_UF2,” and “NEW.UF2” in it.

Then, the RP2040’s folder opened on my computer and I was able to drag and drop the file into the RP2040’s folder.

Then, in Arduino IDE I imported libraries https://raw.githubusercontent.com/qbolsee/ArduinoCore-fab-sam/master/json/package_Fab_SAM_index.json and https://www.mattairtech.com/software/arduino/package_MattairTech_index.json by going to File>Preferences>Additional Boards Manager URLs and copying and pasting the library links into the additional boards manager URLs tab.

Navigating to the board manager, I downloaded the megaTinyCore board library. I then selected the SAM D11C board under the Boards tab.

I then uploaded a C++ code to blink the LEDs and test the board.

void setup() {    // setup function that runs when the program starts. Initializes variables, pin modes, using libraries, etc.

pinMode(5, OUTPUT);   // sets the mode of pin 5 to output (so pin 5 can be used to send signals High or Low)

}     // closes the setup function

void loop() {     // after the setup function runs this loop function will run indefinitely and complete the main tasks the code is designed to do

digitalWrite(5, HIGH);      // sets pin 5 to high (meaning it sends a voltage to the pin) and turns an LED connected to pin 5 on

delay(1000);      // pauses the code for 1 second (1000 milliseconds) 

digitalWrite(5, LOW);       // sets pin 5 to low (meaning it stops sending voltage to the pin) and tuns off an LED connected to pin 5

delay(1000);        // pauses the code for another second

}       // closes the loop function

I had ChatGPT help me to understand this code and add comments to it; summarizing it to mean: The code makes an LED connected to pin 5 blink on and off with a one second interval. The setup function configures pin 5 as an output and the loop function turns the LED on and off with the one second delay between changing from on and off.

When the code successfully uploaded, the following popped up in the serial monitor:

Sketch uses 9760 bytes (79%) of program storage space. Maximum is 12288 bytes.
Atmel SMART device 0x10030006 found
Device       : ATSAMD11C14A
Chip ID      : 10030006
Version      : v2.0 Nov 22 2017 12:56:25
Address      : 4096
Pages        : 192
Page Size    : 64 bytes
Total Size   : 12KB
Planes       : 1
Lock Regions : 16
Locked       : none
Security     : false
Boot Flash   : true
BOD          : true
BOR          : true
Erase flash
done in 2.161 seconds

Write 10112 bytes to flash (158 pages)

[                              ] 0% (0/158 pages)
[==                            ] 9% (15/158 pages)
[=====                         ] 18% (30/158 pages)
[========                      ] 28% (45/158 pages)
[===========                   ] 37% (60/158 pages)
[==============                ] 47% (75/158 pages)
[=================             ] 56% (90/158 pages)
[===================           ] 66% (105/158 pages)
[======================        ] 75% (120/158 pages)
[=========================     ] 85% (135/158 pages)
[============================  ] 94% (150/158 pages)
[==============================] 100% (158/158 pages)
done in 24.355 seconds

Verify 10112 bytes of flash

[                              ] 0% (0/158 pages)
[==                            ] 9% (15/158 pages)
[=====                         ] 18% (30/158 pages)
[========                      ] 28% (45/158 pages)
[===========                   ] 37% (60/158 pages)
[==============                ] 47% (75/158 pages)
[=================             ] 56% (90/158 pages)
[===================           ] 66% (105/158 pages)
[======================        ] 75% (120/158 pages)
[=========================     ] 85% (135/158 pages)
[============================  ] 94% (150/158 pages)
[==============================] 100% (158/158 pages)
Verify successful
done in 0.083 seconds
CPU reset.

Video of the blinking:

ATTiny412 Programming

Half of our fab node’s groups for this week made the SAMD11C chip board (my group did this one) and the other half made ATTiny412 boards. After we all got our boards working we then swapped with another group to do programming with the other board. Richard and I swapped boards with Angelina Yang, Connor Cruz, and Kabir Nawaz.

The ATTiny412 Board Set-Up:

Richard, again, wrote a C++ code to blink the LED.

// initialize digital pin LED_BUILTIN as an output

int LED = 4;    // declares a variable named "LED
 and assigns it the value 4. The varible will be used to refer to pin 4.

void setup() {    // setup function that runs when the program starts. Initializes variables, pin modes, using libraries, etc. 

pinMode(LED, OUTPUT);   // sets the mode of the pin referred to by the variable "LED" (pin 4) to output (meaning that pin 4 will be used to send signals High or Low).

}     // closes the setup function

void loop() {     // after the setup function runs this loop function will run indefinitely and complete the main tasks the code is designed to do

digitalWrite(LED, HIGH);    // sets "LED" variable to high (sends voltage to the pin) and turns an LED connected to pin 4 on.

delay(1000);      // pauses the code for 1 second (1000 milliseconds)                

digitalWrite(LED, LOW);    // sets "LED" variable to low (stops sending voltage to the pin) and turns an LED connected to pin 4 off.

delay(1000);     // pauses the code for 1 second (1000 milliseconds)               

}     // closes the loop function

I had ChatGPT help me to understand this code and add comments to it; summarizing it to mean: The code makes an LED connected to pin 4 blink on and off with a one second interval. The setup function configures pin 4 as an output and the loop function turns the LED on and off with the one second delay between changing from on and off. The use of the “LED” variable (pin 4) makes the code easier to read and modify.

  • Note: I ended up using a UPDI connector board to connect the ATTiny412 board to the Quentorres. This is weeks later Alana writing this right now and realizing I never documented the UPDI connector board o_o So, check out my week 8 documentation which has documentation relating to the UPDI board, its files, and production :)

Communication

For this week, I need to: “write a program for a microcontroller development board to interact (with local input &/or output devices) and communicate (with remote wired or wireless devices).”

The aformentioned work covers the first half of the requirements (using a GPIO).

To cover the second half of the requirements (communicating with another device), you can visit my Week 13 Networking and Communications work!

Reflection

This week was beyond mind-bogglingly hard. The amount of time I spent working and the amount of time my stuff actually spent working is so disproportionately out of wack it physically hurts. I’m not even sure I consiously knew what I was doing 90% of the time but I was doing anything and it somehow worked out. In the end it all makes sense, but at the time… whew I thought I was going to cry/die/laugh/float away into space all at once. What I learned? Trust the process. Trust the process, put in the time, and lean on your fab mates for a helping hand/shoulder to cry on.

References

https://fabacademy.org/2020/labs/leon/students/adrian-torres/samdino.html

https://gitlab.fabcloud.org/pub/programmers/quentorres

https://gitlab.fabcloud.org/academany/fabacademy/2020/bootcamp/spicy/blob/master/Program1614.md

https://fabacademy.org/2020/labs/leon/students/adrian-torres/week08.html

https://fabacademy.org/2020/labs/ulb/students/quentin-bolsee/assignments/week09/

https://fabacademy.org/2024/labs/charlotte/students/richard-shan/lessons/week6/microcontrollerBasedControl/


Last update: July 9, 2024