Session 1: Introduction#

NSK108#

Is a board that is made for educational purposes. It is build by Noavaran Electronic. It supports AVR and MCS-51 microcontroller, In this class we are working on an AVR microcontroller, called Atmega32.

nsk108

In the picture above, you can see the board that we are working on this class.

Programmer#

To program our code to the microcontroller, we are using ISP programmer. In the picture below you can see the programmer that we are using right now. We are connecting this programmer to our pc via usb port. Also, we connect the ISP to the board.

programmer

ATmega32#

ATmega32 is an 8-bit AVR microcontroller developed by Atmel (now Microchip Technology). Commonly used in embedded systems, robotics, and industrial automation due to its low power consumption and ease of use.

  • 32 KB of flash memory

    • non-volatile

    • Where our program is stored

  • 2 KB of SRAM

    • volatile

    • Where our variables, stack operations and buffer is stored

  • 1 KB of EEPROM

    • non-volatile

    • Config that we want it to remain

  • 32 general-purpose I/O pins

  • 8-channel 10-bit ADC

  • 3 timers (one 8-bit, two 16-bit)

  • UART, SPI, and I2C communication interfaces

atmega32_pins

In the picture above, you can see the pins on ATmega32. There are 32 geneal-purpose I/O pins:

  • PA

  • PB

  • PC

  • PD

Each pin is connected to a component on the board which we are going to explain them in the according lesson. All of these 32 pins can be set as outputs or inputs. (using their DDR)

jumper#

A removable connector that is used to connect to pins on the board. There is an example of a jumper in the picture below.

jumper

In this board most of the time there are 3 positions that you can put a jumper on:

  • on

  • off

  • none

The picture below shows the position of a jumper in “on” position in “JP1”.

jumper_on

Also, The picture below shows the position of a jumper in “off” position in “JP1”.

jumper_off

And lastly, The picture below has no jumper in “JP1”.

jumper_none

SimulIDE#

SimulIDE is a simplified IDE for simulating circuits. It is a free and open-source software and exteremly good for teaching purposes. More advanced IDEs are:

  • Proteus

  • Multisim

  • KiCad

To install SimulIDE you can simply download it from the link below:

SimulIDE

Then extract the zip file and run the executable file.

PlatformIO#

PlatformIO is an open-source extension for Visual Studio Code. It is a well-kown IDE for embedded systems. It supports a wide range of microcontrollers and boards. We are using PlatformIO to write our code and make a hex file. Then we are using the ISP programmer to program the hex file to the microcontroller or we can use the simulator to simulate the code.

To install PlatformIO, first you should have visual studio code installed on your machine. Then you can go to the extensions tab and search for PlatformIO. After installing the extension, you can start a new project and select the board that you are working on. It will download all the necessary files needed for your project. In this course we are using the Atmega32 board. So when we are creating a new project, we are selecting ATMega32 as our board, like the picture below.

platformio

After our project is created, a folder will be created in the directory that you have selected. In this folder, you can see the “src” folder which contains the main.cpp file. We write our code in this file. The template that is created for us is like the code below:

#include <Arduino.h>

// put function declarations here:
int myFunction(int, int);

void setup() {
  // put your setup code here, to run once:
  int result = myFunction(2, 3);
}

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

// put function definitions here:
int myFunction(int x, int y) {
  return x + y;
}

In the code above, you can see the setup and loop functions. These two functions are the ones that we are using, and we can delete the other functions. So we end up with the code like below:

#include <Arduino.h>

void setup()
{
}

void loop()
{
}

In setup function, we are initializing the pins and the components that we are using. In loop function, we are writing the main code that we want to run repeatedly (it is like a while True). To make the hex file, we can simply click on the “tick” icon on the bottom of the screen. Then the hex file will be created in the “.pio/build/ATmega32” folder.

avrdude#

avrdude is a command-line tool that is used to program the hex file to the microcontroller. To install avrdude on Ubuntu you can simply run the command below:

sudo apt install avrdude

Other linux distributions also contain avrdude that you can get them from their package manager. To program our code to the microcontroller, we can use the command below:

avrdude -c usbasp -p m32 -U flash:w:.pio/build/ATmega32/firmware.hex