Skip to content

9. Electronics design

Group assignment:

  • Use the test equipment in your lab to observe the operation of a microcontroller circuit board (as a minimum, you should demonstrate the use of a multimeter and oscilloscope)
  • Document your work on the group work page and reflect what you learned on your individual page

Individual assignment:

  • Use an EDA tool to design a development board to interact and communicate with an embedded microcontroller

Learning KiCAD

I began this week by watching some KiCAD tutorial videos which my instructor, Mr. Dubick, sent to my classmates and I (I also could have used Eagle in Fusion, but I ended up choosing KiCAD). The full collection of these tutorial videos can be found here. From these videos, I learned the basics of KiCAD in both the schematics editor and PCB editor. I also followed along with the videos’ PCB board to create my own. Although I obviously didn’t use this board for this week’s assignment, it still helped me understand how KiCAD works. After finishing these tutorial videos, I moved onto the actual assignment for this week, which was to design my own PCB board including an embedded microcontroller.

Creating my Board

Making the Schematic

I first downloaded the Fab KiCAD library (which can be found here) and saved it as a zip file. Then, I went to Preferences > Manage Symbol Libraries as well as Preferences > Manage Footprint Libraries to add the libraries I needed to KiCAD. Now, I could begin making my schematic. After watching all of the previously mentioned tutorial videos, I felt relatively confident with KiCAD (in the schematics editor at least) and added the following components: 1 ATtiny412, 1 LED, 1 generic resistor, 1 button switch, 1 capacitor, and one 1x3 conn header. The wiring of these components took about 45 minutes, as I spent quite some time figuring out how to properly draw net labels. My final schematic is shown in the picture below.

After finishing this schematic, I performed an electrical rules check to make sure there weren’t any issues with my wiring. It initially came up with 3 errors, but I quickly realized that these errors all had to do with missing footprints on the components I selected. To fix this, I went into the footprint editor and chose corresponding footprints from the fab library for each of the components. I then did another electrical rules check, and, this time, I encountered no errors.

How are the pins connected?

I mostly connected the pins in the above schematic using direct wire connections, as these connections were the eaisest for me to visualize. If I had to redo this board, I would probably make more use of net/global labels, since they make the schematic a bit easier to understand at a glance. On the topic of labels, I used net labels for the 3-pin conn header, the LED, and the button because trying to connect them using wires would have been too tedious, and that is the purpose of net labels.

Using the PCB Editor

Now that I had created the schematic, I could go onto the next step, which was creating my PCB board. I first opened the PCB editor in KiCAD and brought all of my components (from the schematic) into it. Then, I began configuring the settings. The most important setting that I changed here was setting the trace width to 0.5 mm, which was wider than the default. Then, after that, I moved all of the components apart from each other so that I could see the ratlines (lines indicating how components are connected) between each of them. After this step, I began actually routing the PCB. This whole process took about 30 - 45 minutes, and the image below shows what the routed PCB looks like. After taking this picture, I also added a small design at the top (pusheen!) which will be milled on the board.

How was the PCB routed?

KiCAD doesn’t have any autorouting features, so I did the routing for this PCB by hand. Since this is a pretty simple PCB, I was able to route it successfully on my first/second try. My criteria when routing this PCB included having only 45 degree turns in the traces (no 90 degree turns) and minimizing the amount of space used.

How was the logo added to the PCB?

KiCAD has a built-in feature called the “image converter”, which allows you to take any .jpg, .png, or bitmap image and turn it into a schematic symbol or PCB footprint. In order to add the logo you see in the image above, I used this feature by uploading a .jpg image, saving it as a PCB footprint, and pasting it into my PCB design file. Then, when milling my PCB design, I included the front silkscreen layer (which is the layer the logo was added to), which allowed me to mill out the logo.

Milling/Soldering the 1st Iteration of my PCB

After creating my PCB in KiCAD, I moved onto exporting it as a gerber file so that I could mill it. To do this, I went to the PCB editor and followed the following steps: Plot > Select F.Cu, Edge.Cuts, and F.Silkscreen > Plot. I left all of the settings as they were (the default settings) as there was nothing worth changing for this specific mill. I then emailed myself the 3 files I created so that I could download them on a separate computer which had Bantam installed. Then, I loaded all 3 of these files into the actual Bantam software (note that the Edge.Cuts file was chosen as the outline of the F.Cu file and was not added as its own independent file). The picture below shows what the toolpath looked like after I offset the pusheen design accordingly.

Before I began milling, I made sure I had the correct settings. To do this, I essentially followed the steps established during electronics production week. The simplified version is the following: load the bit (the 0.005 mm engraving bit in this case), z-axis probe where you want to cut, make sure your designs have the correct offsets (x and y should be offset by 4 if you are cutting in the bottom left corner), set trace clearance to 1.5 mm, generate the g-code, mill. After my pusheen design was cut, the machine prompted me to change the tool to something other than the 0.005 mm engraving bit. I chose the 1/64 bit because it was precise enough to cut my traces and I would rather not use the 1/100 bit for this job. After inserting this new bit, the job took another few minutes before finishing. My finished PCB board is shown in the picture below. Unfortunately, I accidentally milled this board with a trace clearance of 0.15 mm instead of 1.5 mm, which was something that would come back to bite me soon.

I immediately began soldering my new board after taking it out of the milling machine. The parts list for this board is shown below.

Parts List:

  • 1 ATtiny412 microcontroller
  • 1 LED (any color)
  • 1 499 ohm or 320 ohm resistor
  • 1 capacitor
  • 1 button switch
  • 1 1x3 conn header

I tried using both solder paste and normal solder for this board, and, to be honest, I had more success using normal solder, as it allowed me to have more precision when soldering smaller components. Although using solder paste was very efficient (especially for the ATtiny412), I think I will stick to normal solder for most of my future boards. The soldering process took about an hour, and the final product is shown in the picture below.

Problems Encountered: Trying to Program

After finishing the soldering process, I plugged my board into an Arduino Uno, and, with the help of my classmate Angelina Yang used 3 jumper wires to try and do some basic programming with it. We first tried to upload the following code:

void setup() {
  // put your setup code here, to run once:
  pinMode(4, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(4, HIGH);
}

This is a very basic code which should have lit up my LED (which was connected to pin 4 on my ATtiny chip). However, I encountered an error here telling me that my board could not be located. To troubleshoot, I grabbed a multimeter and began testing connections on my board. Unfortunately, I soon found out that my GND and PWR were connected, likely as a result of a solder bridge near my ATtiny. However, I couldn’t tell exactly where it was. After trying unsuccessfully to get rid of this solder bridge, I decided to just remill my board and make some key changes.

My ATtiny412 Board: Second Iteration

The first change I decided to make to my board was the addition of another LED and resistor. This new LED would serve as an indicator LED connected directly to power so that, when I connect my board to a computer, I can immediately tell if power is going through or not. Next, I also decided to slightly change some of my routing in the PCB editor because, in the previous version, there were some traces which were too close together for the 1/64 bit to mill correctly. Finally, I decided to remove my pusheen design (;-;) to make some extra space for the new LED and resistor. This new design is shown in the screenshot below.

Armed with this new design, I went back through the process of emailing myself the gerber files, loading them into Bantam, and milling my new board. This time, I remembered to set the trace clearance to the proper width of 1.5 mm and milled the board after going through the workflow. This time, I feel like my board came out a lot better, and the milled board is shown in the picture below.

I then soldered this board using the same parts list as before (except for the addition of 1 more LED and 1 more resistor) and encountered no issues with this step. However, after I soldered on the new LED/resistor, the conn header, and the ATtiny, I paused on this step to try and activate the indicator LED by plugging the board back into the Arduino Uno I used to test my first board. Luckily, once I did this, the indicator LED turned on successfully!

Now that I knew this new board could connect to power properly, I soldered on the rest of the components.

Programming: Second Iteration

After soldering, I used a multimeter to test the connections on my board. This time, there were no solder bridges nor any other connection issues, allowing me to finally begin programming it. To do this, I decided to use my RP2040 as a programmer instead of using the Arduino Uno. For some reason, I had to flash my RP2040 with the uf2 file again (I initially did this during embedded programming week), and so I plugged in my RP2040 into my computer and followed all of the steps like I had done before (shown on the Quentorres website). Since I already had the libraries I needed to program the ATtiny412 from previous weeks, I could move directly onto writing and uploading the code I would use on my board. I followed the steps in the Quentorres documentation again for this step (linked above) and encountered no issues up until when I actually tried to upload the following code (which was the same code as what I used to test my first board):

void setup() {
  // put your setup code here, to run once:
  pinMode(4, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(4, HIGH);
}

Here, I encountered the following error:

A programmer is required to upload.

Fortunately, there was a simple fix to this which I learned about on Collin Kanofsky’s documentation. You simply have to go to Sketch > Upload with Programmer and the error should no longer show up. However, here, I encountered a new issue, shown below.

pymcuprog.pymcuprog_errors.PymcuprogError: UPDI initialization failed
Failed programming: uploading error: exit status 1

Trying (and failing) to Solve the 2nd Issue

I got stuck here for a few minutes before I found a step-by-step process to resolve this issue at the bottom of the Quentorres documentation. The process is as follows:

  1. Open your computer’s terminal (I used Powershell) and type in the following command:
pymcuprog --version

When I did this, I encountered an error telling me that pymcuprog wasn’t recognized, meaning that I didn’t have it installed.

To fix this, I tried to follow the next few steps.

  1. Make sure you have python installed by typing in the following command:
python --version

For some reason, when I did this, Powershell told me that Python wasn’t even installed. I knew this was incorrect as I quickly searched for it in my computer and found it in the “Windows SSD” drive in task manager. Because I knew I had python installed already, I went to the next step.

  1. Enter “pip install pymcuprog” in your terminal.
pip install pymcuprog

This worked, and I now had pymcuprog installed.

  1. Go to Sketch > Export compiled binary
  2. Now, go to Sketch > Show Sketch Folder. This should open file explorer in the location of your .hex file (for your Arduino IDE code)
  3. Navigate to that folder in your terminal using the “cd ___” command

I had no issues with any of these steps. After successfully navigating to the correct folder, I tried to do the following step:

  1. Enter the following command in your terminal (after navigating to the .hex file) to program the board:
pymcuprog write -t uart -u /dev/ttyACM0 -d attiny1614 -f BlinkATtiny.ino.hex --erase --verify

After entering this, however, I encountered an error telling me that the port “/dev/ttyACM0” could not be found.

According to the Quentorres documentation, this port should appear as an option when you go to Tools > Port in Arduino IDE. When I did this, however, I could only see COM6, which was the port that my RP2040 and ATtiny were connected to. After struggling with this and trying to upload my code countless times, I got some help from Collin Kanofsky, who recommended that I try plugging my board into his computer instead of my own. I did this and uploaded my code again (using upload using programmer), but I kept encountering the same error of “UPDI initialization failed”.

Solution

I was out of ideas at this point, but Collin let me know that my board was likely encountering one of two issues. One, the converter board I was using (between the RP2040 and ATtiny boards) wasn’t working correctly, or, two, there was something wrong with my RP2040 board. I first tested the converter board by using a different board which I knew worked and uploaded a simple program. This worked successfully, so I knew there was nothing wrong with the converter board. Next, to test my RP2040, I borrowed Angelina Yang’s RP2040 board, connected it to my ATtiny board, and uploaded the same code that I had been using. THIS UPLOAD WENT THROUGH SUCCESSFULLY!! For some reason, though, my LED still wasn’t lighting up. After consulting with Collin again, he found a picture of the ATtiny412 pinout and realized that, although the port my LED was connected to was marked as pin 4 on KiCAD, Arduino IDE actually recognized it as pin 2. After this, I immediately changed my code to the following:

void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(2, HIGH);
}

I quickly uploaded this code (still using Angelina’s RP2040 board), and my LED lit up!

Now that I had fixed the issues with my programming/board, I made another program which incorporated the button switch on my board. The code is shown below.

int buttonstate = 0;

void setup() {
  pinMode(2, OUTPUT);

  pinMode(3, INPUT_PULLUP);

}

void loop() {
  buttonstate = digitalRead(3);
  if (buttonstate == HIGH) { 
    digitalWrite(2, HIGH);
  }
  else {
    digitalWrite(2, LOW);
}
}

I chose pin 3 for my button because that is where my switch was connected to. When I wrote this code, I expected it to turn on the LED when I pushed down on the button and turn off the LED when I wasn’t pressing it. However, as the following video shows, this process seems to have been reversed. Instead of turning on when I pressed the button, the LED turned off. It only turned on when the button wasn’t being pressed.

Regardless, I now had a working ATtiny412 board created, milled, and programmed by myself!

Group Assignment

This week, I worked with Landon Broadwell and David Vaughn to observe the operation of a microcontroller circuit board using a multimeter and an oscilloscope. The entire process we used to do this can be found in our group’s documentation, which can be found here. Throughout the course of this assignment, we learned how to use an oscilloscope and how to use analog code to program PWM pins. Learning how to program these PWN pins will be especially helpful for us, as it opens up a whole new door into the world of analog (instead of digital) components.

Reflection

I felt relatively good at the beginning of this week, specifically when I was learning KiCAD and designing the first iteration of my ATtiny412 board. However, this quickly changed when I got to the programming stage of the week, which is where I encountered almost all of my problems. The fact that I had to mill/solder a second iteration of my board due to the first not working definitely took up a large portion of the time I spent on this week’s assignment, and I regret not checking the connections of my soldering/traces before trying to program the first board. However, I also learned many useful skills this week, such as how to design and mill my own board. I also became more familiar with the process of programming an ATtiny board using an RP2040 as the programmer. My files for this week can be found here.


Last update: June 28, 2024