Home Assignments Project Development Final Project About Contact

Embedded Programming

Assignment

  • Read a microcontroller datasheet
  • Program my board to do something

Read a microcontroller datasheet

When getting to know the possibilities of the microcontroller, how it was built and how it should be used I quickly discovered that there was a lot to know. The most important thing for me was to understand how the pins of the microcontroller was laid out so that I would be able to program them.

The pin numbers I would have to program in a software on a computer is not the same as the number of the microcontroller on the actual board. This is because some of the numbers are used for other things than programmable pins. In the tutorials section of the Fab Academy website there is a good schematic showing the pins of the ATtiny44 microcontroller and its correspondent pin in the Arduino software.

pins

Looking at page 2 and 3 in the datesheet we see the reasoning why the pin numbers are different. Pin number 1, 4 and 14 are used for VCC, GND and reset which is why they are not programmable pins and therefore not usable in the Arduino software.

datasheet

Another important thing which really caught my attention in Neils lecture is how the complexity of code language can influence microcontrollers. Underneath there's is a diagram which basically shows how fast computer software can exchange information with the pins on the microcontroller. On the y-axis there is time in MHz and on the x-axis the board price. I have highlighted the Raspberry Pi which has been programming using both Python and C code, with C code being the fastest (the frequency is higher). This is due to Python being a higher level language, which means that it takes more time to translate it to readable machine code for a microcontroller/computer to read than C code which is a more basic language than Python.

runtimes

Coding languages such as C can be challenging and time consuming to write from the bottom, while python is a more accessible language for people with a entry coding skill level. Some softwares makes you use C code but has libraries wich make it easier since you don't have to write everything out yourself. From what I understand with the knowledge I have gained in this week, it can be compared to using Bootstrap, or something similar, when writing HTML instead of making you own css stylesheet.

Program my board to do something

The board I will be programming is the board I made in week 7. I'm programming it with the programmer I made in week 5.

The interface we were going to be using to program our boards is the software Arduino has made. One of the misconceptions about Arduino is that it is only circuit boards, but it's actually a lot more, one of them being a software. Arduino uses C code but has the ability to add libraries for different microcontrollers. By default Arduino does not have a library for ATtiny microcontroller that I have on the board I will be programming. Therefore the first thing I did was to add the ATtiny to the library with a URL link. The URl link is put under settings and after that it will appear under tools - boards - board manager.

settings boardmanager

After that I had to burn my bootloader onto the board I was going to be programming. Bootloader is another word for programmer. For the bootloader to be burned I also had to select the specifications of the board I was using.

bootloader

Even though I had selected the specifications of the board something was still wrong when I was trying to burn bootloader. I got the error message "could not find USBtiny device". After hours of trying to solve the problem with my local instructor we had Bas on the phone who stated that I had the wrong driver installed. After installing the right driver with a software called Zadic it worked.

drivers

The reason this problem occurred for me and might not for others, is when I programmed my programmer that I made in week 5 I used an Ubuntu computer that we had in the lab. Had I used my own computer at that time, I would already have had the right driver installed.

After I was finally able to burn the Bootloader I tried to use a code example from the tutorials section which would make the LED light up when the button on the board is pressed. After the code was typed in I pressed compile and upload in the top left corner of the screen, and luckily it worked.

example electronics

After having used a coding example I tried to make my own bit of code. The tutorial for using Arduino with the ATtiny44 listed all the supported commands:

commands

From the code example I saw that the first thing to do was to tell the computer which pin the LED and button is using. Next thing was to write that the button should not be activated from the beginning. From what I can tell the two states of the button is called 0 (off) and 1 (on). The next piece of code is under void setup which is a code that will be running once when you turn the board on. Here the button is specified as an input and the LED as an output device since the button is making an input for the LED to read and use to create an output. The button sends information and the led displays information.

Under void loop the code that should be run repeatedly, or the action itself, is placed. I would like to switch things up a bit from the code example. I changed the LED to be on by default in the if statement. After that I would make the LED blink if the button was pressed down. I would make use of the delay command and let the time interval when the LED was turned on be the same, but differ the length of the pauses in between the LED lighting up. when I pressed compile code, the Arduino software told me the mistakes I had in the code, for example forgetting to add ";"" at the end of each of the commands. After correcting my mistakes the code was running the way it was supposed to.

code

Problem

After having had success with C code using the Arduino software I tried to use the hello echo C code and uploading to my board with both git bash and windows powershell, but I can’t seem to make it work. I have tried to go through the installation process of the toolchain software. Underneath you see the mistake I'm getting:

problem

Every time I run the make file command it is making a out file.

problem

Later in Fab Academy I used an Ubuntu computer to go over to upload c files. See Input Week