Skip to content

6. Embedded programming

This week I learned in a group project about different chip architectures, and learned lots of programming methods with the Arduino Uno And Attiny 412.

Porgramming

This week programming, I decided to recreate a project I’ve already done on an arduino, and did the project on the Attiny 412 and rasberry pi pico microcontroller.

Arduino Uno

The project that I was going to do was a group assignment that I did in a previous engineering course. I used an arduino uno, ultrasonic sensor, and LED’s to create a parking sensor. The wiring was simple, but I had to put a lot of LED’s on the breadboard. Here’s what my final circuit looked like.

For coding, I used the Arduino IDE. I already had the code but looking back at it, the code could be optimized a lot better. I wasn’t exactly sure how to do this, so I asked ChatGPT. His response came with this:

This code used the string functions so that as the distance increased, an additional pin was added for each LED to turn on. This code only works if all the LED’s are lined up in a sequence, so I changed some wiring. After I changed the wiring, the code worked well, and the code worked.

Here’s a video:

Attiny

Next, I used the Attiny 412 microcontroller. I already had this chip soldered onto a board from pre-fab training so I could put the chip onto a breadboard. Because the 412 doesn’t have nearly as many I/O pins, I decided to only use 3 LED’s. I had to go back to my older, less efficient version of the code, because I couldn’t put all of the pins in numerical sequence. Here’s what the wiring looked like:

Programming the Attiny chip was different than programming an arduino. The Attiny doesnt have any type of usb interface like the arduino uno has, so instead I had to use a programmer board to upload my code using the single-wire UPDI pin. To do this, I first used a code called JTAG2UPDI, which when uploaded, turns the arduino into a programmer board. Then, I uploaded my other code into the ATtiny, making sure to use Jtag2updi as the programmer and setting the board to Attiny 412.

No Library Programming

The final requirement for this week is a lab specific requirement, which is blinking an LED using bare metal programming. I am coming back to this part after deciding to roll over, this section was originally named bare metal programming, but Neil suggested the term no library programming. To do this, I will use the same method of programming as before, via arduino using JTAG2UPDI. However, different from the programming that I’ve done, I have to program the LED to blink without using the built-in libraries of the Arduino. In arduino, when using the command pinmode (X, HIGH), A lot is happening behind the scenes in order to make this happen. When a specific pin is referenced, through Arduino’s built in board libraries, it is able to know exactly where in the microcontroller needs to be referenced and what change needs to be made to turn the pin high or low. With No Library programming, I will be using the 412’s datasheet to directly give commands to the part of the microcontroller’s architecture.


Last update: April 3, 2024