Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
    • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Programming Atmega162 Microcontroller with Arduino IDE

July 31, 2019 By EG Projects

In this post i am going to explain how to program the Atmega162 controller using Arduino IDE. Since their is no support for Atmega162 officially in arduino IDE, So for making atmega162 compatible with arduino ide we need to define some files to make it visible to  the arduino ide. Luckily some work is already done previously so i decided to carry on from where the previous geeks left. The post  from http://openhardware.ro/using-atmega162-arduino-ide/ explains about carrying out the task, but its written in 2013 and needs to be reviewed. Following their tutorial the code will not compile in the latest arduino ide versions, it did not complied for me. A thread on arduino forum also discusses about the same topic making boot loader for the atmega162 http://forum.arduino.cc/index.php?topic=104693.15 . This thread also lacks in serial communication explanation. I will be discussing about the serial communication in next post.

To make any board/microcontroller visible to arduino ide we need to include its name in the boards.txt file. You can locate the boards.txt file at C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt. After locating the file you need to include the following to the end of the file and save the file.

 ############################################################## atmega162.name= ATmega162 atmega162.upload.tool=avrdude atmega162.upload.protocol=arduino atmega162.upload.maximum_size=14336 atmega162.upload.speed=57600 atmega162.bootloader.tool=avrdude atmega162.bootloader.low_fuses=0xFF atmega162.bootloader.high_fuses=0xD8 atmega162.bootloader.extended_fuses=0xFB atmega162.bootloader.path=optiboot atmega162.bootloader.file=optiboot_atmega162.hex atmega162.bootloader.unlock_bits=0x3F atmega162.bootloader.lock_bits=0x0F atmega162.build.mcu=atmega162 atmega162.build.f_cpu=16000000L atmega162.build.core=arduino atmega162.build.variant=atmega162 ############################################################## 

The above piece of statements will make the atmega162 visible to arduino IDE. Now you can see the “Atmega162” option appearing under the  Arduino IDE-> Tools>board drop down menu. The above statements also sets the atmega fuse bits and we tell the arduino ide about the  atmega162 bootloader. The statements also sets the frequency of the crystal that we are going to use with the atmega162. The statement atmega162.build.f_cpu=16000000L sets the atmega162 frequency to 16Mhz. You can also change the value of the crystal like if you want to use the 4Mhz just replace the statement with atmega162.build.f_cpu=4000000L. 
Atmega162 with Arduino IDE

Atmega162 with Arduino IDE

Now its time to define the arduino pins map. These pins are defined by the previous geeks so we are going to use the same pin out. But you can change it if you want.Creat a new folder name “atmega162″ at location C:\ProgramFiles(x86)\Arduino\hardware\arduino\avr\variants\”atmega162” Place this file in it arduino pins_arduino.h. Download the file from below.

pins_arduino.h
File Size: 6 kb
File Type: h

Download File


Note: Their is a difference between the original Pin out of the atmega162 and the ones that are used for the programming. For programming scheme the pins are defined in the pins_arduino header file. The pins are not defined according to the numbers that the pins originally occupied. But rather a new scheme is declared. Recall arduino uno in which the pins are defined by numbers D0, D1–D13. The same rules applies here the original numbers of pins are defined as 1,2,3–40 etc and for programming the pins are defined as D0,D1,D2,D3–D30 respectively. So for programming the use the numbers that are denoted with the letter D.    

Now overwrite the file “iom162.h” file located at C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\iom162.h Download the file from below. iom162 contains the registers that are associated with atmega162 microcontroller.

Atmega162 PinMap for Arduino IDE

Atmega162 PinMap for Arduino IDE

iom162.h
File Size: 20 kb
File Type: h

Download File


Atmega162 Bootloader

Now its time to tell the Arduino ide about the atmega162 microcontroller boot loader. Each Arduino board boot loader is placed at C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot. So place the atmega162 boot loader(optiboot_atmega162.hex file) in this optiboot folder. Download the Boot loader from the link on right side. Although the boot loader is uploaded in the microcontroller but it does not worked for me. I program the atmega162 using an external USBasp programmer.

Burning Bootloader in Atmega162 Microcontroller
​
Note that atmega162 can not be programmed directly with arduino ide. You need to programme it using an external programmer such as “USBasp”. Now connect the atmega icsp pins to your programmer “Mine USBasp” and burn the bootloader in it. First Select the board “Atmega162” from ArduinoIDE> Tools>Board>Atmega162 dropdown menu. Then select the programmer ArduinoIDE> Tools>Programmer>USBasp. Then ArduinoIDE> Tools>Burn Bootloader. Thats all now you can use your atmega 162 microcontroller with Arduino IDE using an external programmer such as “USBasp”.

Atmega162 support for arduino Ide

Atmega162 support for arduino Ide

Bootloader Atmega162
Atmega162 programmed with USBasp and Arduino Ide

Atmega162 programmed with USBasp and Arduino Ide

Click to set custom HTML

Interfacing 7-Segment Display with Atmega162 Microcontroller

Its time to work with the new stuff. I am going to display numbers from 0 to 9 on seven segment display using atmega162.  Code is written in Arduino Ide and burned in to the atmega162 microcontroller using USBasp programmer. Seven segment is directly  connected to the Port-A of the microcontroller. Also an Led is connected to pin 20 of atmega162. The led is a status led, Indicating the status of the microcontroller working or not.
 int blinkl=20; void setup() { // put your setup code here, to run once: pinMode(blinkl,OUTPUT); DDRA=0xFF; //Port-A as Output //PortA-6 to A //PortA-0 to F } void loop() { digitalWrite(blinkl,HIGH); delay(500); digitalWrite(blinkl,LOW); delay(500); PORTA=0x02; //Displaying 0 on 7-segment Display delay(500); PORTA=0x4F; //Displaying 1 on 7-segment Display delay(500); PORTA=0x11; //Displaying 2 on 7-segment Display delay(500); PORTA=0x05; //Displaying 3 on 7-segment Display delay(500); PORTA=0x4C; //Displaying 4 on 7-segment Display delay(500); PORTA=0x24; //Displaying 5 on 7-segment Display delay(500); PORTA=0x20; //Displaying 6 on 7-segment Display delay(500); PORTA=0x0F; //Displaying 7 on 7-segment Display delay(500); PORTA=0x00; //Displaying 8 on 7-segment Display delay(500); PORTA=0x0C; //Displaying 9 on 7-segment Display } 
Arduino Code
Watch the Project Video Here…

More projects using arduino ide and Atmega162 microcontroller. I also operated uart serial channel of atmega-162 microcontroller using arduino ide. Also check that project. Link is given below.   

Uart of Atmega162 with Arduino ide

Related Articles Read More >

A Bluetooth-controlled datalogger robot
touch bell push
How to design a touchless bell push using Arduino
SMS-enabled scrolling message board using Arduino
Interfacing stepper motor with 8051(89c51,89c52 ) microcontroller

Featured Tutorials

  • Capacitive Touch Controlled Robot using X-Bee Module
  • Keypad Controlled RF based Wireless Robot
  • A Bluetooth-controlled datalogger robot
  • Keypad Controlled And Industrial Gas Monitoring Wireless Robot
  • Joystick Controlled Wireless Robot
  • CAN Protocol – Understanding the Controller Area Network Protocol

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

Recent Articles

  • How to build an IR remote-operated RGB LED strip using Arduino
  • Maxim launches automotive-grade secure authenticator for enhanced vehicle safety
  • Samsung offers compact, WiFi-enabled VRF air-conditioning systems
  • Nexperia launches industry’s first 80-V RET family for high-voltage circuits
  • The Amazing World of Robotics and its Promising Future
...

RSS EDABOARD.com Discussions

  • Rippe current rating of aluminium electrolytic capacitor is very low.
  • Radiated emissions problems
  • Same geometry but slightly different results
  • Mic preamp and Tx on MAX260x
  • Security for IoT

RSS Electro-Tech-Online.com Discussions

  • new to Ardunio but trying to compile
  • Security for IoT
  • Can this rail fault cause the oscillator to give bad signal ?
  • watchdog in stop mode
  • First time using MOSFETs project
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
    • Contributions
  • Articles
    • EG Blogs
    • Insight
    • Invention Stories
    • How to
    • What Is
    • News
      • EE Design News
      • DIY Reviews
      • Guest Post
      • Sponsored Content
  • Forums
    • EG Forum Archive
    • EDABoard.com
    • Electro-Tech-Online
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering