Introduction: Programming ATmega16A Using Arduino IDE
Assalamualaikum warahmatullahi wabarakatuh
Hi,my name is Ekky Hermestian IW from Indonesia
This tutorial will show you how to program an ATmega16 using Arduino IDE
We can use syntax like
pinMode()
digitalWrite()
digitalRead()
and many more using non-Arduino AVR microcontrollers.
I usually program ATmega16 using CodeVisionAVR and i must define PORT and DDR, but in Arduino will automatically define the PORT and DDR using pinMode() syntax and when we want to set pin to high in CVAVR we must write PORTB.5=1 but in arduino is more simply just like digitalWrite(13, HIGH).
Step 1: Pin_arduino.h
arduino uno is using ATmegaxx8 and define the port using numer so we can easily use it
that proses is stored in Pin_arduino.h
we can find the file in this path C:\Program Files\Arduino\hardware\arduino\avr\variants\standard
open Pin_arduino.h and we will see how arduino convert PORT and DDR
then we need to change the following things before we can use arduino on ATmega16.
- The number of digital pins
- The number of analog pins
- Analog pin mappings and const for Analog pins (actual values for A0, A1)
- Digital pin to PCICR mapping
- Pin to port (PORTA, PORTB etc) mapping
- Pin to timer mapping
Most of these are straight forward and we can get the correct values from the target AVR chips datasheet.
Attachments
Step 2: Board.txt
To let the Arduino IDE, know about our new microcontroller, we need to create a newboards.txt file which has the following information about the microcontroller.
- Upload protocol
- Upload speed (baudrate)
- Upload fusesClock frequency
- Maximum flash memory size
- Which variant (pins_arduino.h) file to use
Like the pins_arduino.h file
Attachments
Step 3: Put It Together
Put the pin_arduino.h in C:\Program Files\Arduino\hardware\arduino\avr\variant\mega16
and copy board.txt to C:\Program Files\Arduino\hardware\arduino\avr
now we put board.txt and pin_arduino.h to arduino instalation folder and we already to use our arduino code to ATmega16
Step 4: Lets Try
Now we can use example like blink led
i connect led to pin 16 (PORTC.0) and ground and i use USBASP to upload the program
i still didnt understand why delay take so long,but i think because i use crystal 12Mhz while in Arduino UNO using 16Mhz
i attach my Minimumsystem schematic
sorry for my bad english
i made this instructable from this Hardwarefun-Use Arduino code in non-Arduino AVR microcontrollers
and i really thanks to Sudar as post author at hardwarefun,Raka Fahriza as Cameraman
Thanks for your attention
18 Comments
Question 4 years ago
how to place boards.txt ? please help
5 years ago
Can you please give the solution for the delay problem?
6 years ago
Assalaamu 'Alaikum Wa Rahmatullah,
i have no question i am new to this. i have AVR dragon with ATmega 16 and i was wondering if i can use Arduino RFID reader which i also have . just need guidance to get started
6 years ago
good job mr
6 years ago
Arduino: 1.6.10 (Windows 10), Board: "Arduino Yún"
Warning: Board arduino:avr:atmega16-8 doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA16-8
<command-line>:0:21: warning: missing whitespace after the macro name
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In function 'void serialEventRun()':
C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:72:2: error: 'config' was not declared in this scope
config |= 0x80; // select UCSRC register (shared with UBRRH)
^
exit status 1
Error compiling for board Atmega16 (internal 8MHz clock).
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
6 years ago
how to don this process on ubuntu ?????
7 years ago
Gan Ekhiw
Mau tanya, Kenapa proses upload nya error, padahal saya sudah ikutin dari http://hardwarefun.com/tutorials/use-arduino-as-an... error nya seperti ini avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x03
avrdude: stk500_recv(): programmer is not responding.
mohon solusi nya gan
7 years ago
Thank you!
7 years ago on Introduction
Hi, I tried to upload the blink LED code and getting this error
"Error while uploading: missing 'upload.tool' configuration parameter"
What to do?
Reply 7 years ago on Introduction
What programer do you use?USBASP or arduino as programer?
if you use usbasp make sure you already install the driver,you can get the driver in here http://www.fischl.de/usbasp/
if you already install the driver make sure in the board.txt has
atmega16-12.upload.tool=arduino write in it
or atmega16-12.upload.tool=avrdude(if you use usbasp)
and dont forget to choose upload using programer in Arduino IDE
Reply 7 years ago on Introduction
Thanks for the reply.
I took help form http://openhardware.ro/using-atmega16-with-arduino-ide/ and now I can upload any sketch to Atmega16.
Reply 7 years ago on Introduction
good..
thanks for sharing smandal13
8 years ago on Introduction
om, di videonya ada atmga16 12mhz. itu yang dimodifikasi apanya?
Reply 8 years ago on Introduction
itu cuma diganti fusebitnya
coba pake
lowfuse=0xFF
highfuse=0xDF
8 years ago
Good job dude
Reply 8 years ago
makasih gan
8 years ago on Introduction
Very nice coding job, this project has some great possiblities!
Reply 8 years ago on Introduction
thanks,now we can have a DIY Arduino board :)